self.level_obj.load_tiles()
self.tiles = {}
+ self.mouse_move = False
+
self.player = ThePlayer()
self.nemesis = Nemesis()
if not self.level_obj.enter_pos:
elif keycode[0] == pygame.K_RIGHT:
direction = (1, 0)
if direction:
- self.nemesis.move(self.level_obj)
- self.draw_nemesis()
- self.player.move(direction, self.level_obj)
- self.draw_player()
+ self.do_move(direction)
+
+ def do_move(self, direction):
+ self.nemesis.move(self.level_obj)
+ self.draw_nemesis()
+ self.player.move(direction, self.level_obj)
+ self.draw_player()
self.check_state()
def check_state(self):
print 'You lost!'
sys.exit(1)
+ def _calc_mouse_pos(self, pos):
+ return (int(pos[0] / TILE_SIZE), int(pos[1] / TILE_SIZE))
+
+ def on_touch_down(self, touch):
+ pos = self._calc_mouse_pos(touch.pos)
+ if pos == self.player.pos:
+ self.mouse_move = True
+ self.mouse_start = pos
+
+ def on_touch_up(self, touch):
+ self.mouse_move = False
+
+ def on_touch_move(self, touch):
+ if self.mouse_move:
+ pos = self._calc_mouse_pos(touch.pos)
+ if (pos[0] - self.mouse_start[0] != 0) or (
+ pos[1] - self.mouse_start[1] != 0):
+ direction = (pos[0] - self.mouse_start[0],
+ pos[1] - self.mouse_start[1])
+ self.do_move(direction)
+ self.mouse_start = pos
+
class GameApp(App):