diff options
author | EUcancER <root@euer.krebsco.de> | 2012-03-28 11:57:04 +0200 |
---|---|---|
committer | EUcancER <root@euer.krebsco.de> | 2012-03-28 11:57:04 +0200 |
commit | 2dc719c48242f9d3bc0114e323d809c3ec8d074e (patch) | |
tree | ff2029a0a6fa9745c207049ba200aa01a3427744 /god/soundboard/sound.py | |
parent | ecf3778511837456c005577acd1b4195f50ea101 (diff) | |
parent | a082985e111ae776e44065fec52e5f3a3199e138 (diff) |
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'god/soundboard/sound.py')
-rw-r--r-- | god/soundboard/sound.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/god/soundboard/sound.py b/god/soundboard/sound.py new file mode 100644 index 00000000..f6564db0 --- /dev/null +++ b/god/soundboard/sound.py @@ -0,0 +1,46 @@ +import pygame +import os +from pygame import locals +import json +CFG_FILE = "config.json" +cfg = json.load(open(CFG_FILE)) + +pygame.init() +pygame.joystick.init() +try: + j = pygame.joystick.Joystick(0) + j.init() + print 'Enabled joystick: ' + j.get_name() +except pygame.error: + print 'no joystick found.' + + +while 1: + for e in pygame.event.get(): + #print 'event : ' + str(e.type) + #print 'data : ' + str(e.dict) + if e.type == pygame.locals.JOYAXISMOTION: + x, y = j.get_axis(0), j.get_axis(1) + if (x > 0): + direction = "right" + elif(x < 0): + direction = "left" + if (y > 0): + direction = "up" + elif(y < 0): + direction = "down" + if (y == x == 0): + pass + else: + try: + os.system(cfg["direction"][direction]) + except Exception as balls: + print "direction not defined?", balls + + elif e.type == pygame.locals.JOYBUTTONDOWN: + try: + os.system(cfg["button"][str(e.button)]) + except Exception as balls: + print "button not defined: ", balls + #elif e.type == pygame.locals.JOYBUTTONUP: + # print 'button up', e.joy, e.button |