-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyHandler.py
More file actions
65 lines (43 loc) · 1.69 KB
/
KeyHandler.py
File metadata and controls
65 lines (43 loc) · 1.69 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'''
Castle Defense Keyboard Handler
By Katie and Paulo
'''
class KeyHandler:
def __init__(self, screen, router):
self.screen = screen
# Game router
self.router = router
self.screen.bind("<Key>", self.handler)
self.screen.canvas.bind("<Button-1>", self.left_click_handler)
self.screen.canvas.bind("<Shift-Button-1>", self.left_shift_click_handler)
self.screen.canvas.bind("<Button-2>", self.right_click_handler) # Right Click
def handler(self,event):
# Pressing forward should move field of vision up
if (event.keycode == 8255233):
self.screen.move_screen('up')
elif (event.keycode == 8320768):
self.screen.move_screen('down')
elif (event.keycode == 8189699):
self.screen.move_screen('left')
elif (event.keycode == 8124162):
self.screen.move_screen('right')
# Call the update graphics
self.screen.update_graphics()
def left_click_handler(self,event):
# Standard click (Without Shift Key)
location = self.screen.get_clicked_cell(event.x, event.y)
self.screen.get_grid().set_selected(location[0],location[1], False)
# Call the update graphics
self.screen.update_graphics()
def left_shift_click_handler(self,event):
# Standard click (With Shift Key)
location = self.screen.get_clicked_cell(event.x, event.y)
self.screen.get_grid().set_selected(location[0],location[1], True)
# Call the update graphics
self.screen.update_graphics()
def right_click_handler(self,event):
location = self.screen.get_clicked_cell(event.x, event.y)
# Get the currently selected action
action = self.screen.get_control_menu().get_current_action()
# Set this cell in the grid to be highlighted
self.router.set_action(location[0],location[1], action)