# HG changeset patch # User Thibaut Girka # Date 1319798306 -7200 # Node ID 9f58e2a6e9505cdc51c8707df9083434cc333af3 # Parent 5e84dfd153ab34c727d4b7b44b3950eca814812d Fix particles, fix "random" item popping, change update order to match the original game's more closely. diff --git a/pytouhou/formats/t6rp.py b/pytouhou/formats/t6rp.py --- a/pytouhou/formats/t6rp.py +++ b/pytouhou/formats/t6rp.py @@ -71,8 +71,8 @@ class T6RP(object): raise Exception #TODO replay.unknown3 = unpack(' ex2 + or by2 < ey1 or by1 > ey2): + bullet.collide() + enemy.on_attack(bullet) + player.state.score += 90 # found experimentally + + + def update_players(self, keystate): for player in self.players: player.update(keystate) #TODO: differentiate keystates (multiplayer mode) if player.state.x < 8.: @@ -121,26 +159,53 @@ class Game(object): if player.state.y > 448.-16: #TODO player.state.y = 448.-16 - for enemy in self.enemies: - enemy.update() - - for enemy in self.effects: - enemy.update() - - for bullet in self.bullets: + for bullet in self.players_bullets: bullet.update() + # Check for collisions + for player in self.players: + if not player.state.touchable: + continue + + px, py = player.x, player.y + phalf_size = player.hitbox_half_size + px1, px2 = px - phalf_size, px + phalf_size + py1, py2 = py - phalf_size, py + phalf_size + + ghalf_size = player.graze_hitbox_half_size + gx1, gx2 = px - ghalf_size, px + ghalf_size + gy1, gy2 = py - ghalf_size, py + ghalf_size + + #TODO: Should that be done here or in update_enemies? + for enemy in self.enemies: + half_size_x, half_size_y = enemy.hitbox_half_size + bx, by = enemy.x, enemy.y + bx1, bx2 = bx - half_size_x, bx + half_size_x + by1, by2 = by - half_size_y, by + half_size_y + + #TODO: box-box or point-in-box? + if enemy.touchable and not (bx2 < px1 or bx1 > px2 + or by2 < py1 or by1 > py2): + enemy.on_collide() + if player.state.invulnerable_time == 0: + player.collide() + + + def update_effects(self): + for effect in self.effects: + effect.update() + + + def update_bullets(self): for bullet in self.cancelled_bullets: bullet.update() - for bullet in self.players_bullets: + for bullet in self.bullets: bullet.update() for item in self.items: item.update() - # 4. Check for collisions! - #TODO for player in self.players: if not player.state.touchable: continue @@ -171,22 +236,10 @@ class Game(object): bullet.grazed = True player.state.graze += 1 player.state.score += 500 # found experimentally - self.new_particle((px, py), 0, .8, 192, delay=True) #TODO: find the real size and range. + self.new_particle((px, py), 0, .8, 192) #TODO: find the real size and range. #TODO: display a static particle during one frame at # 12 pixels of the player, in the axis of the “collision”. - for enemy in self.enemies: - half_size_x, half_size_y = enemy.hitbox_half_size - bx, by = enemy.x, enemy.y - bx1, bx2 = bx - half_size_x, bx + half_size_x - by1, by2 = by - half_size_y, by + half_size_y - - if enemy.touchable and not (bx2 < px1 or bx1 > px2 - or by2 < py1 or by1 > py2): - enemy.on_collide() - if player.state.invulnerable_time == 0: - player.collide() - for item in self.items: half_size = item.hitbox_half_size bx, by = item.x, item.y @@ -197,29 +250,6 @@ class Game(object): or by2 < py1 or by1 > py2): player.collect(item) - for enemy in self.enemies: - ex, ey = enemy.x, enemy.y - ehalf_size_x, ehalf_size_y = enemy.hitbox_half_size - ex1, ex2 = ex - ehalf_size_x, ex + ehalf_size_x - ey1, ey2 = ey - ehalf_size_y, ey + ehalf_size_y - - for bullet in self.players_bullets: - half_size = bullet.hitbox_half_size - bx, by = bullet.x, bullet.y - bx1, bx2 = bx - half_size, bx + half_size - by1, by2 = by - half_size, by + half_size - - if not (bx2 < ex1 or bx1 > ex2 - or by2 < ey1 or by1 > ey2): - bullet.collide() - enemy.on_attack(bullet) - player.state.score += 90 # found experimentally - - # 5. Cleaning - self.cleanup() - - self.frame += 1 - def cleanup(self): # Filter out non-visible enemies diff --git a/pytouhou/game/player.py b/pytouhou/game/player.py --- a/pytouhou/game/player.py +++ b/pytouhou/game/player.py @@ -79,7 +79,7 @@ class Player(object): self.death_time = self._game.frame self._game.new_death((self.state.x, self.state.y), 2) for i in range(16): - self._game.new_particle((self.state.x, self.state.y), 2, 4., 256, delay=True) #TODO: find the real size and range. + self._game.new_particle((self.state.x, self.state.y), 2, 4., 256) #TODO: find the real size and range. def collect(self, item): diff --git a/pytouhou/vm/eclrunner.py b/pytouhou/vm/eclrunner.py --- a/pytouhou/vm/eclrunner.py +++ b/pytouhou/vm/eclrunner.py @@ -132,7 +132,7 @@ class ECLRunner(object): enm.drop_particles(7, 0) self._game.drop_bonus(enm.x, enm.y, enm._bonus_dropped) elif enm._bonus_dropped == -1: - if self._game.deaths_count % 3: + if self._game.deaths_count % 3 == 0: enm.drop_particles(10, 0) self._game.drop_bonus(enm.x, enm.y, self._game.bonus_list[self._game.next_bonus]) self._game.next_bonus = (self._game.next_bonus + 1) % 32