comparison pytouhou/game/game.pyx @ 486:2f53be1b2f60

Merge netplay branch.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 27 Sep 2013 19:01:47 +0200
parents pytouhou/game/game.py@1de67f332f00 pytouhou/game/game.py@1c891c71cf22
children 711c75115675
comparison
equal deleted inserted replaced
474:ca22df9e70bc 486:2f53be1b2f60
162 cpdef change_bullets_into_star_items(self): 162 cpdef change_bullets_into_star_items(self):
163 cdef Player player 163 cdef Player player
164 cdef Bullet bullet 164 cdef Bullet bullet
165 cdef Laser laser 165 cdef Laser laser
166 166
167 player = self.players[0] #TODO 167 player = min(self.players, key=select_player_key)
168 item_type = self.item_types[6] 168 item_type = self.item_types[6]
169 self.items.extend([Item((bullet.x, bullet.y), 6, item_type, self, player=player) 169 self.items.extend([Item((bullet.x, bullet.y), 6, item_type, self, player=player)
170 for bullet in self.bullets]) 170 for bullet in self.bullets])
171 for laser in self.lasers: 171 for laser in self.lasers:
172 self.items.extend([Item(pos, 6, item_type, self, player=player) 172 self.items.extend([Item(pos, 6, item_type, self, player=player)
257 face = Face(self.msg_anm, effect, side) 257 face = Face(self.msg_anm, effect, side)
258 self.faces[side] = face 258 self.faces[side] = face
259 return face 259 return face
260 260
261 261
262 cpdef run_iter(self, long keystate): 262 cpdef run_iter(self, list keystates):
263 cdef Laser laser 263 cdef Laser laser
264
264 # 1. VMs. 265 # 1. VMs.
265 for runner in self.ecl_runners: 266 for runner in self.ecl_runners:
266 runner.run_iter() 267 runner.run_iter()
267 268
268 # 2. Modify difficulty 269 # 2. Modify difficulty
281 # We have to mimic this functionnality to be replay-compatible with the official game. 282 # We have to mimic this functionnality to be replay-compatible with the official game.
282 283
283 # Pri 6 is background 284 # Pri 6 is background
284 self.update_background() #TODO: Pri unknown 285 self.update_background() #TODO: Pri unknown
285 if self.msg_runner is not None: 286 if self.msg_runner is not None:
286 self.update_msg(keystate) # Pri ? 287 self.update_msg(keystates[0]) # Pri ?
287 keystate &= ~3 # Remove the ability to attack (keystates 1 and 2). 288 for i in xrange(len(keystates)):
288 self.update_players(keystate) # Pri 7 289 keystates[i] &= ~3 # Remove the ability to attack (keystates 1 and 2).
290 self.update_players(keystates) # Pri 7
289 self.update_enemies() # Pri 9 291 self.update_enemies() # Pri 9
290 self.update_effects() # Pri 10 292 self.update_effects() # Pri 10
291 self.update_bullets() # Pri 11 293 self.update_bullets() # Pri 11
292 for laser in self.lasers: #TODO: what priority is it? 294 for laser in self.lasers: #TODO: what priority is it?
293 laser.update() 295 laser.update()
335 self.msg_runner.skipping = bool(keystate & 256) 337 self.msg_runner.skipping = bool(keystate & 256)
336 self.last_keystate = keystate 338 self.last_keystate = keystate
337 self.msg_runner.run_iteration() 339 self.msg_runner.run_iteration()
338 340
339 341
340 cdef void update_players(self, long keystate): 342 cdef void update_players(self, list keystates):
341 cdef Bullet bullet 343 cdef Bullet bullet
342 cdef Player player 344 cdef Player player
345 cdef long keystate
343 346
344 if self.time_stop: 347 if self.time_stop:
345 return 348 return
346 349
347 for bullet in self.players_bullets: 350 for bullet in self.players_bullets:
348 bullet.update() 351 bullet.update()
349 352
350 for player in self.players: 353 for player, keystate in zip(self.players, keystates):
351 player.update(keystate) #TODO: differentiate keystates (multiplayer mode) 354 player.update(keystate) #TODO: differentiate keystates (multiplayer mode)
352 355
353 #XXX: Why 78910? Is it really the right value? 356 #XXX: Why 78910? Is it really the right value?
354 player.state.effective_score = min(player.state.effective_score + 78910, 357 player.state.effective_score = min(player.state.effective_score + 78910,
355 player.state.score) 358 player.state.score)
356 #TODO: give extra lives to the player 359 #TODO: give extra lives to the player
357 360
358 361
359 cdef void update_effects(self): 362 cdef void update_effects(self):
360 cdef Element effect 363 cdef Element effect
361 364
538 541
539 # Disable boss mode if it is dead/it has timeout 542 # Disable boss mode if it is dead/it has timeout
540 if self.boss and self.boss._enemy.removed: 543 if self.boss and self.boss._enemy.removed:
541 self.boss = None 544 self.boss = None
542 545
546
543 cdef list filter_removed(list elements): 547 cdef list filter_removed(list elements):
544 cdef Element element 548 cdef Element element
545 549
546 filtered = [] 550 filtered = []
547 for element in elements: 551 for element in elements:
548 if not element.removed: 552 if not element.removed:
549 filtered.append(element) 553 filtered.append(element)
550 return filtered 554 return filtered
555
556
557 def select_player_key(player):
558 return (player.state.score, player.state.character)