-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard.py
29 lines (25 loc) · 933 Bytes
/
keyboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from event import (
PygameHandler,
TargettedEvent,
)
from pygame.locals import *
from locals import *
class MovementEvent(TargettedEvent):
def __init__(self, target, dx, dy):
super(MovementEvent,self).__init__(None,target)
self.dx=dx
self.dy=dy
class WASDHandler(PygameHandler):
def __init__(self, player):
super(WASDHandler, self).__init__(KEYDOWN)
self.player = player
def handle_event(self, event):
loop = get_loop()
if event.payload.key == K_w:
loop.enqueue(MovementEvent(self.player, 0 , -MOVEMENT_INC))
elif event.payload.key == K_a:
loop.enqueue(MovementEvent(self.player, -MOVEMENT_INC , 0))
elif event.payload.key == K_s:
loop.enqueue(MovementEvent(self.player, 0 , MOVEMENT_INC))
elif event.payload.key == K_d:
loop.enqueue(MovementEvent(self.player, MOVEMENT_INC , 0))