comparison pytouhou/games/sample/game.py @ 598:a7286a0facf9

Add a sample game.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 25 Oct 2014 18:52:17 +0200
parents pytouhou/games/eosd/game.py@244c99c568c8
children d471b07ce4fd
comparison
equal deleted inserted replaced
597:244c99c568c8 598:a7286a0facf9
1 # -*- encoding: utf-8 -*-
2 ##
3 ## Copyright (C) 2011 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
4 ##
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published
7 ## by the Free Software Foundation; version 3 only.
8 ##
9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details.
13 ##
14
15 from pytouhou.utils.interpolator import Interpolator
16
17 from pytouhou.game.game import Game as GameBase
18 from pytouhou.game.bullettype import BulletType
19 from pytouhou.game.lasertype import LaserType
20 from pytouhou.game.itemtype import ItemType
21 from pytouhou.game.player import Player as PlayerBase
22 from pytouhou.game.orb import Orb
23 from pytouhou.game.background import Background
24
25 from pytouhou.vm import ECLMainRunner
26
27
28 class Common(object):
29 def __init__(self, resource_loader, player_characters, continues, stage,
30 width=384, height=448):
31 self.width, self.height = width, height
32
33 self.etama = resource_loader.get_multi_anm(('etama3.anm', 'etama4.anm'))
34 self.bullet_types = [BulletType(self.etama[0], 0, 11, 14, 15, 16, hitbox_size=2,
35 type_id=0),
36 BulletType(self.etama[0], 1, 12, 17, 18, 19, hitbox_size=3,
37 type_id=1),
38 BulletType(self.etama[0], 2, 12, 17, 18, 19, hitbox_size=2,
39 type_id=2),
40 BulletType(self.etama[0], 3, 12, 17, 18, 19, hitbox_size=3,
41 type_id=3),
42 BulletType(self.etama[0], 4, 12, 17, 18, 19, hitbox_size=2.5,
43 type_id=4),
44 BulletType(self.etama[0], 5, 12, 17, 18, 19, hitbox_size=2,
45 type_id=5),
46 BulletType(self.etama[0], 6, 13, 20, 20, 20, hitbox_size=8,
47 launch_anim_offsets=(0, 1, 1, 2, 2, 3, 4, 0),
48 type_id=6),
49 BulletType(self.etama[0], 7, 13, 20, 20, 20, hitbox_size=5.5,
50 launch_anim_offsets=(1, 1, 1, 1),
51 type_id=7),
52 BulletType(self.etama[0], 8, 13, 20, 20, 20, hitbox_size=4.5,
53 launch_anim_offsets=(0, 1, 1, 2, 2, 3, 4, 0),
54 type_id=8),
55 BulletType(self.etama[1], 0, 1, 2, 2, 2, hitbox_size=16,
56 launch_anim_offsets=(0, 1, 2, 3),
57 type_id=9)]
58
59 self.laser_types = [LaserType(self.etama[0], 9),
60 LaserType(self.etama[0], 10)]
61
62 self.item_types = [ItemType(self.etama[0], 0, 7), #Power
63 ItemType(self.etama[0], 1, 8), #Point
64 ItemType(self.etama[0], 2, 9), #Big power
65 ItemType(self.etama[0], 3, 10), #Bomb
66 ItemType(self.etama[0], 4, 11), #Full power
67 ItemType(self.etama[0], 5, 12), #1up
68 ItemType(self.etama[0], 6, 13)] #Star
69
70 self.enemy_face = [('face03a.anm', 'face03b.anm'),
71 ('face05a.anm',),
72 ('face06a.anm', 'face06b.anm'),
73 ('face08a.anm', 'face08b.anm'),
74 ('face09a.anm', 'face09b.anm'),
75 ('face09b.anm', 'face10a.anm', 'face10b.anm'),
76 ('face08a.anm', 'face12a.anm', 'face12b.anm', 'face12c.anm')]
77
78 default_power = [0, 64, 128, 128, 128, 128, 0][stage]
79
80 eosd_characters = resource_loader.get_eosd_characters()
81 self.first_character = player_characters[0] // 2
82 self.player_anms = {}
83 self.players = [None] * len(player_characters)
84 for i, player_character in enumerate(player_characters):
85 character = player_character // 2
86 if character not in self.player_anms:
87 face = resource_loader.get_multi_anm(('face0%da.anm' % character,
88 'face0%db.anm' % character,
89 'face0%dc.anm' % character))
90 anm = resource_loader.get_single_anm('player0%d.anm' % character)
91 self.player_anms[character] = (anm, face)
92
93 self.players[i] = Player(i, self.player_anms[character][0],
94 eosd_characters[player_character],
95 character, default_power, continues)
96
97
98
99 class Game(GameBase):
100 def __init__(self, resource_loader, stage, rank, difficulty,
101 common, prng, hints=None, friendly_fire=True,
102 nb_bullets_max=640):
103
104 self.etama = common.etama #XXX
105 try:
106 self.enm_anm = resource_loader.get_multi_anm(('stg%denm.anm' % stage,
107 'stg%denm2.anm' % stage))
108 except KeyError:
109 self.enm_anm = resource_loader.get_anm('stg%denm.anm' % stage)
110 ecl = resource_loader.get_ecl('ecldata%d.ecl' % stage)
111 self.ecl_runners = [ECLMainRunner(main, ecl.subs, self) for main in ecl.mains]
112
113 self.spellcard_effect_anm = resource_loader.get_single_anm('eff0%d.anm' % stage)
114
115 self.msg = resource_loader.get_msg('msg%d.dat' % stage)
116 msg_anm = [common.player_anms[common.first_character][1], #TODO: does it break bomb face of non-first player?
117 resource_loader.get_multi_anm(common.enemy_face[stage - 1])]
118
119 self.msg_anm = [[], []]
120 for i, anms in enumerate(msg_anm):
121 for anm in anms:
122 for sprite in anm.sprites.values():
123 self.msg_anm[i].append((anm, sprite))
124
125 for player in common.players:
126 player._game = self
127
128 # Load stage data
129 self.std = resource_loader.get_stage('stage%d.std' % stage)
130
131 background_anm = resource_loader.get_single_anm('stg%dbg.anm' % stage)
132 self.background = Background(self.std, background_anm)
133
134 common.interface.start_stage(self, stage)
135
136 GameBase.__init__(self, common.players, stage, rank, difficulty,
137 common.bullet_types, common.laser_types,
138 common.item_types, nb_bullets_max, common.width,
139 common.height, prng, common.interface, hints,
140 friendly_fire)
141
142
143
144 class Player(PlayerBase):
145 def __init__(self, number, anm, shts, character, power, continues):
146 self.sht = shts[0]
147 self.focused_sht = shts[1]
148
149 PlayerBase.__init__(self, number, anm, character, power, continues)
150
151 self.orbs = [Orb(anm, 128, self),
152 Orb(anm, 129, self)]
153
154 self.orbs[0].offset_x = -24
155 self.orbs[1].offset_x = 24
156
157 def start_focusing(self):
158 self.focused = True
159
160 def stop_focusing(self):
161 self.focused = False
162
163 @property
164 def objects(self):
165 return [self] + self.orbs
166
167 def update(self, keystate):
168 PlayerBase.update(self, keystate)
169
170 for orb in self.orbs:
171 orb.update()