changeset 156:ebfd328e700c

Rename a few functions, move a few things around...
author Thibaut Girka <thib@sitedethib.com>
date Mon, 10 Oct 2011 18:34:36 +0200
parents ed86bec43b93
children ca6f8b3f739d
files pytouhou/game/bullet.py pytouhou/game/enemy.py pytouhou/game/game.py pytouhou/game/item.py pytouhou/game/player.py
diffstat 5 files changed, 19 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- 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):
--- 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):
--- 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()
--- 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
 
--- 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),