comparison pytouhou/game/game.py @ 274:f037bca24f2d

Partially implement lasers. “Launch animations”/“energy circles” are missing, aswell as collision and grazing.
author Thibaut Girka <thib@sitedethib.com>
date Sun, 05 Feb 2012 23:41:55 +0100
parents 3631abb6e95b
children 4838e9bab0f9
comparison
equal deleted inserted replaced
273:595b227886b1 274:f037bca24f2d
25 25
26 26
27 27
28 class Game(object): 28 class Game(object):
29 def __init__(self, resource_loader, players, stage, rank, difficulty, 29 def __init__(self, resource_loader, players, stage, rank, difficulty,
30 bullet_types, item_types, 30 bullet_types, laser_types, item_types,
31 nb_bullets_max=None, width=384, height=448, prng=None): 31 nb_bullets_max=None, width=384, height=448, prng=None):
32 self.resource_loader = resource_loader 32 self.resource_loader = resource_loader
33 33
34 self.width, self.height = width, height 34 self.width, self.height = width, height
35 35
36 self.nb_bullets_max = nb_bullets_max 36 self.nb_bullets_max = nb_bullets_max
37 self.bullet_types = bullet_types 37 self.bullet_types = bullet_types
38 self.laser_types = laser_types
38 self.item_types = item_types 39 self.item_types = item_types
39 40
40 self.players = players 41 self.players = players
41 self.enemies = [] 42 self.enemies = []
42 self.effects = [] 43 self.effects = []
43 self.bullets = [] 44 self.bullets = []
45 self.lasers = []
44 self.cancelled_bullets = [] 46 self.cancelled_bullets = []
45 self.players_bullets = [] 47 self.players_bullets = []
46 self.items = [] 48 self.items = []
47 49
48 self.stage = stage 50 self.stage = stage
111 113
112 114
113 def change_bullets_into_star_items(self): 115 def change_bullets_into_star_items(self):
114 player = self.players[0] #TODO 116 player = self.players[0] #TODO
115 item_type = self.item_types[6] 117 item_type = self.item_types[6]
116 self.items.extend(Item((bullet.x, bullet.y), 6, item_type, self, player=player) for bullet in self.bullets) 118 self.items.extend(Item((bullet.x, bullet.y), 6, item_type, self, player=player)
119 for bullet in self.bullets)
120 for laser in self.lasers:
121 self.items.extend(Item(pos, 6, item_type, self, player=player)
122 for pos in laser.get_bullets_pos())
123 laser.cancel()
117 self.bullets = [] 124 self.bullets = []
118 125
119 126
120 def new_effect(self, pos, anim, anm_wrapper=None): 127 def new_effect(self, pos, anim, anm_wrapper=None):
121 self.effects.append(Effect(pos, anim, anm_wrapper or self.etama4)) 128 self.effects.append(Effect(pos, anim, anm_wrapper or self.etama4))
153 self.update_effect() #TODO: Pri unknown 160 self.update_effect() #TODO: Pri unknown
154 self.update_players(keystate) # Pri 7 161 self.update_players(keystate) # Pri 7
155 self.update_enemies() # Pri 9 162 self.update_enemies() # Pri 9
156 self.update_effects() # Pri 10 163 self.update_effects() # Pri 10
157 self.update_bullets() # Pri 11 164 self.update_bullets() # Pri 11
165 for laser in self.lasers: #TODO: what priority is it?
166 laser.update()
158 # Pri 12 is HUD 167 # Pri 12 is HUD
159 168
160 # 4. Cleaning 169 # 4. Cleaning
161 self.cleanup() 170 self.cleanup()
162 171
271 self.players_bullets = [bullet for bullet in self.players_bullets 280 self.players_bullets = [bullet for bullet in self.players_bullets
272 if not bullet._removed] 281 if not bullet._removed]
273 self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets 282 self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets
274 if not bullet._removed] 283 if not bullet._removed]
275 284
285 # Filter “timed-out” lasers
286 self.lasers = [laser for laser in self.lasers if not laser._removed]
287
276 # Filter out-of-scren items 288 # Filter out-of-scren items
277 items = [] 289 items = []
278 for item in self.items: 290 for item in self.items:
279 if item.y < 448: 291 if item.y < 448:
280 items.append(item) 292 items.append(item)