annotate pytouhou/game/player.py @ 386:dc6ed7b1c6de

Cancel player lasers when she dies.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 20 Oct 2012 20:44:12 +0200
parents 690b5faaa0e6
children ac2891afb0bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
1 # -*- encoding: utf-8 -*-
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
2 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
4 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
6 ## it under the terms of the GNU General Public License as published
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
7 ## by the Free Software Foundation; version 3 only.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
8 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
9 ## This program is distributed in the hope that it will be useful,
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
12 ## GNU General Public License for more details.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
13 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
14
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
15
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
16 from pytouhou.game.sprite import Sprite
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
17 from pytouhou.vm.anmrunner import ANMRunner
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
18 from pytouhou.game.bullettype import BulletType
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
19 from pytouhou.game.bullet import Bullet
294
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
20 from pytouhou.game.lasertype import LaserType
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
21 from pytouhou.game.laser import PlayerLaser
339
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
22 from pytouhou.game.game import GameOver
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
23
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
24 from math import pi
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
25
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
26
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
27 class PlayerState(object):
265
0aab9b34299e Use better defaults for player, and start the stage as if in practice mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 248
diff changeset
28 def __init__(self, character=0, score=0, power=0, lives=2, bombs=3):
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
29 self.character = character # ReimuA/ReimuB/MarisaA/MarisaB/...
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
30
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
31 self.score = score
303
647bde10353d Add score/effective_score distinction and prepare for highscore handling.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
32 self.effective_score = score
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
33 self.lives = lives
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
34 self.bombs = bombs
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
35 self.power = power
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
36
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
37 self.graze = 0
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
38 self.points = 0
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
39
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
40 self.x = 192.0
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
41 self.y = 384.0
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
42
191
d2b58a26c908 Set the correct invulnerability time.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 190
diff changeset
43 self.invulnerable_time = 240
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
44 self.touchable = True
199
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
45 self.focused = False
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
46
197
e1bc8c4cbb1a Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 196
diff changeset
47 self.power_bonus = 0 # Never goes over 30.
e1bc8c4cbb1a Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 196
diff changeset
48
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
49
331
1b4f04b08729 Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 328
diff changeset
50 def copy(self):
1b4f04b08729 Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 328
diff changeset
51 return PlayerState(self.character, self.score,
1b4f04b08729 Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 328
diff changeset
52 self.power, self.lives, self.bombs)
1b4f04b08729 Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 328
diff changeset
53
1b4f04b08729 Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 328
diff changeset
54
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
55 class Player(object):
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
56 def __init__(self, state, game, anm_wrapper):
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
57 self._game = game
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
58 self.sprite = None
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
59 self.anmrunner = None
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
60 self.anm_wrapper = anm_wrapper
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
61
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
62 self.speeds = (self.sht.horizontal_vertical_speed,
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
63 self.sht.diagonal_speed,
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
64 self.sht.horizontal_vertical_focused_speed,
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
65 self.sht.diagonal_focused_speed)
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
66
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
67 self.hitbox_half_size = self.sht.hitbox / 2.
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
68 self.graze_hitbox_half_size = self.sht.graze_hitbox / 2.
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
69
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
70 self.fire_time = 0
142
c7f0fd9d2145 Simple collision detection
Thibaut Girka <thib@sitedethib.com>
parents: 130
diff changeset
71
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
72 self.state = state
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
73 self.direction = None
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
74
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
75 self.set_anim(0)
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
76
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
77 self.death_time = 0
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
78
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
79
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
80 @property
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
81 def x(self):
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
82 return self.state.x
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
83
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
84
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
85 @property
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
86 def y(self):
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
87 return self.state.y
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
88
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
89
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
90 def set_anim(self, index):
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
91 self.sprite = Sprite()
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
92 self.anmrunner = ANMRunner(self.anm_wrapper, index, self.sprite)
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
93 self.anmrunner.run_frame()
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
94
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
95
343
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 339
diff changeset
96 def play_sound(self, name):
379
e0e284fcb288 Make a sound when an enemy is hit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 343
diff changeset
97 self._game.sfx_player.play('%s.wav' % name)
343
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 339
diff changeset
98
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 339
diff changeset
99
156
ebfd328e700c Rename a few functions, move a few things around...
Thibaut Girka <thib@sitedethib.com>
parents: 152
diff changeset
100 def collide(self):
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
101 if not self.state.invulnerable_time and not self.death_time and self.state.touchable: # Border Between Life and Death
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
102 self.death_time = self._game.frame
248
77b83064b57e Use the correct animation for player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 236
diff changeset
103 self._game.new_effect((self.state.x, self.state.y), 17)
198
13918723d1bc Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 197
diff changeset
104 self._game.modify_difficulty(-1600)
343
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 339
diff changeset
105 self.play_sound('pldead00')
190
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 184
diff changeset
106 for i in range(16):
193
9f58e2a6e950 Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 191
diff changeset
107 self._game.new_particle((self.state.x, self.state.y), 2, 4., 256) #TODO: find the real size and range.
152
86807b8a63bd Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 142
diff changeset
108
86807b8a63bd Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 142
diff changeset
109
206
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
110 def start_focusing(self):
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
111 self.state.focused = True
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
112
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
113
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
114 def stop_focusing(self):
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
115 self.state.focused = False
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
116
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
117
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
118 def fire(self):
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
119 sht = self.focused_sht if self.state.focused else self.sht
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
120 power = min(power for power in sht.shots if self.state.power < power)
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
121
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
122 bullets = self._game.players_bullets
294
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
123 lasers = self._game.players_lasers
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
124 nb_bullets_max = self._game.nb_bullets_max
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
125
343
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 339
diff changeset
126 if self.fire_time % 5 == 0:
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 339
diff changeset
127 self.play_sound('plst00')
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 339
diff changeset
128
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
129 for shot in sht.shots[power]:
294
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
130 origin = self.orbs[shot.orb - 1] if shot.orb else self.state
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
131
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
132 if shot.type == 3:
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
133 if self.fire_time != 30:
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
134 continue
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
135
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
136 number = shot.delay #TODO: number can do very surprising things, like removing any bullet creation from enemies with 3. For now, crash when not 0 or 1.
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
137 if lasers[number]:
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
138 continue
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
139
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
140 laser_type = LaserType(self.anm_wrapper, shot.sprite % 256, 68)
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
141 lasers[number] = PlayerLaser(laser_type, 0, shot.hitbox, shot.damage, shot.angle, shot.speed, shot.interval, origin)
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
142 continue
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
143
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
144 if (self.fire_time + shot.delay) % shot.interval != 0:
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
145 continue
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
146
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
147 if nb_bullets_max is not None and len(bullets) == nb_bullets_max:
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
148 break
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
149
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
150 x = origin.x + shot.pos[0]
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
151 y = origin.y + shot.pos[1]
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
152
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
153 #TODO: find a better way to do that.
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
154 bullet_type = BulletType(self.anm_wrapper, shot.sprite % 256,
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
155 shot.sprite % 256 + 32, #TODO: find the real cancel anim
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
156 0, 0, 0, 0.)
294
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
157 #TODO: Type 1 (homing bullets)
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
158 if shot.type == 2:
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
159 #TODO: triple-check acceleration!
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
160 bullets.append(Bullet((x, y), bullet_type, 0,
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
161 shot.angle, shot.speed,
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
162 (-1, 0, 0, 0, 0.15, -pi/2., 0., 0.),
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
163 16, self, self._game, player_bullet=True,
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
164 damage=shot.damage, hitbox=shot.hitbox))
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
165 else:
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
166 bullets.append(Bullet((x, y), bullet_type, 0,
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
167 shot.angle, shot.speed,
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
168 (0, 0, 0, 0, 0., 0., 0., 0.),
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
169 0, self, self._game, player_bullet=True,
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
170 damage=shot.damage, hitbox=shot.hitbox))
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
171
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
172
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
173 def update(self, keystate):
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
174 if self.death_time == 0 or self._game.frame - self.death_time > 60:
220
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 211
diff changeset
175 speed, diag_speed = self.speeds[2:] if self.state.focused else self.speeds[:2]
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
176 try:
220
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 211
diff changeset
177 dx, dy = {16: (0.0, -speed), 32: (0.0, speed), 64: (-speed, 0.0), 128: (speed, 0.0),
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 211
diff changeset
178 16|64: (-diag_speed, -diag_speed), 16|128: (diag_speed, -diag_speed),
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 211
diff changeset
179 32|64: (-diag_speed, diag_speed), 32|128: (diag_speed, diag_speed)}[keystate & (16|32|64|128)]
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
180 except KeyError:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
181 dx, dy = 0.0, 0.0
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
182
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
183 if dx < 0 and self.direction != -1:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
184 self.set_anim(1)
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
185 self.direction = -1
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
186 elif dx > 0 and self.direction != +1:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
187 self.set_anim(3)
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
188 self.direction = +1
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
189 elif dx == 0 and self.direction is not None:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
190 self.set_anim({-1: 2, +1: 4}[self.direction])
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
191 self.direction = None
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
192
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
193 self.state.x += dx
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
194 self.state.y += dy
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
195
380
c25530efea3b Replace player position in game zone right after its move; fix shots offsets at boundaries.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 379
diff changeset
196 if self.state.x < 8.:
c25530efea3b Replace player position in game zone right after its move; fix shots offsets at boundaries.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 379
diff changeset
197 self.state.x = 8.
c25530efea3b Replace player position in game zone right after its move; fix shots offsets at boundaries.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 379
diff changeset
198 if self.state.x > self._game.width - 8:
c25530efea3b Replace player position in game zone right after its move; fix shots offsets at boundaries.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 379
diff changeset
199 self.state.x = self._game.width - 8.
c25530efea3b Replace player position in game zone right after its move; fix shots offsets at boundaries.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 379
diff changeset
200 if self.state.y < 16.:
c25530efea3b Replace player position in game zone right after its move; fix shots offsets at boundaries.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 379
diff changeset
201 self.state.y = 16.
c25530efea3b Replace player position in game zone right after its move; fix shots offsets at boundaries.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 379
diff changeset
202 if self.state.y > self._game.height - 16:
c25530efea3b Replace player position in game zone right after its move; fix shots offsets at boundaries.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 379
diff changeset
203 self.state.y = self._game.height -16.
c25530efea3b Replace player position in game zone right after its move; fix shots offsets at boundaries.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 379
diff changeset
204
199
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
205 if not self.state.focused and keystate & 4:
206
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
206 self.start_focusing()
199
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
207 elif self.state.focused and not keystate & 4:
206
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
208 self.stop_focusing()
199
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
209
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
210 if self.state.invulnerable_time > 0:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
211 self.state.invulnerable_time -= 1
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
212
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
213 m = self.state.invulnerable_time % 8
328
56523a16db1d Fix some replay synchronization issues and update the TODO.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
214 if m == 7 or self.state.invulnerable_time == 0:
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
215 self.sprite.color = (255, 255, 255)
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
216 self.sprite.changed = True
328
56523a16db1d Fix some replay synchronization issues and update the TODO.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
217 elif m == 1:
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
218 self.sprite.color = (64, 64, 64)
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
219 self.sprite.changed = True
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
220
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
221 if keystate & 1 and self.fire_time == 0:
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
222 self.fire_time = 30
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
223 if self.fire_time > 0:
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
224 self.fire()
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
225 self.fire_time -= 1
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
226
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
227 if self.death_time:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
228 time = self._game.frame - self.death_time
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
229 if time == 6: # too late, you are dead :(
175
5dc243bcf312 Don’t collect the items you drop while dying…
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
230 self.state.touchable = False
184
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
231 if self.state.power > 16:
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
232 self.state.power -= 16
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
233 else:
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
234 self.state.power = 0
386
dc6ed7b1c6de Cancel player lasers when she dies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 384
diff changeset
235 for laser in self._game.players_lasers:
dc6ed7b1c6de Cancel player lasers when she dies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 384
diff changeset
236 if laser:
dc6ed7b1c6de Cancel player lasers when she dies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 384
diff changeset
237 laser.cancel()
184
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
238
339
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
239 self.state.lives -= 1
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
240 if self.state.lives < 0:
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
241 #TODO: display a menu to ask the players if they want to continue.
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
242 self._game.continues -= 1
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
243 if self._game.continues < 0:
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
244 raise GameOver
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
245
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
246 for i in range(5):
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
247 self._game.drop_bonus(self.state.x, self.state.y, 4,
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
248 end_pos=(self._game.prng.rand_double() * 288 + 48,
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
249 self._game.prng.rand_double() * 192 - 64))
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
250 self.state.score = 0
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
251 self.state.effective_score = 0
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
252 self.state.lives = 2 #TODO: use the right default.
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
253 self.state.bombs = 3 #TODO: use the right default.
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
254 self.state.power = 0
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
255
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
256 self.state.graze = 0
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
257 self.state.points = 0
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
258 else:
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
259 self._game.drop_bonus(self.state.x, self.state.y, 2,
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
260 end_pos=(self._game.prng.rand_double() * 288 + 48, # 102h.exe@0x41f3dc
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
261 self._game.prng.rand_double() * 192 - 64)) # @0x41f3
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
262 for i in range(5):
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
263 self._game.drop_bonus(self.state.x, self.state.y, 0,
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
264 end_pos=(self._game.prng.rand_double() * 288 + 48,
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
265 self._game.prng.rand_double() * 192 - 64))
184
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
266
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
267 elif time == 7:
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
268 self.sprite.mirrored = False
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
269 self.sprite.blendfunc = 0
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
270 self.sprite.rescale = 0.75, 1.5
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
271 self.sprite.fade(26, 96, lambda x: x)
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
272 self.sprite.scale_in(26, 0.00, 2.5, lambda x: x)
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
273
211
a765ef90c2b0 Make death animation closer to the original
Thibaut Girka <thib@sitedethib.com>
parents: 206
diff changeset
274 elif time == 32:
225
2d35565b5608 Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents: 220
diff changeset
275 self.state.x = float(self._game.width) / 2. #TODO
2d35565b5608 Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents: 220
diff changeset
276 self.state.y = float(self._game.width) #TODO
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
277 self.direction = None
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
278
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
279 self.sprite = Sprite()
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
280 self.anmrunner = ANMRunner(self.anm_wrapper, 0, self.sprite)
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
281 self.sprite.alpha = 128
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
282 self.sprite.rescale = 0.0, 2.5
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
283 self.sprite.fade(30, 255, lambda x: x)
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
284 self.sprite.blendfunc = 1
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
285 self.sprite.scale_in(30, 1., 1., lambda x: x)
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
286 self.anmrunner.run_frame()
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
287
211
a765ef90c2b0 Make death animation closer to the original
Thibaut Girka <thib@sitedethib.com>
parents: 206
diff changeset
288 elif time == 61: # respawned
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
289 self.state.touchable = True
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
290 self.state.invulnerable_time = 240
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
291 self.sprite.blendfunc = 0
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
292 self.sprite.changed = True
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
293
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
294 if time > 30:
335
2350147cf043 Fix bullet cancellation and removal
Thibaut Girka <thib@sitedethib.com>
parents: 331
diff changeset
295 self._game.cancel_bullets()
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
296
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
297 if time > 90: # start the bullet hell again
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
298 self.death_time = 0
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
299
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
300 self.anmrunner.run_frame()
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
301