annotate pytouhou/games/eosd/game.py @ 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 244c99c568c8
children 2cf518129725
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
597
244c99c568c8 Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 548
diff changeset
28 class Common(object):
503
c622eaf64428 Optimize GameRunner some more, fix replay, and remove Window dependency in Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
29 def __init__(self, resource_loader, player_characters, continues, stage,
c622eaf64428 Optimize GameRunner some more, fix replay, and remove Window dependency in Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
30 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
31 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
32
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
33 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
34 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
35 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
36 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
37 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
38 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
39 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
40 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
41 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
42 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
43 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
44 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
45 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
46 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
47 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
48 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
49 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
50 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
51 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
52 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
53 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
54 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
55 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
56 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
57 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
58
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 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
60 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
61
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 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
63 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
64 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
65 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
66 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
67 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
68 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
69
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 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
71 ('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
72 ('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
73 ('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
74 ('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
75 ('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
76 ('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
77
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
78 default_power = [0, 64, 128, 128, 128, 128, 0][stage]
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
79
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],
244c99c568c8 Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 548
diff changeset
95 character, default_power, 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
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 428
diff changeset
105 try:
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 428
diff changeset
106 self.enm_anm = resource_loader.get_multi_anm(('stg%denm.anm' % stage,
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 428
diff changeset
107 'stg%denm2.anm' % stage))
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 428
diff changeset
108 except KeyError:
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 428
diff changeset
109 self.enm_anm = resource_loader.get_anm('stg%denm.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
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
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
127
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
128 # 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
129 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
130
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 428
diff changeset
131 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
132 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
133
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
134 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
135
597
244c99c568c8 Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 548
diff changeset
136 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
137 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
138 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
139 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
140 friendly_fire)
300
da53bc29b94a Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 289
diff changeset
141
548
1e9ea6519f3c Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 547
diff changeset
142 try:
1e9ea6519f3c Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 547
diff changeset
143 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
144 except AttributeError:
1e9ea6519f3c Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 547
diff changeset
145 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
146
548
1e9ea6519f3c Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 547
diff changeset
147 try:
1e9ea6519f3c Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 547
diff changeset
148 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
149 except AttributeError:
1e9ea6519f3c Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 547
diff changeset
150 pass
345
2c4589370cc6 Display a boss remaining lives and timeout.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 341
diff changeset
151
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
152
206
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
153
597
244c99c568c8 Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 548
diff changeset
154 class Player(PlayerBase):
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
155 def __init__(self, number, anm, shts, character, power, continues):
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
156 self.sht = shts[0]
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
157 self.focused_sht = shts[1]
206
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
158
597
244c99c568c8 Don’t hardcode the available games and interfaces, and relocation them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 548
diff changeset
159 PlayerBase.__init__(self, number, anm, character, power, continues)
229
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
160
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
161 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
162 Orb(anm, 129, self)]
206
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
163
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
164 self.orbs[0].offset_x = -24
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
165 self.orbs[1].offset_x = 24
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
166
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
167 self.orb_dx_interpolator = None
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
168 self.orb_dy_interpolator = None
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
169
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
170
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
171 def start_focusing(self):
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
172 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
173 (8,), self._game.frame + 8,
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
174 lambda x: x ** 2)
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
175 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
176 (-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
177 self.focused = True
206
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
178
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
179
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
180 def stop_focusing(self):
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
181 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
182 (24,), self._game.frame + 8,
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
183 lambda x: x ** 2)
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
184 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
185 (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
186 self.focused = False
206
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
187
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
188
384
690b5faaa0e6 Make rendering of multiple-sprites elements work like single-sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 379
diff changeset
189 @property
206
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
190 def objects(self):
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
191 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
192
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
193
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
194 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
195 PlayerBase.update(self, keystate)
206
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
196
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
197 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
198 if self.orb_dx_interpolator:
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
199 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
200 dx, = self.orb_dx_interpolator.values
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
201 self.orbs[0].offset_x = -dx
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
202 self.orbs[1].offset_x = dx
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
203 if self.orb_dy_interpolator:
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
204 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
205 dy, = self.orb_dy_interpolator.values
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
206 self.orbs[0].offset_y = dy
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
207 self.orbs[1].offset_y = dy
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
208
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
209 for orb in self.orbs:
eca53abdfeab Fix ReimuA, and refactor Player a bit.
Thibaut Girka <thib@sitedethib.com>
parents: 200
diff changeset
210 orb.update()