Mercurial > touhou
annotate pytouhou/games/eosd/game.py @ 761:f506ad5c9b17
formats: Replace unwrap() with proper io::Error.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 06 Jan 2021 01:47:06 +0100 |
parents | df6ae915ebaa |
children |
rev | line source |
---|---|
196
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 ## |
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 ## Copyright (C) 2011 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 ## |
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 ## |
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 ## GNU General Public License for more details. |
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 ## |
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 |
206
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
15 from pytouhou.utils.interpolator import Interpolator |
196
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 |
597
244c99c568c8
Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
548
diff
changeset
|
17 from pytouhou.game.game import Game as GameBase |
196
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 from pytouhou.game.bullettype import BulletType |
274
f037bca24f2d
Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents:
262
diff
changeset
|
19 from pytouhou.game.lasertype import LaserType |
196
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 from pytouhou.game.itemtype import ItemType |
597
244c99c568c8
Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
548
diff
changeset
|
21 from pytouhou.game.player import Player as PlayerBase |
199
8ec34c56fed0
Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
22 from pytouhou.game.orb import Orb |
428
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
409
diff
changeset
|
23 from pytouhou.game.background import Background |
196
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 |
547
e35bef07290d
Always import runners from pytouhou.vm, to allow their replacement.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
545
diff
changeset
|
25 from pytouhou.vm import ECLMainRunner |
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:
216
diff
changeset
|
26 |
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:
216
diff
changeset
|
27 |
615
d1f0bb0b7a17
Don’t inherit explicitely from object, we are not on Python 2.7 anymore. :)
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
614
diff
changeset
|
28 class Common: |
614
2cf518129725
Delay power assignment to players until the game is started.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
597
diff
changeset
|
29 default_power = [0, 64, 128, 128, 128, 128, 0] |
2cf518129725
Delay power assignment to players until the game is started.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
597
diff
changeset
|
30 |
2cf518129725
Delay power assignment to players until the game is started.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
597
diff
changeset
|
31 def __init__(self, resource_loader, player_characters, continues, *, |
503
c622eaf64428
Optimize GameRunner some more, fix replay, and remove Window dependency in Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
32 width=384, height=448): |
c622eaf64428
Optimize GameRunner some more, fix replay, and remove Window dependency in Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
33 self.width, self.height = width, height |
c622eaf64428
Optimize GameRunner some more, fix replay, and remove Window dependency in Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
34 |
434
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
35 self.etama = resource_loader.get_multi_anm(('etama3.anm', 'etama4.anm')) |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
36 self.bullet_types = [BulletType(self.etama[0], 0, 11, 14, 15, 16, hitbox_size=2, |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
37 type_id=0), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
38 BulletType(self.etama[0], 1, 12, 17, 18, 19, hitbox_size=3, |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
39 type_id=1), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
40 BulletType(self.etama[0], 2, 12, 17, 18, 19, hitbox_size=2, |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
41 type_id=2), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
42 BulletType(self.etama[0], 3, 12, 17, 18, 19, hitbox_size=3, |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
43 type_id=3), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
44 BulletType(self.etama[0], 4, 12, 17, 18, 19, hitbox_size=2.5, |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
45 type_id=4), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
46 BulletType(self.etama[0], 5, 12, 17, 18, 19, hitbox_size=2, |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
47 type_id=5), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
48 BulletType(self.etama[0], 6, 13, 20, 20, 20, hitbox_size=8, |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
49 launch_anim_offsets=(0, 1, 1, 2, 2, 3, 4, 0), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
50 type_id=6), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
51 BulletType(self.etama[0], 7, 13, 20, 20, 20, hitbox_size=5.5, |
470
98995d8ac744
Reset ANMRunner.sprite_index_offset after the first frame, fixes bullettype 7; also forbid glitch bullet types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
52 launch_anim_offsets=(1, 1, 1, 1), |
434
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
53 type_id=7), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
54 BulletType(self.etama[0], 8, 13, 20, 20, 20, hitbox_size=4.5, |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
55 launch_anim_offsets=(0, 1, 1, 2, 2, 3, 4, 0), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
56 type_id=8), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
57 BulletType(self.etama[1], 0, 1, 2, 2, 2, hitbox_size=16, |
470
98995d8ac744
Reset ANMRunner.sprite_index_offset after the first frame, fixes bullettype 7; also forbid glitch bullet types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
58 launch_anim_offsets=(0, 1, 2, 3), |
434
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
59 type_id=9)] |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
60 |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
61 self.laser_types = [LaserType(self.etama[0], 9), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
62 LaserType(self.etama[0], 10)] |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
63 |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
64 self.item_types = [ItemType(self.etama[0], 0, 7), #Power |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
65 ItemType(self.etama[0], 1, 8), #Point |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
66 ItemType(self.etama[0], 2, 9), #Big power |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
67 ItemType(self.etama[0], 3, 10), #Bomb |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
68 ItemType(self.etama[0], 4, 11), #Full power |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
69 ItemType(self.etama[0], 5, 12), #1up |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
70 ItemType(self.etama[0], 6, 13)] #Star |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
71 |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
72 self.enemy_face = [('face03a.anm', 'face03b.anm'), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
73 ('face05a.anm',), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
74 ('face06a.anm', 'face06b.anm'), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
75 ('face08a.anm', 'face08b.anm'), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
76 ('face09a.anm', 'face09b.anm'), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
77 ('face09b.anm', 'face10a.anm', 'face10b.anm'), |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
78 ('face08a.anm', 'face12a.anm', 'face12b.anm', 'face12c.anm')] |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
79 |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
80 eosd_characters = resource_loader.get_eosd_characters() |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
81 self.first_character = player_characters[0] // 2 |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
82 self.player_anms = {} |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
83 self.players = [None] * len(player_characters) |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
84 for i, player_character in enumerate(player_characters): |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
85 character = player_character // 2 |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
86 if character not in self.player_anms: |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
87 face = resource_loader.get_multi_anm(('face0%da.anm' % character, |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
88 'face0%db.anm' % character, |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
89 'face0%dc.anm' % character)) |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
90 anm = resource_loader.get_single_anm('player0%d.anm' % character) |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
91 self.player_anms[character] = (anm, face) |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
92 |
597
244c99c568c8
Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
548
diff
changeset
|
93 self.players[i] = Player(i, self.player_anms[character][0], |
244c99c568c8
Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
548
diff
changeset
|
94 eosd_characters[player_character], |
614
2cf518129725
Delay power assignment to players until the game is started.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
597
diff
changeset
|
95 character, continues) |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
96 |
434
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
97 |
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
98 |
597
244c99c568c8
Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
548
diff
changeset
|
99 class Game(GameBase): |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
100 def __init__(self, resource_loader, stage, rank, difficulty, |
508
1bc014f9d572
Make GameRunner entirely independent of Window or GameRenderer, so we can run a game without display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
503
diff
changeset
|
101 common, prng, hints=None, friendly_fire=True, |
503
c622eaf64428
Optimize GameRunner some more, fix replay, and remove Window dependency in Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
102 nb_bullets_max=640): |
235
e59bd7979ddc
Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
233
diff
changeset
|
103 |
434
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
104 self.etama = common.etama #XXX |
623
df6ae915ebaa
Don’t load stg?enm.anm two times if there is no stg?enm2.anm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
615
diff
changeset
|
105 self.enm_anm = resource_loader.get_anm('stg%denm.anm' % stage) |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
106 try: |
623
df6ae915ebaa
Don’t load stg?enm.anm two times if there is no stg?enm2.anm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
615
diff
changeset
|
107 self.enm_anm = self.enm_anm + resource_loader.get_anm('stg%denm2.anm' % stage) |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
108 except KeyError: |
623
df6ae915ebaa
Don’t load stg?enm.anm two times if there is no stg?enm2.anm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
615
diff
changeset
|
109 pass |
428
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
409
diff
changeset
|
110 ecl = resource_loader.get_ecl('ecldata%d.ecl' % stage) |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
409
diff
changeset
|
111 self.ecl_runners = [ECLMainRunner(main, ecl.subs, self) for main in ecl.mains] |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
409
diff
changeset
|
112 |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
113 self.spellcard_effect_anm = resource_loader.get_single_anm('eff0%d.anm' % stage) |
428
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
409
diff
changeset
|
114 |
286
4838e9bab0f9
Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
274
diff
changeset
|
115 self.msg = resource_loader.get_msg('msg%d.dat' % stage) |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
116 msg_anm = [common.player_anms[common.first_character][1], #TODO: does it break bomb face of non-first player? |
434
18e4b121646b
Move the common parts of EoSDGame outside, to not reallocate them at each stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
117 resource_loader.get_multi_anm(common.enemy_face[stage - 1])] |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
118 |
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
119 self.msg_anm = [[], []] |
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
120 for i, anms in enumerate(msg_anm): |
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
121 for anm in anms: |
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
122 for sprite in anm.sprites.values(): |
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
123 self.msg_anm[i].append((anm, sprite)) |
286
4838e9bab0f9
Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
274
diff
changeset
|
124 |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
125 for player in common.players: |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
126 player._game = self |
614
2cf518129725
Delay power assignment to players until the game is started.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
597
diff
changeset
|
127 if player.power < 0: |
2cf518129725
Delay power assignment to players until the game is started.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
597
diff
changeset
|
128 player.power = common.default_power[stage - 1] |
196
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
129 |
428
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
409
diff
changeset
|
130 # Load stage data |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
409
diff
changeset
|
131 self.std = resource_loader.get_stage('stage%d.std' % stage) |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
409
diff
changeset
|
132 |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
133 background_anm = resource_loader.get_single_anm('stg%dbg.anm' % stage) |
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
428
diff
changeset
|
134 self.background = Background(self.std, background_anm) |
428
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
409
diff
changeset
|
135 |
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:
434
diff
changeset
|
136 common.interface.start_stage(self, stage) |
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:
434
diff
changeset
|
137 |
597
244c99c568c8
Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
548
diff
changeset
|
138 GameBase.__init__(self, common.players, stage, rank, difficulty, |
244c99c568c8
Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
548
diff
changeset
|
139 common.bullet_types, common.laser_types, |
244c99c568c8
Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
548
diff
changeset
|
140 common.item_types, nb_bullets_max, common.width, |
244c99c568c8
Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
548
diff
changeset
|
141 common.height, prng, common.interface, hints, |
244c99c568c8
Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
548
diff
changeset
|
142 friendly_fire) |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
289
diff
changeset
|
143 |
548
1e9ea6519f3c
Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
144 try: |
1e9ea6519f3c
Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
145 self.texts['stage_name'] = common.interface.stage_name |
1e9ea6519f3c
Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
146 except AttributeError: |
1e9ea6519f3c
Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
147 pass |
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:
434
diff
changeset
|
148 |
548
1e9ea6519f3c
Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
149 try: |
1e9ea6519f3c
Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
150 self.texts['song_name'] = common.interface.song_name |
1e9ea6519f3c
Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
151 except AttributeError: |
1e9ea6519f3c
Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
152 pass |
345
2c4589370cc6
Display a boss remaining lives and timeout.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
341
diff
changeset
|
153 |
196
1e501e3b6645
Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
154 |
206
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
155 |
597
244c99c568c8
Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
548
diff
changeset
|
156 class Player(PlayerBase): |
614
2cf518129725
Delay power assignment to players until the game is started.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
597
diff
changeset
|
157 def __init__(self, number, anm, shts, character, continues): |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
158 self.sht = shts[0] |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
159 self.focused_sht = shts[1] |
206
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
160 |
614
2cf518129725
Delay power assignment to players until the game is started.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
597
diff
changeset
|
161 PlayerBase.__init__(self, number, anm, character, continues, power=-1) |
229
5afc75f71fed
Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
220
diff
changeset
|
162 |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
163 self.orbs = [Orb(anm, 128, self), |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
164 Orb(anm, 129, self)] |
206
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
165 |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
166 self.orbs[0].offset_x = -24 |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
167 self.orbs[1].offset_x = 24 |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
168 |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
169 self.orb_dx_interpolator = None |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
170 self.orb_dy_interpolator = None |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
171 |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
172 |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
173 def start_focusing(self): |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
174 self.orb_dx_interpolator = Interpolator((24,), self._game.frame, |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
175 (8,), self._game.frame + 8, |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
176 lambda x: x ** 2) |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
177 self.orb_dy_interpolator = Interpolator((0,), self._game.frame, |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
178 (-32,), self._game.frame + 8) |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
179 self.focused = True |
206
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
180 |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
181 |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
182 def stop_focusing(self): |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
183 self.orb_dx_interpolator = Interpolator((8,), self._game.frame, |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
184 (24,), self._game.frame + 8, |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
185 lambda x: x ** 2) |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
186 self.orb_dy_interpolator = Interpolator((-32,), self._game.frame, |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
187 (0,), self._game.frame + 8) |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
188 self.focused = False |
206
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
189 |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
190 |
384
690b5faaa0e6
Make rendering of multiple-sprites elements work like single-sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
379
diff
changeset
|
191 @property |
206
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
192 def objects(self): |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
193 return [self] + (self.orbs if self.power >= 8 else []) |
206
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
194 |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
195 |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
196 def update(self, keystate): |
597
244c99c568c8
Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
548
diff
changeset
|
197 PlayerBase.update(self, keystate) |
206
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
198 |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
199 if self.death_time == 0 or self._game.frame - self.death_time > 60: |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
200 if self.orb_dx_interpolator: |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
201 self.orb_dx_interpolator.update(self._game.frame) |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
202 dx, = self.orb_dx_interpolator.values |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
203 self.orbs[0].offset_x = -dx |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
204 self.orbs[1].offset_x = dx |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
205 if self.orb_dy_interpolator: |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
206 self.orb_dy_interpolator.update(self._game.frame) |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
207 dy, = self.orb_dy_interpolator.values |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
208 self.orbs[0].offset_y = dy |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
209 self.orbs[1].offset_y = dy |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
210 |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
211 for orb in self.orbs: |
eca53abdfeab
Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
200
diff
changeset
|
212 orb.update() |