Adding keyboard handlers for the game.

This commit is contained in:
Alex Yatskov 2014-05-16 13:43:20 +09:00
parent 485085df58
commit f55f112cfe

View File

@ -34,15 +34,24 @@ class Engine:
return False return False
if event.type == pygame.KEYDOWN: if event.type == pygame.KEYDOWN:
print 'keydown' if event.key == pygame.K_LEFT:
self.move_left()
elif event.key == pygame.K_RIGHT:
self.move_right()
elif event.key == pygame.K_DOWN:
self.move_down()
elif event.key == pygame.K_UP:
self.flip()
elif event.key == pygame.K_ESCAPE:
return False
elif event.type == pygame.JOYAXISMOTION: elif event.type == pygame.JOYAXISMOTION:
print event.axis, event.value
if event.axis == 0: if event.axis == 0:
if event.value > 0: self.move_right() if event.value > 0: self.move_right()
else: self.move_left() elif event.value < 0: self.move_left()
elif event.axis == 1: elif event.axis == 1:
if event.value > 0: self.move_down() if event.value > 0: self.move_down()
else: self.flip() elif event.value < 0: self.flip()
return True return True
@ -58,11 +67,11 @@ class Engine:
def move_down(self): def move_down(self):
print 'down' print 'down'
def flip(self): def flip(self):
print 'flip' print 'flip'
def main(): def main():
engine = Engine() engine = Engine()
engine.create((800, 600)) engine.create((800, 600))