comparison pytouhou/game/item.py @ 220:0595315d3880

Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 18 Dec 2011 14:14:32 +0100
parents d07506a2e16e
children 5afc75f71fed
comparison
equal deleted inserted replaced
219:091301805cce 220:0595315d3880
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, _type, 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, 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._type = _type
27 self._item_type = item_type 27 self._item_type = item_type
28 28
29 self.hitbox_half_size = item_type.hitbox_size / 2. 29 self.hitbox_half_size = item_type.hitbox_size / 2.
30 30
31 self.frame = 0 31 self.frame = 0
32
33 self.player = player
34
35 self.x, self.y = start_pos 32 self.x, self.y = start_pos
36 self.angle = angle 33 self.angle = angle
37 self.speed = speed 34
38 dx, dy = cos(angle) * speed, sin(angle) * speed 35 if player:
39 self.delta = dx, dy 36 self.autocollect(player)
37 else:
38 self.player = None
40 39
41 if not player: 40 if not player:
42 #TODO: find the formulae in the binary. 41 #TODO: find the formulae in the binary.
43 self.speed_interpolator = None 42 self.speed_interpolator = None
44 if end_pos: 43 if end_pos:
51 self._sprite.angle = angle 50 self._sprite.angle = angle
52 51
53 52
54 def autocollect(self, player): 53 def autocollect(self, player):
55 self.player = player 54 self.player = player
56 self.speed = 8. 55 self.speed = player.sht.autocollection_speed if hasattr(player, 'sht') else 8.
57 56
58 57
59 def on_collect(self, player_state): 58 def on_collect(self, player):
59 player_state = player.state
60 old_power = player_state.power 60 old_power = player_state.power
61 61
62 if self._type == 0 or self._type == 2: # power or big power 62 if self._type == 0 or self._type == 2: # power or big power
63 if old_power < 128: 63 if old_power < 128:
64 player_state.power_bonus = 0 64 player_state.power_bonus = 0
82 player_state.score += score 82 player_state.score += score
83 self._game.modify_difficulty(+1) 83 self._game.modify_difficulty(+1)
84 84
85 elif self._type == 1: # point 85 elif self._type == 1: # point
86 player_state.points += 1 86 player_state.points += 1
87 if player_state.y < 128: #TODO: find the exact poc. 87 poc = player.sht.point_of_collection if hasattr(player, 'sht') else 128 #TODO: find the exact poc in EoSD.
88 if player_state.y < poc:
88 score = 100000 89 score = 100000
89 self._game.modify_difficulty(+30) 90 self._game.modify_difficulty(+30)
90 else: 91 else:
91 score = 0 #TODO: find the formula. 92 score = 0 #TODO: find the formula.
92 self._game.modify_difficulty(+3) 93 self._game.modify_difficulty(+3)
115 116
116 self._removed = True 117 self._removed = True
117 118
118 119
119 def update(self): 120 def update(self):
120 dx, dy = self.delta
121
122 if self.frame == 60: 121 if self.frame == 60:
123 self.speed_interpolator = Interpolator((0.,), 60, 122 self.speed_interpolator = Interpolator((0.,), 60,
124 (3.,), 180) 123 (3.,), 180)
125 124
126 if self.player is not None: 125 if self.player is not None:
132 self.x, self.y = self.pos_interpolator.values 131 self.x, self.y = self.pos_interpolator.values
133 else: 132 else:
134 self.speed_interpolator.update(self.frame) 133 self.speed_interpolator.update(self.frame)
135 self.speed, = self.speed_interpolator.values 134 self.speed, = self.speed_interpolator.values
136 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed 135 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed
137 self.delta = dx, dy
138 self.x += dx 136 self.x += dx
139 self.y += dy 137 self.y += dy
140 138
141 self.frame += 1 139 self.frame += 1
142 140