""" This module defines functions that respond to user keyboard and touch events."""fromkivy.uix.relativelayoutimportRelativeLayout
[docs]defkeyboard_closed(self):""" Handle event when the keyboard is closed. """self.keyboard.unbind(on_key_down=self.on_keyboard_down)self.keyboard.bind(on_key_up=self.on_keyboard_up)self.keyboard=None
[docs]defon_keyboard_down(self,keyboard,keycode,text,modifiers):""" Handle event when a key is pressed. """ifkeycode[1]=='left':self.current_speed_x=self.SPEED_Xelifkeycode[1]=='right':self.current_speed_x=-self.SPEED_XreturnTrue
[docs]defon_keyboard_up(self,keyboard,keycode):""" Handle event when a key is released. """self.current_speed_x=0
[docs]defon_touch_down(self,touch):""" Handle event when a screen touch is detected. Args: touch (Touch): The touch event. """ifnotself.state_game_overandself.state_game_has_started:iftouch.x<self.width/2:self.current_speed_x=self.SPEED_Xelse:self.current_speed_x=-self.SPEED_Xreturnsuper(RelativeLayout,self).on_touch_down(touch)
[docs]defon_touch_up(self,touch):""" Handle event when a screen touch ends. Args: touch (Touch): The touch event. """pass