-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_actions.py
35 lines (25 loc) · 972 Bytes
/
user_actions.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
30
31
32
33
34
35
from kivy.uix.relativelayout import RelativeLayout
def keyboard_closed(self):
self._keyboard.unbind(on_key_down=self._on_keyboard_down)
self._keyboard.unbind(on_key_up=self._on_keyboard_up)
self._keyboard = None
def on_keyboard_down(self, keyboard, keycode, text, modifiers):
if keycode[1] == 'left':
self.current_speed_x = self.SPEED_X
elif keycode[1] == 'right':
self.current_speed_x = -self.SPEED_X
return True
def on_keyboard_up(self, keyboard, keycode):
self.current_speed_x = 0
def on_touch_down(self, touch):
if not self.state_game_over and self.state_game_has_started:
if touch.x < self.width / 2:
# print("<-")
self.current_speed_x = self.SPEED_X
else:
# print("->")
self.current_speed_x = -self.SPEED_X
return super(RelativeLayout, self).on_touch_down(touch)
def on_touch_up(self, touch):
# print("UP")
self.current_speed_x = 0