Mercurial > touhou
comparison pytouhou/games/eosd.py @ 196:1e501e3b6645
Add a subclass for each character, and implement player attacks.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 29 Oct 2011 14:21:42 -0700 |
parents | |
children | e1bc8c4cbb1a |
comparison
equal
deleted
inserted
replaced
195:52c0b9399413 | 196:1e501e3b6645 |
---|---|
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 | |
16 from pytouhou.game.game import Game | |
17 from pytouhou.game.bullettype import BulletType | |
18 from pytouhou.game.itemtype import ItemType | |
19 from pytouhou.game.player import Player | |
20 from pytouhou.game.bullet import Bullet | |
21 | |
22 from math import pi | |
23 | |
24 | |
25 class EoSDGame(Game): | |
26 def __init__(self, resource_loader, player_states, stage, rank, difficulty, **kwargs): | |
27 etama3 = resource_loader.get_anm_wrapper(('etama3.anm',)) | |
28 etama4 = resource_loader.get_anm_wrapper(('etama4.anm',)) | |
29 bullet_types = [BulletType(etama3, 0, 11, 14, 15, 16, hitbox_size=4), | |
30 BulletType(etama3, 1, 12, 17, 18, 19, hitbox_size=6), | |
31 BulletType(etama3, 2, 12, 17, 18, 19, hitbox_size=4), | |
32 BulletType(etama3, 3, 12, 17, 18, 19, hitbox_size=6), | |
33 BulletType(etama3, 4, 12, 17, 18, 19, hitbox_size=5), | |
34 BulletType(etama3, 5, 12, 17, 18, 19, hitbox_size=4), | |
35 BulletType(etama3, 6, 13, 20, 20, 20, hitbox_size=16), | |
36 BulletType(etama3, 7, 13, 20, 20, 20, hitbox_size=11), | |
37 BulletType(etama3, 8, 13, 20, 20, 20, hitbox_size=9), | |
38 BulletType(etama4, 0, 1, 2, 2, 2, hitbox_size=32)] | |
39 #TODO: hitbox | |
40 item_types = [ItemType(etama3, 0, 7, hitbox_size=42, score=10), #Power | |
41 ItemType(etama3, 1, 8, hitbox_size=42, score=100000), #Point, TODO: changes for hard, lunatic and poc | |
42 ItemType(etama3, 2, 9, hitbox_size=42, score=10), #Big power | |
43 ItemType(etama3, 3, 10, hitbox_size=42), #Bomb | |
44 ItemType(etama3, 4, 11, hitbox_size=42, score=1000), #Full power | |
45 ItemType(etama3, 5, 12, hitbox_size=42), #1up | |
46 ItemType(etama3, 6, 13, hitbox_size=42, score=500)] #Star | |
47 | |
48 eosd_characters = [ReimuA, ReimuB, MarisaA, MarisaB] | |
49 players = [] | |
50 for player in player_states: | |
51 players.append(eosd_characters[player.character](player, self, resource_loader)) | |
52 | |
53 Game.__init__(self, resource_loader, players, stage, rank, difficulty, | |
54 bullet_types, item_types, nb_bullets_max=640, **kwargs) | |
55 | |
56 | |
57 class Reimu(Player): | |
58 def __init__(self, state, game, resource_loader): | |
59 anm_wrapper = resource_loader.get_anm_wrapper(('player00.anm',)) | |
60 self.bullet_angle = pi/30 #TODO: check | |
61 | |
62 Player.__init__(self, state, game, anm_wrapper, speed=4.) | |
63 | |
64 | |
65 def fire(self): | |
66 if self.fire_time % self.bullet_launch_interval == 0: | |
67 if self.state.power < 16: | |
68 bullets_per_shot = 1 | |
69 elif self.state.power < 48: | |
70 bullets_per_shot = 2 | |
71 elif self.state.power < 96: | |
72 bullets_per_shot = 3 | |
73 elif self.state.power < 128: | |
74 bullets_per_shot = 4 | |
75 elif self.state.power >= 128: | |
76 bullets_per_shot = 5 | |
77 | |
78 bullets = self._game.players_bullets | |
79 nb_bullets_max = self._game.nb_bullets_max | |
80 | |
81 bullet_angle = self.bullet_launch_angle - self.bullet_angle * (bullets_per_shot - 1) / 2. | |
82 for bullet_nb in range(bullets_per_shot): | |
83 if nb_bullets_max is not None and len(bullets) == nb_bullets_max: | |
84 break | |
85 | |
86 bullets.append(Bullet((self.x, self.y), self.bullet_type, 0, | |
87 bullet_angle, self.bullet_speed, | |
88 (0, 0, 0, 0, 0., 0., 0., 0.), | |
89 0, self, self._game, player_bullet=True)) | |
90 bullet_angle += self.bullet_angle | |
91 | |
92 | |
93 class ReimuA(Reimu): | |
94 def __init__(self, state, game, resource_loader): | |
95 Reimu.__init__(self, state, game, resource_loader) | |
96 | |
97 self.bulletA_type = BulletType(self.anm_wrapper, 65, 97, 0, 0, 0, hitbox_size=4, damage=48) #TODO: verify the hitbox and damages. | |
98 self.bulletA_speed = 12. | |
99 | |
100 | |
101 def fire(self): | |
102 Reimu.fire(self) | |
103 | |
104 if self.state.power < 8: | |
105 return | |
106 | |
107 else: | |
108 pass #TODO | |
109 | |
110 | |
111 class ReimuB(Reimu): | |
112 def __init__(self, state, game, resource_loader): | |
113 Reimu.__init__(self, state, game, resource_loader) | |
114 | |
115 self.bulletB_type = BulletType(self.anm_wrapper, 66, 98, 0, 0, 0, hitbox_size=4, damage=48) #TODO: verify the hitbox and damages. | |
116 self.bulletB_speed = 22. | |
117 | |
118 | |
119 def fire_spine(self, offset_x): | |
120 bullets = self._game.players_bullets | |
121 nb_bullets_max = self._game.nb_bullets_max | |
122 | |
123 if nb_bullets_max is not None and len(bullets) == nb_bullets_max: | |
124 return | |
125 | |
126 bullets.append(Bullet((self.x + offset_x, self.y), self.bulletB_type, 0, | |
127 self.bullet_launch_angle, self.bulletB_speed, | |
128 (0, 0, 0, 0, 0., 0., 0., 0.), | |
129 0, self, self._game, player_bullet=True)) | |
130 | |
131 | |
132 def fire(self): | |
133 Reimu.fire(self) | |
134 | |
135 if self.state.power < 8: | |
136 return | |
137 | |
138 elif self.state.power < 16: | |
139 if self.fire_time % 15 == 0: | |
140 for offset in (-24, 24): | |
141 self.fire_spine(offset) | |
142 | |
143 elif self.state.power < 32: | |
144 if self.fire_time % 10 == 0: | |
145 for offset in (-24, 24): | |
146 self.fire_spine(offset) | |
147 | |
148 elif self.state.power < 48: | |
149 if self.fire_time % 8 == 0: | |
150 for offset in (-24, 24): | |
151 self.fire_spine(offset) | |
152 | |
153 elif self.state.power < 96: | |
154 if self.fire_time % 5 == 0: | |
155 for offset in (-16, 32): | |
156 self.fire_spine(offset) | |
157 if self.fire_time % 8 == 0: | |
158 for offset in (-32, 16): | |
159 self.fire_spine(offset) | |
160 | |
161 elif self.state.power < 128: | |
162 if self.fire_time % 3 == 0: | |
163 for offset in (-12, 36): | |
164 self.fire_spine(offset) | |
165 if self.fire_time % 5 == 0: | |
166 for offset in (-36, 12): | |
167 self.fire_spine(offset) | |
168 if self.fire_time % 10 == 0: | |
169 for offset in (-24, 24): | |
170 self.fire_spine(offset) | |
171 | |
172 else: | |
173 if self.fire_time % 3 == 0: | |
174 for offset in (-36, -12, 12, 36): | |
175 self.fire_spine(offset) | |
176 if self.fire_time % 5 == 0: | |
177 for offset in (-24, 24): | |
178 self.fire_spine(offset) | |
179 | |
180 | |
181 class Marisa(Player): | |
182 def __init__(self, state, game, resource_loader): | |
183 anm_wrapper = resource_loader.get_anm_wrapper(('player01.anm',)) | |
184 self.bullet_angle = pi/40 #TODO: check | |
185 | |
186 Player.__init__(self, state, game, anm_wrapper, speed=5.) | |
187 | |
188 | |
189 def fire(self): | |
190 if self.fire_time % self.bullet_launch_interval == 0: | |
191 if self.state.power < 32: | |
192 bullets_per_shot = 1 | |
193 elif self.state.power < 96: | |
194 bullets_per_shot = 2 | |
195 elif self.state.power < 128: | |
196 bullets_per_shot = 3 | |
197 elif self.state.power >= 128: | |
198 bullets_per_shot = 5 | |
199 | |
200 bullets = self._game.players_bullets | |
201 nb_bullets_max = self._game.nb_bullets_max | |
202 | |
203 bullet_angle = self.bullet_launch_angle - self.bullet_angle * (bullets_per_shot - 1) / 2. | |
204 for bullet_nb in range(bullets_per_shot): | |
205 if nb_bullets_max is not None and len(bullets) == nb_bullets_max: | |
206 break | |
207 | |
208 bullets.append(Bullet((self.x, self.y), self.bullet_type, 0, | |
209 bullet_angle, self.bullet_speed, | |
210 (0, 0, 0, 0, 0., 0., 0., 0.), | |
211 0, self, self._game, player_bullet=True)) | |
212 bullet_angle += self.bullet_angle | |
213 | |
214 | |
215 class MarisaA(Marisa): | |
216 def __init__(self, state, game, resource_loader): | |
217 Marisa.__init__(self, state, game, resource_loader) | |
218 | |
219 #TODO: verify the hitbox and damages. | |
220 self.bulletA_types = [BulletType(self.anm_wrapper, 65, 0, 0, 0, 0, hitbox_size=4, damage=48), | |
221 BulletType(self.anm_wrapper, 66, 0, 0, 0, 0, hitbox_size=4, damage=48), | |
222 BulletType(self.anm_wrapper, 67, 0, 0, 0, 0, hitbox_size=4, damage=48), | |
223 BulletType(self.anm_wrapper, 68, 0, 0, 0, 0, hitbox_size=4, damage=48)] | |
224 self.bulletA_speed_interpolator = None | |
225 | |
226 | |
227 def fire(self): | |
228 Marisa.fire(self) | |
229 | |
230 if self.state.power < 8: | |
231 return | |
232 | |
233 else: | |
234 pass #TODO | |
235 | |
236 | |
237 class MarisaB(Marisa): | |
238 def __init__(self, state, game, resource_loader): | |
239 Marisa.__init__(self, state, game, resource_loader) | |
240 | |
241 self.laser_type = None | |
242 | |
243 | |
244 def fire(self): | |
245 Marisa.fire(self) | |
246 | |
247 if self.state.power < 8: | |
248 return | |
249 | |
250 else: | |
251 pass #TODO |