1 # Player and Player-like objects
3 from erdslangetjie.data import load_image
6 class GameSprite(object):
15 def get_texture(self):
16 return self.sprite.texture
19 class FigureSprite(GameSprite):
21 def can_move(self, direction, level):
22 '''Check if we can move in the given direction'''
23 cand_pos = (self.pos[0] + direction[0], self.pos[1] + direction[1])
24 return not level.blocked(cand_pos)
27 class ThePlayer(FigureSprite):
30 super(ThePlayer, self).__init__()
31 self.sprite = load_image('sprites/player.png')
33 def move(self, direction, level):
34 if self.can_move(direction, level):
35 self.pos = (self.pos[0] + direction[0], self.pos[1] + direction[1])
40 class Nemesis(FigureSprite):
43 super(Nemesis, self).__init__()
44 self.sprite = load_image('sprites/nemesis.png')
48 def move(self, level, caught):
49 if not self.on_board():
50 # Advance towards the map a step at a time
51 self.pos = (self.pos[0] + 1, self.pos[1])
53 self.pos = level.enter_pos
57 self.been.append(self.pos)
58 for direction in [(1, 0), (-1, 0), (0, -1), (0, 1)] * 2:
59 new_pos = (self.pos[0] + direction[0], self.pos[1] + direction[1])
60 if self.can_move(direction, level) and new_pos not in self.been:
62 self.been.append(new_pos)
76 return self.pos[0] >= 0