Mercurial > Kubik
changeset 116:84a6ec24a915
add joystick
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Mon, 07 Jul 2014 20:17:32 +0000 |
| parents | f79b9703f37e |
| children | d543503fed43 |
| files | joy.py |
| diffstat | 1 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/joy.py Mon Jul 07 20:17:32 2014 +0000 @@ -0,0 +1,40 @@ +import pygame + +import kubik + + +FPS = 12 + + +pygame.display.init() +pygame.joystick.init() +pygame.mixer.init() + +clock = pygame.time.Clock() +hello = pygame.mixer.Sound('~/sound/Turret_turret_active_5.wav') +robot = kubik.Robot() + +for joy in range(pygame.joystick.get_count()): + pygame.joystick.Joystick(joy).init() + +robot.home() +while True: + for event in pygame.event.get(): + if event.type == pygame.JOYBUTTONDOWN: + hello.play() + print "Hello!" + elif event.type == pygame.JOYAXISMOTION: + print event.axis, event.value + if event.axis == 0: + for leg in robot.legs[:2]: + leg.move_to((30 + 20 * event.value, None, None)) + for leg in robot.legs[2:]: + leg.move_to((30 - 20 * event.value, None, None)) + elif event.axis == 1: + for leg in robot.legs: + leg.move_to((None, 40 * event.value, None)) + elif event.axis == 2: + for leg in robot.legs: + leg.move_to((None, None, -30 - 30 * event.value)) + robot.update() + clock.tick(FPS)
