Mercurial > touhou
comparison pytouhou/game/item.py @ 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 | ebfd328e700c |
children | 13918723d1bc |
comparison
equal
deleted
inserted
replaced
196:1e501e3b6645 | 197:e1bc8c4cbb1a |
---|---|
17 | 17 |
18 from pytouhou.utils.interpolator import Interpolator | 18 from pytouhou.utils.interpolator import Interpolator |
19 | 19 |
20 | 20 |
21 class Item(object): | 21 class Item(object): |
22 def __init__(self, start_pos, item_type, game, angle=pi/2, speed=8., player=None, end_pos=None): | 22 def __init__(self, start_pos, _type, item_type, game, angle=pi/2, speed=8., player=None, end_pos=None): |
23 self._game = game | 23 self._game = game |
24 self._sprite = item_type.sprite | 24 self._sprite = item_type.sprite |
25 self._removed = False | 25 self._removed = False |
26 self._type = _type | |
26 self._item_type = item_type | 27 self._item_type = item_type |
27 | 28 |
28 self.hitbox_half_size = item_type.hitbox_size / 2. | 29 self.hitbox_half_size = item_type.hitbox_size / 2. |
29 | 30 |
30 self.frame = 0 | 31 self.frame = 0 |
48 (0.,), 60) | 49 (0.,), 60) |
49 | 50 |
50 self._sprite.angle = angle | 51 self._sprite.angle = angle |
51 | 52 |
52 | 53 |
54 def on_collect(self, player_state): | |
55 old_power = player_state.power | |
56 | |
57 if self._type == 0 or self._type == 2: # power or big power | |
58 if old_power < 128: | |
59 player_state.power_bonus = 0 | |
60 score = 10 | |
61 player_state.power += (1 if self._type == 0 else 8) | |
62 if player_state.power > 128: | |
63 player_state.power = 128 | |
64 else: | |
65 bonus = player_state.power_bonus + (1 if self._type == 0 else 8) | |
66 if bonus > 30: | |
67 bonus = 30 | |
68 if bonus < 9: | |
69 score = (bonus + 1) * 10 | |
70 elif bonus < 18: | |
71 score = (bonus - 8) * 100 | |
72 elif bonus < 30: | |
73 score = (bonus - 17) * 1000 | |
74 elif bonus == 30: | |
75 score = 51200 | |
76 player_state.power_bonus = bonus | |
77 player_state.score += score | |
78 | |
79 elif self._type == 1: # point | |
80 player_state.points += 1 | |
81 if player_state.y < 128: #TODO: find the exact poc. | |
82 score = 100000 | |
83 else: | |
84 score = 0 #TODO: find the formula. | |
85 player_state.score += score | |
86 | |
87 elif self._type == 3: # bomb | |
88 if player_state.bombs < 8: | |
89 player_state.bombs += 1 | |
90 | |
91 elif self._type == 4: # full power | |
92 player_state.score += 1000 | |
93 player_state.power = 128 | |
94 | |
95 elif self._type == 5: # 1up | |
96 if player_state.lives < 8: | |
97 player_state.lives += 1 | |
98 | |
99 elif self._type == 6: # star | |
100 player_state.score += 500 | |
101 | |
102 if old_power < 128 and player_state.power >= 128: | |
103 #TODO: display “full power”. | |
104 self._game.change_bullets_into_star_items() | |
105 | |
106 self._removed = True | |
107 | |
108 | |
53 def update(self): | 109 def update(self): |
54 dx, dy = self.delta | 110 dx, dy = self.delta |
55 | 111 |
56 if self.frame == 60: | 112 if self.frame == 60: |
57 self.speed_interpolator = Interpolator((0.,), 60, | 113 self.speed_interpolator = Interpolator((0.,), 60, |