annotate pytouhou/game/player.pyx @ 606:3c2f96f1d715

Fix compilation under Cython 0.22, by making the pyx and the pxd declarations’ except clause similar.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 26 Nov 2014 13:36:38 +0100
parents e15672733c93
children 2cf518129725
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
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
15 from libc.math cimport M_PI as pi
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
16
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
17 from pytouhou.game.sprite cimport Sprite
547
e35bef07290d Always import runners from pytouhou.vm, to allow their replacement.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 527
diff changeset
18 from pytouhou.vm import ANMRunner
472
8038f1957b71 Type bullettype, itemtype and lasertype a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 471
diff changeset
19 from pytouhou.game.bullettype cimport BulletType
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
20 from pytouhou.game.bullet cimport Bullet
472
8038f1957b71 Type bullettype, itemtype and lasertype a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 471
diff changeset
21 from pytouhou.game.lasertype cimport LaserType
471
06f0eeb519bb Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 468
diff changeset
22 from pytouhou.game.laser cimport PlayerLaser
577
e35a083d4208 Move NextStage outside of pytouhou.vm.msg, to be able to use it from anywhere without dependency on EoSD.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
23 from pytouhou.game import GameOver
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
24
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
25
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
26 cdef class Player(Element):
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
27 def __init__(self, long number, anm, long character=0, long power=0,
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
28 long continues=0, long lives=2, long bombs=3, long score=0):
509
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 502
diff changeset
29 Element.__init__(self, (192, 384))
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
30
492
887de1309491 Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 472
diff changeset
31 self.number = number
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
32 self.character = character # ReimuA/ReimuB/MarisaA/MarisaB/...
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
33
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
34 self.score = score
303
647bde10353d Add score/effective_score distinction and prepare for highscore handling.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
35 self.effective_score = score
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
36 self.lives = lives
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
37 self.bombs = bombs
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
38 self.continues = continues
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
39 self.power = power
465
5f5955635d2c Move continues to PlayerState, and make sure they aren’t reinitialized before each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 457
diff changeset
40
5f5955635d2c Move continues to PlayerState, and make sure they aren’t reinitialized before each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 457
diff changeset
41 self.continues_used = 0
5f5955635d2c Move continues to PlayerState, and make sure they aren’t reinitialized before each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 457
diff changeset
42 self.miss = 0
5f5955635d2c Move continues to PlayerState, and make sure they aren’t reinitialized before each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 457
diff changeset
43 self.bombs_used = 0
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
44
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
45 self.graze = 0
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
46 self.points = 0
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
47
191
d2b58a26c908 Set the correct invulnerability time.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 190
diff changeset
48 self.invulnerable_time = 240
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
49 self.touchable = True
199
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
50 self.focused = False
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
51
197
e1bc8c4cbb1a Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 196
diff changeset
52 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
53
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
54 self._game = None
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 390
diff changeset
55 self.anm = anm
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
56
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
57 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
58 self.sht.diagonal_speed,
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
59 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
60 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
61
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
62 self.fire_time = 0
142
c7f0fd9d2145 Simple collision detection
Thibaut Girka <thib@sitedethib.com>
parents: 130
diff changeset
63
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
64 self.direction = 0
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
65
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
66 self.set_anim(0)
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
67
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
68 self.death_time = 0
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
69
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
70
606
3c2f96f1d715 Fix compilation under Cython 0.22, by making the pyx and the pxd declarations’ except clause similar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
71 cdef void set_anim(self, index) except *:
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
72 self.sprite = Sprite()
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 390
diff changeset
73 self.anmrunner = ANMRunner(self.anm, index, self.sprite)
130
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
606
3c2f96f1d715 Fix compilation under Cython 0.22, by making the pyx and the pxd declarations’ except clause similar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
76 cdef void play_sound(self, str name) except *:
379
e0e284fcb288 Make a sound when an enemy is hit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 343
diff changeset
77 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
78
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 339
diff changeset
79
606
3c2f96f1d715 Fix compilation under Cython 0.22, by making the pyx and the pxd declarations’ except clause similar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
80 cdef void collide(self) except *:
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
81 if not self.invulnerable_time and not self.death_time and self.touchable: # Border Between Life and Death
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
82 self.death_time = self._game.frame
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
83 self._game.new_effect((self.x, self.y), 17)
198
13918723d1bc Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 197
diff changeset
84 self._game.modify_difficulty(-1600)
343
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 339
diff changeset
85 self.play_sound('pldead00')
590
e15672733c93 Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
86 for i in range(16):
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
87 self._game.new_particle((self.x, self.y), 11, 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
88
86807b8a63bd Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 142
diff changeset
89
206
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
90 def start_focusing(self):
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
91 self.focused = True
206
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
92
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
93
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
94 def stop_focusing(self):
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
95 self.focused = False
206
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
96
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
97
606
3c2f96f1d715 Fix compilation under Cython 0.22, by making the pyx and the pxd declarations’ except clause similar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
98 cdef void fire(self) except *:
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
99 cdef long shot_power
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
100
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
101 sht = self.focused_sht if self.focused else self.sht
444
f26c8ab57257 Use a simple for loop to determine the power level of the player; fixes a traceback when the SHT has no shot at all.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
102
f26c8ab57257 Use a simple for loop to determine the power level of the player; fixes a traceback when the SHT has no shot at all.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
103 # Don’t use min() since sht.shots could be an empty dict.
f26c8ab57257 Use a simple for loop to determine the power level of the player; fixes a traceback when the SHT has no shot at all.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
104 power = 999
f26c8ab57257 Use a simple for loop to determine the power level of the player; fixes a traceback when the SHT has no shot at all.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
105 for shot_power in sht.shots:
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
106 if self.power < shot_power:
444
f26c8ab57257 Use a simple for loop to determine the power level of the player; fixes a traceback when the SHT has no shot at all.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
107 power = power if power < shot_power else shot_power
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
108
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
109 bullets = self._game.players_bullets
294
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
110 lasers = self._game.players_lasers
447
78e1c3864e73 Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 445
diff changeset
111 nb_bullets_max = self._game.nb_bullets_max
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
112
343
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 339
diff changeset
113 if self.fire_time % 5 == 0:
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 339
diff changeset
114 self.play_sound('plst00')
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 339
diff changeset
115
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
116 for shot in sht.shots[power]:
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
117 origin = <Element>(self.orbs[shot.orb - 1] if shot.orb else self)
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
118 shot_type = <unsigned char>shot.type
294
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
119
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
120 if shot_type == 3:
294
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
121 if self.fire_time != 30:
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
122 continue
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
123
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
124 #TODO: number can do very surprising things, like removing any
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
125 # bullet creation from enemies with 3. For now, crash when not
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
126 # an actual laser number.
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
127 number = <long>shot.delay
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
128 if lasers[number] is not None:
294
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
129 continue
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
130
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 390
diff changeset
131 laser_type = LaserType(self.anm, shot.sprite % 256, 68)
294
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
132 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
133 continue
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
134
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
135 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
136 continue
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
137
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
138 if nb_bullets_max != 0 and len(bullets) == nb_bullets_max:
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
139 break
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
140
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
141 x = origin.x + <double>shot.pos[0]
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
142 y = origin.y + <double>shot.pos[1]
235
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 #TODO: find a better way to do that.
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 390
diff changeset
145 bullet_type = BulletType(self.anm, shot.sprite % 256,
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
146 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
147 0, 0, 0, 0.)
294
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 274
diff changeset
148 #TODO: Type 1 (homing bullets)
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
149 if shot_type == 2:
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
150 #TODO: triple-check acceleration!
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
151 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
152 shot.angle, shot.speed,
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
153 (-1, 0, 0, 0, 0.15, -pi/2., 0., 0.),
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
154 16, self, self._game, player=self.number,
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
155 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
156 else:
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
157 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
158 shot.angle, shot.speed,
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
159 (0, 0, 0, 0, 0., 0., 0., 0.),
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
160 0, self, self._game, player=self.number,
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
161 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
162
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 225
diff changeset
163
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
164 cpdef update(self, long keystate):
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
165 cdef double dx, dy
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
166
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
167 if self.death_time == 0 or self._game.frame - self.death_time > 60:
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
168 speed, diag_speed = self.speeds[2:] if self.focused else self.speeds[:2]
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
169 try:
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
170 dx, dy = {16: (0., -speed), 32: (0., speed), 64: (-speed, 0.), 128: (speed, 0.),
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
171 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
172 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
173 except KeyError:
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
174 dx, dy = 0., 0.
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
175
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
176 if dx < 0 and self.direction != -1:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
177 self.set_anim(1)
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
178 self.direction = -1
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
179 elif dx > 0 and self.direction != +1:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
180 self.set_anim(3)
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
181 self.direction = +1
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
182 elif dx == 0 and self.direction != 0:
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
183 self.set_anim({-1: 2, +1: 4}[self.direction])
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
184 self.direction = 0
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
185
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
186 self.x += dx
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
187 self.y += dy
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
188
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
189 if self.x < 8.:
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
190 self.x = 8.
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
191 if self.x > self._game.width - 8:
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
192 self.x = self._game.width - 8.
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
193 if self.y < 16.:
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
194 self.y = 16.
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
195 if self.y > self._game.height - 16:
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
196 self.y = self._game.height -16.
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
197
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
198 if not self.focused and keystate & 4:
206
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
199 self.start_focusing()
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
200 elif self.focused and not keystate & 4:
206
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 199
diff changeset
201 self.stop_focusing()
199
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
202
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
203 if self.invulnerable_time > 0:
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
204 self.invulnerable_time -= 1
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
205
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
206 m = self.invulnerable_time % 8
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
207 if m == 7 or self.invulnerable_time == 0:
590
e15672733c93 Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
208 for i in range(3):
527
db28538cd399 Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 509
diff changeset
209 self.sprite._color[i] = 255
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
210 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
211 elif m == 1:
590
e15672733c93 Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
212 for i in range(3):
527
db28538cd399 Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 509
diff changeset
213 self.sprite._color[i] = 64
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
214 self.sprite.changed = True
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
215
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
216 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
217 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
218 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
219 self.fire()
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
220 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
221
498
c9c2fb873dbd Actually consume a bomb when using it, make the player invulnerable for a certain time, and implement deathbomb.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
222 if self.death_time == 0 or self.death_time < 6: #TODO: < or <=?
c9c2fb873dbd Actually consume a bomb when using it, make the player invulnerable for a certain time, and implement deathbomb.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
223 if keystate & 2 and self.bombs and self.bomb_time == 0:
457
4ccc47828002 Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 447
diff changeset
224 self._game.set_player_bomb()
4ccc47828002 Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 447
diff changeset
225 self.bomb_time = 240
498
c9c2fb873dbd Actually consume a bomb when using it, make the player invulnerable for a certain time, and implement deathbomb.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
226 self.bombs -= 1
c9c2fb873dbd Actually consume a bomb when using it, make the player invulnerable for a certain time, and implement deathbomb.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
227 self.bombs_used += 1
c9c2fb873dbd Actually consume a bomb when using it, make the player invulnerable for a certain time, and implement deathbomb.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
228 self.invulnerable_time = 240 #TODO: check the duration of bombs.
c9c2fb873dbd Actually consume a bomb when using it, make the player invulnerable for a certain time, and implement deathbomb.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
229 self.death_time = 0 # Deathbomb.
457
4ccc47828002 Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 447
diff changeset
230 if self.bomb_time > 0:
4ccc47828002 Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 447
diff changeset
231 self.bomb_time -= 1
4ccc47828002 Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 447
diff changeset
232 if self.bomb_time == 0:
4ccc47828002 Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 447
diff changeset
233 self._game.unset_player_bomb()
4ccc47828002 Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 447
diff changeset
234
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
235 if self.death_time:
447
78e1c3864e73 Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 445
diff changeset
236 time = self._game.frame - self.death_time
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
237 if time == 6: # too late, you are dead :(
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
238 self.touchable = False
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
239 if self.power > 16:
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
240 self.power -= 16
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
241 else:
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
242 self.power = 0
498
c9c2fb873dbd Actually consume a bomb when using it, make the player invulnerable for a certain time, and implement deathbomb.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
243 self.bombs = 3 #TODO: use the right default.
471
06f0eeb519bb Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 468
diff changeset
244 self._game.cancel_player_lasers()
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
245
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
246 self.miss += 1
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
247 self.lives -= 1
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
248 if self.lives < 0:
339
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
249 #TODO: display a menu to ask the players if they want to continue.
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
250 if self.continues == 0:
339
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
251 raise GameOver
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
252
465
5f5955635d2c Move continues to PlayerState, and make sure they aren’t reinitialized before each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 457
diff changeset
253 # Don’t decrement if it’s infinite.
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
254 if self.continues >= 0:
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
255 self.continues -= 1
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
256 self.continues_used += 1
465
5f5955635d2c Move continues to PlayerState, and make sure they aren’t reinitialized before each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 457
diff changeset
257
590
e15672733c93 Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
258 for i in range(5):
502
3d3285918ba1 Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 498
diff changeset
259 self._game.drop_bonus(self.x, self.y, 4, player=self,
339
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,
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))
574
94229756abd9 Give extra lives to the player once she has reached a certain score, and increment the default score on continue.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 547
diff changeset
262 self.score = self.continues_used if self.continues_used <= 9 else 9
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
263 self.effective_score = 0
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
264 self.lives = 2 #TODO: use the right default.
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
265 self.bombs = 3 #TODO: use the right default.
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
266 self.power = 0
339
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
267
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
268 self.graze = 0
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
269 self.points = 0
339
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
270 else:
502
3d3285918ba1 Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 498
diff changeset
271 self._game.drop_bonus(self.x, self.y, 2, player=self,
339
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
272 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
273 self._game.prng.rand_double() * 192 - 64)) # @0x41f3
590
e15672733c93 Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
274 for i in range(5):
502
3d3285918ba1 Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 498
diff changeset
275 self._game.drop_bonus(self.x, self.y, 0, player=self,
339
7a05edbab88a Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
276 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
277 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
278
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
279 elif time == 7:
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
280 self.sprite.mirrored = False
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
281 self.sprite.blendfunc = 0
527
db28538cd399 Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 509
diff changeset
282 self.sprite._rescale[:] = [0.75, 1.5]
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
283 self.sprite.fade(26, 96)
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
284 self.sprite.scale_in(26, 0., 2.5)
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
285
447
78e1c3864e73 Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 445
diff changeset
286 #TODO: the next two branches could be happening at the same frame.
78e1c3864e73 Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 445
diff changeset
287 elif time == 31:
78e1c3864e73 Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 445
diff changeset
288 self._game.cancel_bullets()
78e1c3864e73 Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 445
diff changeset
289
211
a765ef90c2b0 Make death animation closer to the original
Thibaut Girka <thib@sitedethib.com>
parents: 206
diff changeset
290 elif time == 32:
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
291 self.x = float(self._game.width) / 2. #TODO
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
292 self.y = float(self._game.width) #TODO
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
293 self.direction = 0
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
294
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
295 self.sprite = Sprite()
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 390
diff changeset
296 self.anmrunner = ANMRunner(self.anm, 0, self.sprite)
527
db28538cd399 Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 509
diff changeset
297 self.sprite._color[3] = 128
db28538cd399 Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 509
diff changeset
298 self.sprite._rescale[:] = [0., 2.5]
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
299 self.sprite.fade(30, 255)
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
300 self.sprite.blendfunc = 1
445
b0abb05811f7 Make pytouhou.game.player an extension type, and move the GameOver exception there since it makes more sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 444
diff changeset
301 self.sprite.scale_in(30, 1., 1.)
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
302
211
a765ef90c2b0 Make death animation closer to the original
Thibaut Girka <thib@sitedethib.com>
parents: 206
diff changeset
303 elif time == 61: # respawned
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
304 self.touchable = True
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
305 self.invulnerable_time = 240
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
306 self.sprite.blendfunc = 0
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
307 self.sprite.changed = True
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
308
447
78e1c3864e73 Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 445
diff changeset
309 elif time == 91: # start the bullet hell again
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
310 self.death_time = 0
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
311
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 303
diff changeset
312 self.anmrunner.run_frame()
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
313