def on_touch_down(self, touch): """ :param touch: :rtype: void """ # Reset current path. self.player_path = [] # get if player can draw here self.tile_identifier = TouchUtils.get_tile_identifier(self, touch.x, touch.y) can_draw = TouchUtils.can_start_stop(self.tile_identifier, self.map_canvas.points) if not can_draw: self.failed_attempts += 1 self.canvas.after.clear() return self.canvas.after.add( Point(points=(touch.x, touch.y), texture=self.TRACE_TEXTURE, pointsize=self.touch_width) ) # Save tile. self.old_tile_identifier = self.tile_identifier[:] self.player_path.append((self.tile_identifier[0], self.tile_identifier[1])) self.old_point = (touch.x, touch.y) touch.grab(self)
def on_touch_up(self, touch): """ :param touch: :rtype: void """ if touch.grab_current is not self: return # get if player can draw here self.tile_identifier = TouchUtils.get_tile_identifier(self, touch.x, touch.y) if self.tile_identifier is None: can_draw = False else: can_draw = TouchUtils.can_start_stop(self.tile_identifier, self.map_canvas.points) if can_draw: if self.is_path_correct(): return self.propagate_level_up() self.failed_attempts += 1 # Delete touch if player loose. self.canvas.after.clear() touch.ungrab(self) return
def on_touch_move(self, touch): """ :param touch: :rtype: void """ if touch.grab_current is not self: return # get if player can draw (test if player is in a valid tile then test if tile change). self.tile_identifier = TouchUtils.get_tile_identifier(self, touch.x, touch.y) if self.tile_identifier is None: can_draw = False # if player change tile elif self.tile_identifier != self.old_tile_identifier: old_tile_properties = TouchUtils.get_tile_properties(self.map_canvas.map_matrix, self.old_tile_identifier) tile_properties = TouchUtils.get_tile_properties(self.map_canvas.map_matrix, self.tile_identifier) direction = TouchUtils.get_touch_direction(self.tile_identifier, self.old_tile_identifier) can_draw = TouchUtils.is_authorised(self.tile_identifier, self.player_path, tile_properties, old_tile_properties, direction) if can_draw: self.player_path.append((self.tile_identifier[0], self.tile_identifier[1])) else: can_draw = True if not can_draw: self.failed_attempts += 1 self.canvas.after.clear() touch.ungrab(self) return points_list = self.get_smooth_points(self.old_point[0], self.old_point[1], touch.x, touch.y) if not points_list: points_list = [(touch.x, touch.y)] for index in range(len(points_list)): x_coord = points_list[index][0] y_coord = points_list[index][1] self.canvas.after.add( Point(points=(x_coord, y_coord), texture=self.TRACE_TEXTURE, pointsize=self.touch_width) ) # Save tile. self.old_tile_identifier = self.tile_identifier self.old_point = (touch.x, touch.y)