# HG changeset patch # User Thibaut Girka # Date 1318264476 -7200 # Node ID ebfd328e700c6e70a247de0d71c6ec29f1be6640 # Parent ed86bec43b936eb1c74dafcfe9c19ce8204f7864 Rename a few functions, move a few things around... diff --git a/pytouhou/game/bullet.py b/pytouhou/game/bullet.py --- a/pytouhou/game/bullet.py +++ b/pytouhou/game/bullet.py @@ -107,10 +107,9 @@ class Bullet(object): (self.speed,), 16) - def collide(self, player): + def collide(self): #TODO: animation self._removed = True - player.die() def update(self): diff --git a/pytouhou/game/enemy.py b/pytouhou/game/enemy.py --- a/pytouhou/game/enemy.py +++ b/pytouhou/game/enemy.py @@ -147,12 +147,10 @@ class Enemy(object): self._anmrunner.run_frame() - def collide(self, player): - if self.touchable: - #TODO: animation - #TODO: doesn’t always kill herself (a boss for example), search how - self._removed = True - player.die() + def collide(self): + #TODO: animation + #TODO: doesn’t always kill herself (a boss for example), search how + self._removed = True def killed(self): diff --git a/pytouhou/game/game.py b/pytouhou/game/game.py --- a/pytouhou/game/game.py +++ b/pytouhou/game/game.py @@ -118,7 +118,8 @@ class Game(object): if not (bx2 < px1 or bx1 > px2 or by2 < py1 or by1 > py2): - bullet.collide(player) + bullet.collide() + player.collide() for enemy in self.enemies: half_size_x, half_size_y = enemy.hitbox_half_size @@ -126,9 +127,10 @@ class Game(object): bx1, bx2 = bx - half_size_x, bx + half_size_x by1, by2 = by - half_size_y, by + half_size_y - if not (bx2 < px1 or bx1 > px2 - or by2 < py1 or by1 > py2): - enemy.collide(player) + if enemy.touchable and not (bx2 < px1 or bx1 > px2 + or by2 < py1 or by1 > py2): + enemy.collide() + player.collide() for item in self.items: half_size = item.hitbox_half_size @@ -138,7 +140,7 @@ class Game(object): if not (bx2 < px1 or bx1 > px2 or by2 < py1 or by1 > py2): - item.collect(player) + player.collect(item) # 5. Cleaning self.cleanup() diff --git a/pytouhou/game/item.py b/pytouhou/game/item.py --- a/pytouhou/game/item.py +++ b/pytouhou/game/item.py @@ -50,11 +50,6 @@ class Item(object): self._sprite.angle = angle - def collect(self, player): - player.state.score += self._item_type.score - self._removed = True - - def update(self): dx, dy = self.delta diff --git a/pytouhou/game/player.py b/pytouhou/game/player.py --- a/pytouhou/game/player.py +++ b/pytouhou/game/player.py @@ -69,7 +69,7 @@ class Player(object): self._anmrunner.run_frame() - def die(self): + def collide(self): self.state.lives -= 1 self.state.x = 192.0 self.state.y = 384.0 @@ -77,6 +77,12 @@ class Player(object): #TODO: set invulnerability. + def collect(self, item): + #TODO + self.state.score += item._item_type.score + item._removed = True + + def update(self, keystate): try: dx, dy = {16: (0.0, -1.0), 32: (0.0, 1.0), 64: (-1.0, 0.0), 128: (1.0, 0.0),