changeset 208:d07506a2e16e

Implement autocollection of items.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 08 Nov 2011 22:10:44 -0800
parents 709f42eaa55e
children 005ea47e11e0
files pytouhou/game/game.py pytouhou/game/item.py
diffstat 2 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/game.py
+++ b/pytouhou/game/game.py
@@ -88,6 +88,12 @@ class Game(object):
         self.items.append(item)
 
 
+    def autocollect(self, player):
+        for item in self.items:
+            if not item.player:
+                item.autocollect(player)
+
+
     def change_bullets_into_star_items(self):
         player = self.players[0] #TODO
         item_type = self.item_types[6]
@@ -212,6 +218,10 @@ class Game(object):
                     #TODO: display a static particle during one frame at
                     # 12 pixels of the player, in the axis of the “collision”.
 
+            #TODO: is it the right place?
+            if py < 128 and player.state.power >= 128: #TODO: check py.
+                self.autocollect(player)
+
             for item in self.items:
                 half_size = item.hitbox_half_size
                 bx, by = item.x, item.y
--- a/pytouhou/game/item.py
+++ b/pytouhou/game/item.py
@@ -51,6 +51,11 @@ class Item(object):
         self._sprite.angle = angle
 
 
+    def autocollect(self, player):
+        self.player = player
+        self.speed = 8.
+
+
     def on_collect(self, player_state):
         old_power = player_state.power