Mercurial > touhou
annotate pytouhou/game/game.pyx @ 612:73f134f84c7f
Request a RGB888 context, since SDL2’s default of RGB332 sucks.
On X11/GLX, it will select the first config available, that is the best
one, while on EGL it will iterate over them to select the one closest
to what the application requested.
Of course, anything lower than RGB888 looks bad and we really don’t
want that.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 26 Mar 2015 20:20:37 +0100 |
parents | 3c2f96f1d715 |
children | a6af3ff86612 |
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 |
547
e35bef07290d
Always import runners from pytouhou.vm, to allow their replacement.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
545
diff
changeset
|
15 from pytouhou.vm import MSGRunner |
97 | 16 |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
17 from pytouhou.game.element cimport Element |
448
3bc37791f0a2
Make Bullet.state an enum.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
447
diff
changeset
|
18 from pytouhou.game.bullet cimport Bullet, LAUNCHED, CANCELLED |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
19 from pytouhou.game.enemy cimport Enemy |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
20 from pytouhou.game.item cimport Item |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
21 from pytouhou.game.effect cimport Particle |
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 Laser, PlayerLaser |
403
9589a01e6edf
Move MSG faces management to pytouhou.game.game, they have nothing to do in the MSG VM.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
390
diff
changeset
|
23 from pytouhou.game.face import Face |
97 | 24 |
25 | |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
26 cdef class Game: |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
27 def __init__(self, players, long stage, long rank, long difficulty, bullet_types, |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
28 laser_types, item_types, long nb_bullets_max=0, long width=384, |
509
292fea5c584e
Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
502
diff
changeset
|
29 long height=448, Random prng=None, interface=None, hints=None, |
292fea5c584e
Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
502
diff
changeset
|
30 bint friendly_fire=True): |
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
|
31 self.width, self.height = width, height |
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
|
32 |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
33 self.nb_bullets_max = nb_bullets_max |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
34 self.bullet_types = bullet_types |
274
f037bca24f2d
Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents:
259
diff
changeset
|
35 self.laser_types = laser_types |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
143
diff
changeset
|
36 self.item_types = item_types |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
37 |
196
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
193
diff
changeset
|
38 self.players = players |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
39 self.enemies = [] |
166
dcf32488a2c9
Better enemy death, with animation and (hopefully) correct flags handling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
165
diff
changeset
|
40 self.effects = [] |
106 | 41 self.bullets = [] |
274
f037bca24f2d
Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents:
259
diff
changeset
|
42 self.lasers = [] |
161
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
159
diff
changeset
|
43 self.cancelled_bullets = [] |
164
5271789c067d
Implement player bullets rendering and updating.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
44 self.players_bullets = [] |
294
94c636f8f863
Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
293
diff
changeset
|
45 self.players_lasers = [None, None] |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
143
diff
changeset
|
46 self.items = [] |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
47 self.labels = [] |
403
9589a01e6edf
Move MSG faces management to pytouhou.game.game, they have nothing to do in the MSG VM.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
390
diff
changeset
|
48 self.faces = [None, None] |
516
577c3a88fb67
Merge the lists Game.texts and Game.native_texts into the Game.texts dict.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
509
diff
changeset
|
49 self.texts = {} |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
299
diff
changeset
|
50 self.interface = interface |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
51 self.hints = hints |
106 | 52 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
53 self.stage = stage |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
54 self.rank = rank |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
55 self.difficulty = difficulty |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
56 self.difficulty_counter = 0 |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
57 self.difficulty_min = 12 if rank == 0 else 10 |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
58 self.difficulty_max = 20 if rank == 0 else 32 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
59 self.boss = None |
180
5a1533677a9a
Freeze time during spellcards
Thibaut Girka <thib@sitedethib.com>
parents:
176
diff
changeset
|
60 self.spellcard = None |
299
e04e402e6380
Implemented Sakuya's time stop.
Elias Boutaleb <kagekyio@gmail.com>
parents:
294
diff
changeset
|
61 self.time_stop = False |
286
4838e9bab0f9
Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
274
diff
changeset
|
62 self.msg_runner = None |
4838e9bab0f9
Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
274
diff
changeset
|
63 self.msg_wait = False |
203
df8b2ab54639
Make pylint slightly happier (and code analysis easier)
Thibaut Girka <thib@sitedethib.com>
parents:
202
diff
changeset
|
64 self.bonus_list = [0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, |
df8b2ab54639
Make pylint slightly happier (and code analysis easier)
Thibaut Girka <thib@sitedethib.com>
parents:
202
diff
changeset
|
65 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 2] |
373
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
372
diff
changeset
|
66 self.prng = prng |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
67 self.frame = 0 |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
68 self.sfx_player = None |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
69 |
306
52d791bb7c32
Rename a few attributes/methods to make a little more sense.
Thibaut Girka <thib@sitedethib.com>
parents:
305
diff
changeset
|
70 self.spellcard_effect = None |
217
577f45454402
Change background during spellcards.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
208
diff
changeset
|
71 |
188
008f90ebfdc0
Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents:
184
diff
changeset
|
72 # See 102h.exe@0x413220 if you think you're brave enough. |
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:
192
diff
changeset
|
73 self.deaths_count = self.prng.rand_uint16() % 3 |
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
192
diff
changeset
|
74 self.next_bonus = self.prng.rand_uint16() % 8 |
188
008f90ebfdc0
Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents:
184
diff
changeset
|
75 |
492
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
76 self.friendly_fire = friendly_fire |
286
4838e9bab0f9
Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
274
diff
changeset
|
77 self.last_keystate = 0 |
4838e9bab0f9
Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
274
diff
changeset
|
78 |
4838e9bab0f9
Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
274
diff
changeset
|
79 |
468
feecdb4a8928
Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
466
diff
changeset
|
80 cdef list msg_sprites(self): |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
81 return [face for face in self.faces if face is not None] if self.msg_runner is not None and not self.msg_runner.ended else [] |
286
4838e9bab0f9
Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
274
diff
changeset
|
82 |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
83 |
468
feecdb4a8928
Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
466
diff
changeset
|
84 cdef list lasers_sprites(self): |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
85 return [laser for laser in self.players_lasers if laser is not None] |
294
94c636f8f863
Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
293
diff
changeset
|
86 |
94c636f8f863
Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
293
diff
changeset
|
87 |
509
292fea5c584e
Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
502
diff
changeset
|
88 cdef void modify_difficulty(self, long diff) nogil: |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
89 self.difficulty_counter += diff |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
90 while self.difficulty_counter < 0: |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
91 self.difficulty -= 1 |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
92 self.difficulty_counter += 100 |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
93 while self.difficulty_counter >= 100: |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
94 self.difficulty += 1 |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
95 self.difficulty_counter -= 100 |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
96 if self.difficulty < self.difficulty_min: |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
97 self.difficulty = self.difficulty_min |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
98 elif self.difficulty > self.difficulty_max: |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
99 self.difficulty = self.difficulty_max |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
100 |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
101 |
468
feecdb4a8928
Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
466
diff
changeset
|
102 cpdef enable_spellcard_effect(self): |
457
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
103 pos = (-32, -16) |
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
104 self.spellcard_effect = Effect(pos, 0, |
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
105 self.spellcard_effect_anm) |
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
106 self.spellcard_effect.sprite.allow_dest_offset = True |
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
107 |
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
108 face = Effect(pos, 3, self.msg_anm[0][0][0]) |
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
109 face.sprite.allow_dest_offset = True |
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
110 face.sprite.anm, face.sprite.texcoords = self.msg_anm[1][self.spellcard[2]] |
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
111 self.effects.append(face) |
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
112 |
516
577c3a88fb67
Merge the lists Game.texts and Game.native_texts into the Game.texts dict.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
509
diff
changeset
|
113 self.texts['enemy_spellcard'] = self.new_native_text((384-24, 24), self.spellcard[1], align='right') |
217
577f45454402
Change background during spellcards.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
208
diff
changeset
|
114 |
577f45454402
Change background during spellcards.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
208
diff
changeset
|
115 |
468
feecdb4a8928
Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
466
diff
changeset
|
116 cpdef disable_spellcard_effect(self): |
306
52d791bb7c32
Rename a few attributes/methods to make a little more sense.
Thibaut Girka <thib@sitedethib.com>
parents:
305
diff
changeset
|
117 self.spellcard_effect = None |
516
577c3a88fb67
Merge the lists Game.texts and Game.native_texts into the Game.texts dict.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
509
diff
changeset
|
118 if 'enemy_spellcard' in self.texts: |
577c3a88fb67
Merge the lists Game.texts and Game.native_texts into the Game.texts dict.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
509
diff
changeset
|
119 del self.texts['enemy_spellcard'] |
457
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
120 |
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
121 |
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
|
122 cdef void set_player_bomb(self) except *: |
457
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
123 face = Effect((-32, -16), 1, self.msg_anm[0][0][0]) |
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
124 face.sprite.allow_dest_offset = True |
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
125 self.effects.append(face) |
516
577c3a88fb67
Merge the lists Game.texts and Game.native_texts into the Game.texts dict.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
509
diff
changeset
|
126 self.texts['player_spellcard'] = self.new_native_text((24, 24), u'Player Spellcard') |
457
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
127 |
4ccc47828002
Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
128 |
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
|
129 cdef void unset_player_bomb(self) except *: |
516
577c3a88fb67
Merge the lists Game.texts and Game.native_texts into the Game.texts dict.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
509
diff
changeset
|
130 del self.texts['player_spellcard'] |
217
577f45454402
Change background during spellcards.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
208
diff
changeset
|
131 |
577f45454402
Change background during spellcards.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
208
diff
changeset
|
132 |
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:
497
diff
changeset
|
133 cpdef drop_bonus(self, double x, double y, long _type, end_pos=None, player=None): |
165
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
164
diff
changeset
|
134 if _type > 6: |
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
164
diff
changeset
|
135 return |
303
647bde10353d
Add score/effective_score distinction and prepare for highscore handling.
Thibaut Girka <thib@sitedethib.com>
parents:
300
diff
changeset
|
136 if len(self.items) >= self.nb_bullets_max: |
647bde10353d
Add score/effective_score distinction and prepare for highscore handling.
Thibaut Girka <thib@sitedethib.com>
parents:
300
diff
changeset
|
137 return #TODO: check |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
138 item_type = self.item_types[_type] |
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:
497
diff
changeset
|
139 self.items.append(Item((x, y), _type, item_type, self, end_pos=end_pos, |
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:
497
diff
changeset
|
140 player=player)) |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
141 |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
142 |
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
|
143 cdef void autocollect(self, Player player) except *: |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
144 cdef Item item |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
145 |
208
d07506a2e16e
Implement autocollection of items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
203
diff
changeset
|
146 for item in self.items: |
446
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
147 item.autocollect(player) |
208
d07506a2e16e
Implement autocollection of items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
203
diff
changeset
|
148 |
d07506a2e16e
Implement autocollection of items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
203
diff
changeset
|
149 |
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
|
150 cdef void cancel_bullets(self) except *: |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
151 cdef Bullet bullet |
471
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
152 cdef Laser laser |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
153 |
335
2350147cf043
Fix bullet cancellation and removal
Thibaut Girka <thib@sitedethib.com>
parents:
328
diff
changeset
|
154 for bullet in self.bullets: |
2350147cf043
Fix bullet cancellation and removal
Thibaut Girka <thib@sitedethib.com>
parents:
328
diff
changeset
|
155 bullet.cancel() |
2350147cf043
Fix bullet cancellation and removal
Thibaut Girka <thib@sitedethib.com>
parents:
328
diff
changeset
|
156 for laser in self.lasers: |
2350147cf043
Fix bullet cancellation and removal
Thibaut Girka <thib@sitedethib.com>
parents:
328
diff
changeset
|
157 laser.cancel() |
2350147cf043
Fix bullet cancellation and removal
Thibaut Girka <thib@sitedethib.com>
parents:
328
diff
changeset
|
158 |
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
|
159 cdef void cancel_player_lasers(self) except *: |
471
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
160 cdef PlayerLaser laser |
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
161 for laser in self.players_lasers: |
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
162 if laser is not None: |
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
163 laser.cancel() |
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
164 |
335
2350147cf043
Fix bullet cancellation and removal
Thibaut Girka <thib@sitedethib.com>
parents:
328
diff
changeset
|
165 |
468
feecdb4a8928
Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
466
diff
changeset
|
166 cpdef change_bullets_into_star_items(self): |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
167 cdef Player player |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
168 cdef Bullet bullet |
471
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
169 cdef Laser laser |
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:
497
diff
changeset
|
170 cdef Item item |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
171 |
486 | 172 player = min(self.players, key=select_player_key) |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
143
diff
changeset
|
173 item_type = self.item_types[6] |
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:
497
diff
changeset
|
174 items = [Item((bullet.x, bullet.y), 6, item_type, self) |
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:
497
diff
changeset
|
175 for bullet in self.bullets] |
274
f037bca24f2d
Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents:
259
diff
changeset
|
176 for laser in self.lasers: |
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:
497
diff
changeset
|
177 items.extend([Item(pos, 6, item_type, self) |
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:
497
diff
changeset
|
178 for pos in laser.get_bullets_pos()]) |
274
f037bca24f2d
Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents:
259
diff
changeset
|
179 laser.cancel() |
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:
497
diff
changeset
|
180 for item in items: |
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:
497
diff
changeset
|
181 item.autocollect(player) |
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:
497
diff
changeset
|
182 self.items.extend(items) |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
143
diff
changeset
|
183 self.bullets = [] |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
143
diff
changeset
|
184 |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
143
diff
changeset
|
185 |
468
feecdb4a8928
Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
466
diff
changeset
|
186 cpdef change_bullets_into_bonus(self): |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
187 cdef Player player |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
188 cdef Bullet bullet |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
189 |
320
1a4ffdda8735
Cancel the bullets when a boss is killed and transfer them to the score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
316
diff
changeset
|
190 score = 0 |
1a4ffdda8735
Cancel the bullets when a boss is killed and transfer them to the score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
316
diff
changeset
|
191 bonus = 2000 |
1a4ffdda8735
Cancel the bullets when a boss is killed and transfer them to the score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
316
diff
changeset
|
192 for bullet in self.bullets: |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
193 self.new_label((bullet.x, bullet.y), str(bonus).encode()) |
320
1a4ffdda8735
Cancel the bullets when a boss is killed and transfer them to the score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
316
diff
changeset
|
194 score += bonus |
1a4ffdda8735
Cancel the bullets when a boss is killed and transfer them to the score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
316
diff
changeset
|
195 bonus += 10 |
1a4ffdda8735
Cancel the bullets when a boss is killed and transfer them to the score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
316
diff
changeset
|
196 self.bullets = [] |
1a4ffdda8735
Cancel the bullets when a boss is killed and transfer them to the score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
316
diff
changeset
|
197 #TODO: display the final bonus score. |
1a4ffdda8735
Cancel the bullets when a boss is killed and transfer them to the score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
316
diff
changeset
|
198 |
487
711c75115675
Various netplay-related fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
486
diff
changeset
|
199 #TODO: do we really want to give it to each player? |
711c75115675
Various netplay-related fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
486
diff
changeset
|
200 for player in self.players: |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
201 player.score += score |
487
711c75115675
Various netplay-related fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
486
diff
changeset
|
202 |
320
1a4ffdda8735
Cancel the bullets when a boss is killed and transfer them to the score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
316
diff
changeset
|
203 |
468
feecdb4a8928
Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
466
diff
changeset
|
204 cpdef kill_enemies(self): |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
205 cdef Enemy enemy |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
206 |
358
488c094ed51d
Make bosses clean their mess when timeouting
Thibaut Girka <thib@sitedethib.com>
parents:
343
diff
changeset
|
207 for enemy in self.enemies: |
488c094ed51d
Make bosses clean their mess when timeouting
Thibaut Girka <thib@sitedethib.com>
parents:
343
diff
changeset
|
208 if enemy.boss: |
488c094ed51d
Make bosses clean their mess when timeouting
Thibaut Girka <thib@sitedethib.com>
parents:
343
diff
changeset
|
209 pass # Bosses are immune to 96 |
488c094ed51d
Make bosses clean their mess when timeouting
Thibaut Girka <thib@sitedethib.com>
parents:
343
diff
changeset
|
210 elif enemy.touchable: |
488c094ed51d
Make bosses clean their mess when timeouting
Thibaut Girka <thib@sitedethib.com>
parents:
343
diff
changeset
|
211 enemy.life = 0 |
497
3da7395f39e3
Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
212 else: |
358
488c094ed51d
Make bosses clean their mess when timeouting
Thibaut Girka <thib@sitedethib.com>
parents:
343
diff
changeset
|
213 #TODO: check |
497
3da7395f39e3
Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
214 enemy.death_callback.fire() |
358
488c094ed51d
Make bosses clean their mess when timeouting
Thibaut Girka <thib@sitedethib.com>
parents:
343
diff
changeset
|
215 |
488c094ed51d
Make bosses clean their mess when timeouting
Thibaut Girka <thib@sitedethib.com>
parents:
343
diff
changeset
|
216 |
468
feecdb4a8928
Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
466
diff
changeset
|
217 cpdef new_effect(self, pos, long anim, anm=None, long number=1): |
388
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
380
diff
changeset
|
218 number = min(number, self.nb_bullets_max - len(self.effects)) |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
219 for i in range(number): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
220 self.effects.append(Effect(pos, anim, anm or self.etama[1])) |
181
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
180
diff
changeset
|
221 |
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
180
diff
changeset
|
222 |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
223 cpdef new_particle(self, pos, long anim, long amp, long number=1, bint reverse=False, long duration=24): |
388
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
380
diff
changeset
|
224 number = min(number, self.nb_bullets_max - len(self.effects)) |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
225 for i in range(number): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
226 self.effects.append(Particle(pos, anim, self.etama[1], amp, self, reverse=reverse, duration=duration)) |
173
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
172
diff
changeset
|
227 |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
172
diff
changeset
|
228 |
468
feecdb4a8928
Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
466
diff
changeset
|
229 cpdef new_enemy(self, pos, life, instr_type, bonus_dropped, die_score): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
230 enemy = Enemy(pos, life, instr_type, bonus_dropped, die_score, self.enm_anm, self) |
97 | 231 self.enemies.append(enemy) |
232 return enemy | |
233 | |
234 | |
468
feecdb4a8928
Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
466
diff
changeset
|
235 cpdef new_msg(self, sub): |
286
4838e9bab0f9
Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
274
diff
changeset
|
236 self.msg_runner = MSGRunner(self.msg, sub, self) |
4838e9bab0f9
Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
274
diff
changeset
|
237 self.msg_runner.run_iteration() |
4838e9bab0f9
Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
274
diff
changeset
|
238 |
4838e9bab0f9
Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
274
diff
changeset
|
239 |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
471
diff
changeset
|
240 cdef Text new_label(self, tuple pos, bytes text): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
241 label = Text(pos, self.interface.ascii_anm, text=text, xspacing=8, shift=48) |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
242 label.set_timeout(60, effect='move') |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
243 self.labels.append(label) |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
244 return label |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
245 |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
246 |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
471
diff
changeset
|
247 cpdef NativeText new_native_text(self, tuple pos, unicode text, align='left'): |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
448
diff
changeset
|
248 label = NativeText(pos, text, shadow=True, align=align) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
448
diff
changeset
|
249 return label |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
448
diff
changeset
|
250 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
448
diff
changeset
|
251 |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
471
diff
changeset
|
252 cpdef Text new_hint(self, hint): |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
253 pos = hint['Pos'] |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
254 #TODO: Scale |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
255 |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
256 pos = pos[0] + 192, pos[1] |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
257 label = Text(pos, self.interface.ascii_anm, text=hint['Text'], align=hint['Align']) |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
258 label.set_timeout(hint['Time']) |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
259 label.set_alpha(hint['Alpha']) |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
471
diff
changeset
|
260 label.set_color(None, hint['Color']) #XXX |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
261 self.labels.append(label) |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
262 return label |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
263 |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
264 |
468
feecdb4a8928
Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
466
diff
changeset
|
265 cpdef new_face(self, side, effect): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
266 face = Face(self.msg_anm, effect, side) |
403
9589a01e6edf
Move MSG faces management to pytouhou.game.game, they have nothing to do in the MSG VM.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
390
diff
changeset
|
267 self.faces[side] = face |
9589a01e6edf
Move MSG faces management to pytouhou.game.game, they have nothing to do in the MSG VM.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
390
diff
changeset
|
268 return face |
9589a01e6edf
Move MSG faces management to pytouhou.game.game, they have nothing to do in the MSG VM.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
390
diff
changeset
|
269 |
9589a01e6edf
Move MSG faces management to pytouhou.game.game, they have nothing to do in the MSG VM.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
390
diff
changeset
|
270 |
486 | 271 cpdef run_iter(self, list keystates): |
471
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
272 cdef Laser laser |
509
292fea5c584e
Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
502
diff
changeset
|
273 cdef long i |
486 | 274 |
97 | 275 # 1. VMs. |
372
704bea2e4360
Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
358
diff
changeset
|
276 for runner in self.ecl_runners: |
704bea2e4360
Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
358
diff
changeset
|
277 runner.run_iter() |
316
f0be7ea62330
Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
278 |
f0be7ea62330
Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
279 # 2. Modify difficulty |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
280 if self.frame % (32*60) == (32*60): #TODO: check if that is really that frame. |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
281 self.modify_difficulty(+100) |
97 | 282 |
316
f0be7ea62330
Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
283 # 3. Filter out destroyed enemies |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
284 self.enemies = filter_removed(self.enemies) |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
285 self.effects = filter_removed(self.effects) |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
286 self.bullets = filter_removed(self.bullets) |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
287 self.cancelled_bullets = filter_removed(self.cancelled_bullets) |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
288 self.items = filter_removed(self.items) |
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:
192
diff
changeset
|
289 |
316
f0be7ea62330
Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
290 # 4. Let's play! |
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:
192
diff
changeset
|
291 # In the original game, updates are done in prioritized functions called "chains" |
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
192
diff
changeset
|
292 # We have to mimic this functionnality to be replay-compatible with the official game. |
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
192
diff
changeset
|
293 |
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
192
diff
changeset
|
294 # Pri 6 is background |
306
52d791bb7c32
Rename a few attributes/methods to make a little more sense.
Thibaut Girka <thib@sitedethib.com>
parents:
305
diff
changeset
|
295 self.update_background() #TODO: Pri unknown |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
296 if self.msg_runner is not None: |
486 | 297 self.update_msg(keystates[0]) # Pri ? |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
298 for i in range(len(keystates)): |
486 | 299 keystates[i] &= ~3 # Remove the ability to attack (keystates 1 and 2). |
475
9d4d52793eca
Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents:
227
diff
changeset
|
300 self.update_players(keystates) # Pri 7 |
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:
192
diff
changeset
|
301 self.update_enemies() # Pri 9 |
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
192
diff
changeset
|
302 self.update_effects() # Pri 10 |
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
192
diff
changeset
|
303 self.update_bullets() # Pri 11 |
274
f037bca24f2d
Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents:
259
diff
changeset
|
304 for laser in self.lasers: #TODO: what priority is it? |
f037bca24f2d
Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents:
259
diff
changeset
|
305 laser.update() |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
299
diff
changeset
|
306 self.interface.update() # Pri 12 |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
307 if self.hints: |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
308 self.update_hints() # Not from this game, so unknown. |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
309 for label in self.labels: #TODO: what priority is it? |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
310 label.update() |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
311 for text in self.texts.values(): #TODO: what priority is it? |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
448
diff
changeset
|
312 if text is not None: |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
448
diff
changeset
|
313 text.update() |
403
9589a01e6edf
Move MSG faces management to pytouhou.game.game, they have nothing to do in the MSG VM.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
390
diff
changeset
|
314 self.update_faces() # Pri XXX |
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:
192
diff
changeset
|
315 |
316
f0be7ea62330
Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
316 # 5. Clean up |
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:
192
diff
changeset
|
317 self.cleanup() |
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
192
diff
changeset
|
318 |
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
192
diff
changeset
|
319 self.frame += 1 |
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
192
diff
changeset
|
320 |
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
192
diff
changeset
|
321 |
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
|
322 cdef void update_background(self) except *: |
299
e04e402e6380
Implemented Sakuya's time stop.
Elias Boutaleb <kagekyio@gmail.com>
parents:
294
diff
changeset
|
323 if self.time_stop: |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
324 return |
306
52d791bb7c32
Rename a few attributes/methods to make a little more sense.
Thibaut Girka <thib@sitedethib.com>
parents:
305
diff
changeset
|
325 if self.spellcard_effect is not None: |
52d791bb7c32
Rename a few attributes/methods to make a little more sense.
Thibaut Girka <thib@sitedethib.com>
parents:
305
diff
changeset
|
326 self.spellcard_effect.update() |
52d791bb7c32
Rename a few attributes/methods to make a little more sense.
Thibaut Girka <thib@sitedethib.com>
parents:
305
diff
changeset
|
327 #TODO: update the actual background here? |
217
577f45454402
Change background during spellcards.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
208
diff
changeset
|
328 |
577f45454402
Change background during spellcards.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
208
diff
changeset
|
329 |
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
|
330 cdef void update_enemies(self) except *: |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
331 cdef Enemy enemy |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
332 |
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:
192
diff
changeset
|
333 for enemy in self.enemies: |
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
192
diff
changeset
|
334 enemy.update() |
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
192
diff
changeset
|
335 |
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
192
diff
changeset
|
336 |
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
|
337 cdef void update_msg(self, long keystate) except *: |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
338 cdef long k |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
339 |
448
3bc37791f0a2
Make Bullet.state an enum.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
447
diff
changeset
|
340 for k in (1, 256): |
3bc37791f0a2
Make Bullet.state an enum.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
447
diff
changeset
|
341 if keystate & k and not self.last_keystate & k: |
3bc37791f0a2
Make Bullet.state an enum.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
447
diff
changeset
|
342 self.msg_runner.skip() |
3bc37791f0a2
Make Bullet.state an enum.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
447
diff
changeset
|
343 break |
336 | 344 self.msg_runner.skipping = bool(keystate & 256) |
286
4838e9bab0f9
Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
274
diff
changeset
|
345 self.last_keystate = keystate |
4838e9bab0f9
Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
274
diff
changeset
|
346 self.msg_runner.run_iteration() |
4838e9bab0f9
Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
274
diff
changeset
|
347 |
4838e9bab0f9
Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
274
diff
changeset
|
348 |
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
|
349 cdef void update_players(self, list keystates) except *: |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
350 cdef Bullet bullet |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
351 cdef Player player |
486 | 352 cdef long keystate |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
353 |
299
e04e402e6380
Implemented Sakuya's time stop.
Elias Boutaleb <kagekyio@gmail.com>
parents:
294
diff
changeset
|
354 if self.time_stop: |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
355 return |
328
56523a16db1d
Fix some replay synchronization issues and update the TODO.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
327
diff
changeset
|
356 |
56523a16db1d
Fix some replay synchronization issues and update the TODO.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
327
diff
changeset
|
357 for bullet in self.players_bullets: |
56523a16db1d
Fix some replay synchronization issues and update the TODO.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
327
diff
changeset
|
358 bullet.update() |
56523a16db1d
Fix some replay synchronization issues and update the TODO.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
327
diff
changeset
|
359 |
486 | 360 for player, keystate in zip(self.players, keystates): |
142
c7f0fd9d2145
Simple collision detection
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
361 player.update(keystate) #TODO: differentiate keystates (multiplayer mode) |
130 | 362 |
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
|
363 old_effective_score = player.effective_score |
486 | 364 #XXX: Why 78910? Is it really the right value? |
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
|
365 player.effective_score = min(old_effective_score + 78910, |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
366 player.score) |
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
|
367 if self.stage < 7: |
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
|
368 for i in [10000000, 20000000, 40000000, 60000000]: |
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
|
369 if player.effective_score >= i and old_effective_score < i: |
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
|
370 if player.lives < 8: |
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
|
371 player.lives += 1 |
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
|
372 self.modify_difficulty(+2) |
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
|
373 player.play_sound('extend') |
303
647bde10353d
Add score/effective_score distinction and prepare for highscore handling.
Thibaut Girka <thib@sitedethib.com>
parents:
300
diff
changeset
|
374 |
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:
192
diff
changeset
|
375 |
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
|
376 cdef void update_effects(self) except *: |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
377 cdef Element effect |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
378 |
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:
192
diff
changeset
|
379 for effect in self.effects: |
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
192
diff
changeset
|
380 effect.update() |
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
192
diff
changeset
|
381 |
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
192
diff
changeset
|
382 |
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
|
383 cdef void update_hints(self) except *: |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
384 for hint in self.hints: |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
385 if hint['Count'] == self.frame and hint['Base'] == 'start': |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
386 self.new_hint(hint) |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
387 |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
403
diff
changeset
|
388 |
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
|
389 cdef void update_faces(self) except *: |
403
9589a01e6edf
Move MSG faces management to pytouhou.game.game, they have nothing to do in the MSG VM.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
390
diff
changeset
|
390 for face in self.faces: |
9589a01e6edf
Move MSG faces management to pytouhou.game.game, they have nothing to do in the MSG VM.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
390
diff
changeset
|
391 if face: |
9589a01e6edf
Move MSG faces management to pytouhou.game.game, they have nothing to do in the MSG VM.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
390
diff
changeset
|
392 face.update() |
9589a01e6edf
Move MSG faces management to pytouhou.game.game, they have nothing to do in the MSG VM.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
390
diff
changeset
|
393 |
9589a01e6edf
Move MSG faces management to pytouhou.game.game, they have nothing to do in the MSG VM.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
390
diff
changeset
|
394 |
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
|
395 cdef void update_bullets(self) except *: |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
396 cdef Player player |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
397 cdef Bullet bullet |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
398 cdef Item item |
471
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
399 cdef PlayerLaser player_laser |
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
400 cdef Laser laser |
492
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
401 cdef PlayerLaser plaser |
471
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
402 cdef double player_pos[2] |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
403 |
299
e04e402e6380
Implemented Sakuya's time stop.
Elias Boutaleb <kagekyio@gmail.com>
parents:
294
diff
changeset
|
404 if self.time_stop: |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
405 return |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
406 |
161
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
159
diff
changeset
|
407 for bullet in self.cancelled_bullets: |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
159
diff
changeset
|
408 bullet.update() |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
159
diff
changeset
|
409 |
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:
192
diff
changeset
|
410 for bullet in self.bullets: |
164
5271789c067d
Implement player bullets rendering and updating.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
411 bullet.update() |
5271789c067d
Implement player bullets rendering and updating.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
412 |
471
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
413 for player_laser in self.players_lasers: |
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
414 if player_laser is not None: |
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
415 player_laser.update() |
294
94c636f8f863
Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
293
diff
changeset
|
416 |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
417 for item in self.items: |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
143
diff
changeset
|
418 item.update() |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
143
diff
changeset
|
419 |
142
c7f0fd9d2145
Simple collision detection
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
420 for player in self.players: |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
421 if not player.touchable: |
172
ea2ad94c33a0
Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
171
diff
changeset
|
422 continue |
ea2ad94c33a0
Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
171
diff
changeset
|
423 |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
424 px, py = player.x, player.y |
471
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
425 player_pos[:] = [px, py] |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
426 phalf_size = <double>player.sht.hitbox |
142
c7f0fd9d2145
Simple collision detection
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
427 px1, px2 = px - phalf_size, px + phalf_size |
c7f0fd9d2145
Simple collision detection
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
428 py1, py2 = py - phalf_size, py + phalf_size |
152
86807b8a63bd
Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
151
diff
changeset
|
429 |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
430 ghalf_size = <double>player.sht.graze_hitbox |
176
80a4c7ed43b3
Add grazing check.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
431 gx1, gx2 = px - ghalf_size, px + ghalf_size |
80a4c7ed43b3
Add grazing check.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
432 gy1, gy2 = py - ghalf_size, py + ghalf_size |
80a4c7ed43b3
Add grazing check.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
433 |
293
ab618c2bbce8
Implement laser collision.
Thibaut Girka <thib@sitedethib.com>
parents:
290
diff
changeset
|
434 for laser in self.lasers: |
471
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
435 if laser.check_collision(player_pos): |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
436 if player.invulnerable_time == 0: |
293
ab618c2bbce8
Implement laser collision.
Thibaut Girka <thib@sitedethib.com>
parents:
290
diff
changeset
|
437 player.collide() |
471
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
438 elif laser.check_grazing(player_pos): |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
439 player.graze += 1 #TODO |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
440 player.score += 500 #TODO |
343
94fdb6c782c1
Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
341
diff
changeset
|
441 player.play_sound('graze') |
293
ab618c2bbce8
Implement laser collision.
Thibaut Girka <thib@sitedethib.com>
parents:
290
diff
changeset
|
442 self.modify_difficulty(+6) #TODO |
388
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
380
diff
changeset
|
443 self.new_particle((px, py), 9, 192) #TODO |
293
ab618c2bbce8
Implement laser collision.
Thibaut Girka <thib@sitedethib.com>
parents:
290
diff
changeset
|
444 |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
445 for bullet in self.bullets: |
335
2350147cf043
Fix bullet cancellation and removal
Thibaut Girka <thib@sitedethib.com>
parents:
328
diff
changeset
|
446 if bullet.state != LAUNCHED: |
2350147cf043
Fix bullet cancellation and removal
Thibaut Girka <thib@sitedethib.com>
parents:
328
diff
changeset
|
447 continue |
2350147cf043
Fix bullet cancellation and removal
Thibaut Girka <thib@sitedethib.com>
parents:
328
diff
changeset
|
448 |
468
feecdb4a8928
Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
466
diff
changeset
|
449 bhalf_width = bullet.hitbox[0] |
feecdb4a8928
Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
466
diff
changeset
|
450 bhalf_height = bullet.hitbox[1] |
142
c7f0fd9d2145
Simple collision detection
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
451 bx, by = bullet.x, bullet.y |
390
b11953cf1d3b
Use only half-size hitboxes for player.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
388
diff
changeset
|
452 bx1, bx2 = bx - bhalf_width, bx + bhalf_width |
b11953cf1d3b
Use only half-size hitboxes for player.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
388
diff
changeset
|
453 by1, by2 = by - bhalf_height, by + bhalf_height |
142
c7f0fd9d2145
Simple collision detection
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
454 |
c7f0fd9d2145
Simple collision detection
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
455 if not (bx2 < px1 or bx1 > px2 |
c7f0fd9d2145
Simple collision detection
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
456 or by2 < py1 or by1 > py2): |
156
ebfd328e700c
Rename a few functions, move a few things around...
Thibaut Girka <thib@sitedethib.com>
parents:
154
diff
changeset
|
457 bullet.collide() |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
458 if player.invulnerable_time == 0: |
172
ea2ad94c33a0
Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
171
diff
changeset
|
459 player.collide() |
152
86807b8a63bd
Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
151
diff
changeset
|
460 |
181
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
180
diff
changeset
|
461 elif not bullet.grazed and not (bx2 < gx1 or bx1 > gx2 |
176
80a4c7ed43b3
Add grazing check.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
462 or by2 < gy1 or by1 > gy2): |
181
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
180
diff
changeset
|
463 bullet.grazed = True |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
464 player.graze += 1 |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
465 player.score += 500 # found experimentally |
343
94fdb6c782c1
Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
341
diff
changeset
|
466 player.play_sound('graze') |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
467 self.modify_difficulty(+6) |
388
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
380
diff
changeset
|
468 self.new_particle((px, py), 9, 192) #TODO: find the real size and range. |
181
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
180
diff
changeset
|
469 #TODO: display a static particle during one frame at |
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
180
diff
changeset
|
470 # 12 pixels of the player, in the axis of the “collision”. |
176
80a4c7ed43b3
Add grazing check.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
471 |
492
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
472 # Check for friendly-fire only if there are multiple players. |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
473 if self.friendly_fire and len(self.players) > 1: |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
474 for bullet in self.players_bullets: |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
475 if bullet.state != LAUNCHED: |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
476 continue |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
477 |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
478 if bullet.player == player.number: |
492
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
479 continue |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
480 |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
481 bhalf_width = bullet.hitbox[0] |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
482 bhalf_height = bullet.hitbox[1] |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
483 bx, by = bullet.x, bullet.y |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
484 bx1, bx2 = bx - bhalf_width, bx + bhalf_width |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
485 by1, by2 = by - bhalf_height, by + bhalf_height |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
486 |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
487 if not (bx2 < px1 or bx1 > px2 |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
488 or by2 < py1 or by1 > py2): |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
489 bullet.collide() |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
490 if player.invulnerable_time == 0: |
492
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
491 player.collide() |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
492 |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
493 for plaser in self.players_lasers: |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
494 if not plaser: |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
495 continue |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
496 |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
497 lhalf_width = plaser.hitbox[0] |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
498 lx, ly = plaser.x, plaser.y * 2. |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
499 lx1, lx2 = lx - lhalf_width, lx + lhalf_width |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
500 |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
501 if not (lx2 < px1 or lx1 > px2 |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
502 or ly < py1): |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
503 if player.invulnerable_time == 0: |
492
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
504 player.collide() |
887de1309491
Add friendly fire in netplay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
487
diff
changeset
|
505 |
208
d07506a2e16e
Implement autocollection of items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
203
diff
changeset
|
506 #TODO: is it the right place? |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
507 if py < 128 and player.power >= 128: #TODO: check py. |
208
d07506a2e16e
Implement autocollection of items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
203
diff
changeset
|
508 self.autocollect(player) |
d07506a2e16e
Implement autocollection of items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
203
diff
changeset
|
509 |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
510 ihalf_size = <double>player.sht.item_hitbox |
152
86807b8a63bd
Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
151
diff
changeset
|
511 for item in self.items: |
86807b8a63bd
Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
151
diff
changeset
|
512 bx, by = item.x, item.y |
390
b11953cf1d3b
Use only half-size hitboxes for player.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
388
diff
changeset
|
513 bx1, bx2 = bx - ihalf_size, bx + ihalf_size |
b11953cf1d3b
Use only half-size hitboxes for player.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
388
diff
changeset
|
514 by1, by2 = by - ihalf_size, by + ihalf_size |
152
86807b8a63bd
Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
151
diff
changeset
|
515 |
86807b8a63bd
Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
151
diff
changeset
|
516 if not (bx2 < px1 or bx1 > px2 |
86807b8a63bd
Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
151
diff
changeset
|
517 or by2 < py1 or by1 > py2): |
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:
217
diff
changeset
|
518 item.on_collect(player) |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
143
diff
changeset
|
519 |
97 | 520 |
466
b16d34fca5b4
Revert a change in 78e1c3864e73, causing boss rush to not destroy any standard enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
521 cpdef cleanup(self): |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
522 cdef Enemy enemy |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
523 cdef Bullet bullet |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
524 cdef Item item |
471
06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
525 cdef PlayerLaser laser |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
526 cdef long i |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
527 |
97 | 528 # Filter out non-visible enemies |
255
a0d6b1915591
Fix bullet removal condition.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
529 for enemy in self.enemies: |
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
|
530 if enemy.is_visible(self.width, self.height): |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
303
diff
changeset
|
531 enemy.was_visible = True |
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
303
diff
changeset
|
532 elif enemy.was_visible: |
97 | 533 # Filter out-of-screen enemy |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
303
diff
changeset
|
534 enemy.removed = True |
255
a0d6b1915591
Fix bullet removal condition.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
535 |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
536 self.enemies = filter_removed(self.enemies) |
97 | 537 |
538 # Filter out-of-scren bullets | |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
539 cancelled_bullets = [] |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
540 bullets = [] |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
541 players_bullets = [] |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
542 |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
543 for bullet in self.cancelled_bullets: |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
544 if bullet.state == CANCELLED and not bullet.removed: |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
545 cancelled_bullets.append(bullet) |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
546 |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
547 for bullet in self.bullets: |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
548 if not bullet.removed: |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
549 if bullet.state == CANCELLED: |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
550 cancelled_bullets.append(bullet) |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
551 else: |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
552 bullets.append(bullet) |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
553 |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
554 for bullet in self.players_bullets: |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
555 if not bullet.removed: |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
556 if bullet.state == CANCELLED: |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
557 cancelled_bullets.append(bullet) |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
558 else: |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
559 players_bullets.append(bullet) |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
560 |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
561 self.cancelled_bullets = cancelled_bullets |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
562 self.bullets = bullets |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
563 self.players_bullets = players_bullets |
97 | 564 |
274
f037bca24f2d
Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents:
259
diff
changeset
|
565 # Filter “timed-out” lasers |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
566 for i, laser in enumerate(self.players_lasers): |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
567 if laser is not None and laser.removed: |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
568 self.players_lasers[i] = None |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
569 |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
570 self.lasers = filter_removed(self.lasers) |
274
f037bca24f2d
Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents:
259
diff
changeset
|
571 |
165
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
164
diff
changeset
|
572 # Filter out-of-scren items |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
573 items = [] |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
574 for item in self.items: |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
299
diff
changeset
|
575 if item.y < self.height: |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
576 items.append(item) |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
577 else: |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
578 self.modify_difficulty(-3) |
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
579 self.items = items |
165
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
164
diff
changeset
|
580 |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
581 self.effects = filter_removed(self.effects) |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
582 self.labels = filter_removed(self.labels) |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
583 self.texts = {key: text for key, text in self.texts.items() if not text.removed} |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
584 |
97 | 585 # Disable boss mode if it is dead/it has timeout |
545
bcff39c920ab
Set boss mode directly from the enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
516
diff
changeset
|
586 if self.boss and self.boss.removed: |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
587 self.boss = None |
97 | 588 |
486 | 589 |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
590 cdef list filter_removed(list elements): |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
591 cdef Element element |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
592 |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
593 filtered = [] |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
594 for element in elements: |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
595 if not element.removed: |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
596 filtered.append(element) |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
446
diff
changeset
|
597 return filtered |
486 | 598 |
599 | |
600 def select_player_key(player): | |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
601 return (player.score, player.character) |