changeset 197:e1bc8c4cbb1a

Do the right action when collecting an item.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 30 Oct 2011 11:29:08 -0700
parents 1e501e3b6645
children 13918723d1bc
files pytouhou/game/enemy.py pytouhou/game/game.py pytouhou/game/item.py pytouhou/game/itemtype.py pytouhou/game/player.py pytouhou/games/eosd.py
diffstat 6 files changed, 70 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/enemy.py
+++ b/pytouhou/game/enemy.py
@@ -17,7 +17,6 @@ from pytouhou.utils.interpolator import 
 from pytouhou.vm.anmrunner import ANMRunner
 from pytouhou.game.sprite import Sprite
 from pytouhou.game.bullet import Bullet
-from pytouhou.game.item import Item
 from math import cos, sin, atan2, pi
 
 
--- a/pytouhou/game/game.py
+++ b/pytouhou/game/game.py
@@ -67,14 +67,14 @@ class Game(object):
         if _type > 6:
             return
         item_type = self.item_types[_type]
-        item = Item((x, y), item_type, self, end_pos=end_pos)
+        item = Item((x, y), _type, item_type, self, end_pos=end_pos)
         self.items.append(item)
 
 
     def change_bullets_into_star_items(self):
         player = self.players[0] #TODO
         item_type = self.item_types[6]
-        self.items.extend(Item((bullet.x, bullet.y), item_type, self, player=player) for bullet in self.bullets)
+        self.items.extend(Item((bullet.x, bullet.y), 6, item_type, self, player=player) for bullet in self.bullets)
         self.bullets = []
 
 
@@ -248,7 +248,7 @@ class Game(object):
 
                 if not (bx2 < px1 or bx1 > px2
                         or by2 < py1 or by1 > py2):
-                    player.collect(item)
+                    item.on_collect(player.state)
 
 
     def cleanup(self):
--- a/pytouhou/game/item.py
+++ b/pytouhou/game/item.py
@@ -19,10 +19,11 @@ from pytouhou.utils.interpolator import 
 
 
 class Item(object):
-    def __init__(self, start_pos, item_type, game, angle=pi/2, speed=8., player=None, end_pos=None):
+    def __init__(self, start_pos, _type, item_type, game, angle=pi/2, speed=8., player=None, end_pos=None):
         self._game = game
         self._sprite = item_type.sprite
         self._removed = False
+        self._type = _type
         self._item_type = item_type
 
         self.hitbox_half_size = item_type.hitbox_size / 2.
@@ -50,6 +51,61 @@ class Item(object):
         self._sprite.angle = angle
 
 
+    def on_collect(self, player_state):
+        old_power = player_state.power
+
+        if self._type == 0 or self._type == 2: # power or big power
+            if old_power < 128:
+                player_state.power_bonus = 0
+                score = 10
+                player_state.power += (1 if self._type == 0 else 8)
+                if player_state.power > 128:
+                    player_state.power = 128
+            else:
+                bonus = player_state.power_bonus + (1 if self._type == 0 else 8)
+                if bonus > 30:
+                    bonus = 30
+                if bonus < 9:
+                    score = (bonus + 1) * 10
+                elif bonus < 18:
+                    score = (bonus - 8) * 100
+                elif bonus < 30:
+                    score = (bonus - 17) * 1000
+                elif bonus == 30:
+                    score = 51200
+                player_state.power_bonus = bonus
+            player_state.score += score
+
+        elif self._type == 1: # point
+            player_state.points += 1
+            if player_state.y < 128: #TODO: find the exact poc.
+                score = 100000
+            else:
+                score = 0 #TODO: find the formula.
+            player_state.score += score
+
+        elif self._type == 3: # bomb
+            if player_state.bombs < 8:
+                player_state.bombs += 1
+
+        elif self._type == 4: # full power
+            player_state.score += 1000
+            player_state.power = 128
+
+        elif self._type == 5: # 1up
+            if player_state.lives < 8:
+                player_state.lives += 1
+
+        elif self._type == 6: # star
+            player_state.score += 500
+
+        if old_power < 128 and player_state.power >= 128:
+            #TODO: display “full power”.
+            self._game.change_bullets_into_star_items()
+
+        self._removed = True
+
+
     def update(self):
         dx, dy = self.delta
 
--- a/pytouhou/game/itemtype.py
+++ b/pytouhou/game/itemtype.py
@@ -1,11 +1,10 @@
 from pytouhou.game.sprite import Sprite
 
 class ItemType(object):
-    def __init__(self, anm_wrapper, sprite_index, indicator_sprite_index, hitbox_size, score=0):
+    def __init__(self, anm_wrapper, sprite_index, indicator_sprite_index, hitbox_size=38.):
         self.anm_wrapper = anm_wrapper
         self.sprite = Sprite()
         self.sprite.anm, self.sprite.texcoords = anm_wrapper.get_sprite(sprite_index)
         self.indicator_sprite = Sprite()
         self.indicator_sprite.anm, self.indicator_sprite.texcoords = anm_wrapper.get_sprite(indicator_sprite_index)
         self.hitbox_size = hitbox_size
-        self.score = score
--- a/pytouhou/game/player.py
+++ b/pytouhou/game/player.py
@@ -41,6 +41,8 @@ class PlayerState(object):
         self.invulnerable_time = 240
         self.touchable = True
 
+        self.power_bonus = 0 # Never goes over 30.
+
 
 class Player(object):
     def __init__(self, state, game, anm_wrapper, speed=4., hitbox_size=2.5, graze_hitbox_size=42.):
@@ -95,12 +97,6 @@ class Player(object):
                 self._game.new_particle((self.state.x, self.state.y), 2, 4., 256) #TODO: find the real size and range.
 
 
-    def collect(self, item):
-        #TODO
-        self.state.score += item._item_type.score
-        item._removed = True
-
-
     def update(self, keystate):
         if self.death_time == 0 or self._game.frame - self.death_time > 60:
             try:
--- a/pytouhou/games/eosd.py
+++ b/pytouhou/games/eosd.py
@@ -37,13 +37,13 @@ class EoSDGame(Game):
                         BulletType(etama3, 8, 13, 20, 20, 20, hitbox_size=9),
                         BulletType(etama4, 0, 1, 2, 2, 2, hitbox_size=32)]
         #TODO: hitbox
-        item_types = [ItemType(etama3, 0, 7,  hitbox_size=42, score=10), #Power
-                      ItemType(etama3, 1, 8,  hitbox_size=42, score=100000), #Point, TODO: changes for hard, lunatic and poc
-                      ItemType(etama3, 2, 9,  hitbox_size=42, score=10), #Big power
-                      ItemType(etama3, 3, 10, hitbox_size=42), #Bomb
-                      ItemType(etama3, 4, 11, hitbox_size=42, score=1000), #Full power
-                      ItemType(etama3, 5, 12, hitbox_size=42), #1up
-                      ItemType(etama3, 6, 13, hitbox_size=42, score=500)] #Star
+        item_types = [ItemType(etama3, 0, 7), #Power
+                      ItemType(etama3, 1, 8), #Point
+                      ItemType(etama3, 2, 9), #Big power
+                      ItemType(etama3, 3, 10), #Bomb
+                      ItemType(etama3, 4, 11), #Full power
+                      ItemType(etama3, 5, 12), #1up
+                      ItemType(etama3, 6, 13)] #Star
 
         eosd_characters = [ReimuA, ReimuB, MarisaA, MarisaB]
         players = []