comparison pytouhou/game/player.pyx @ 465:5f5955635d2c

Move continues to PlayerState, and make sure they aren’t reinitialized before each stage.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 11 Sep 2013 16:03:55 +0200
parents 4ccc47828002
children feecdb4a8928
comparison
equal deleted inserted replaced
464:36bc577b2392 465:5f5955635d2c
25 class GameOver(Exception): 25 class GameOver(Exception):
26 pass 26 pass
27 27
28 28
29 cdef class PlayerState: 29 cdef class PlayerState:
30 def __init__(self, long character=0, long score=0, long power=0, long lives=2, long bombs=3): 30 def __init__(self, long character=0, long score=0, long power=0,
31 long lives=2, long bombs=3, long continues=0):
31 self.character = character # ReimuA/ReimuB/MarisaA/MarisaB/... 32 self.character = character # ReimuA/ReimuB/MarisaA/MarisaB/...
32 33
33 self.score = score 34 self.score = score
34 self.effective_score = score 35 self.effective_score = score
35 self.lives = lives 36 self.lives = lives
36 self.bombs = bombs 37 self.bombs = bombs
37 self.power = power 38 self.power = power
39 self.continues = continues
40
41 self.continues_used = 0
42 self.miss = 0
43 self.bombs_used = 0
38 44
39 self.graze = 0 45 self.graze = 0
40 self.points = 0 46 self.points = 0
41 47
42 self.x = 192.0 48 self.x = 192.0
45 self.invulnerable_time = 240 51 self.invulnerable_time = 240
46 self.touchable = True 52 self.touchable = True
47 self.focused = False 53 self.focused = False
48 54
49 self.power_bonus = 0 # Never goes over 30. 55 self.power_bonus = 0 # Never goes over 30.
50
51
52 def copy(self):
53 return PlayerState(self.character, self.score,
54 self.power, self.lives, self.bombs)
55 56
56 57
57 cdef class Player(Element): 58 cdef class Player(Element):
58 def __init__(self, PlayerState state, Game game, anm): 59 def __init__(self, PlayerState state, Game game, anm):
59 Element.__init__(self) 60 Element.__init__(self)
248 self.state.power = 0 249 self.state.power = 0
249 for laser in self._game.players_lasers: 250 for laser in self._game.players_lasers:
250 if laser is not None: 251 if laser is not None:
251 laser.cancel() 252 laser.cancel()
252 253
254 self.state.miss += 1
253 self.state.lives -= 1 255 self.state.lives -= 1
254 if self.state.lives < 0: 256 if self.state.lives < 0:
255 #TODO: display a menu to ask the players if they want to continue. 257 #TODO: display a menu to ask the players if they want to continue.
256 self._game.continues -= 1 258 if self.state.continues == 0:
257 if self._game.continues < 0:
258 raise GameOver 259 raise GameOver
260
261 # Don’t decrement if it’s infinite.
262 if self.state.continues >= 0:
263 self.state.continues -= 1
264 self.state.continues_used += 1
259 265
260 for i in xrange(5): 266 for i in xrange(5):
261 self._game.drop_bonus(self.state.x, self.state.y, 4, 267 self._game.drop_bonus(self.state.x, self.state.y, 4,
262 end_pos=(self._game.prng.rand_double() * 288 + 48, 268 end_pos=(self._game.prng.rand_double() * 288 + 48,
263 self._game.prng.rand_double() * 192 - 64)) 269 self._game.prng.rand_double() * 192 - 64))