comparison pytouhou/game/item.pyx @ 494:6be9c99a3a24

Merge PlayerState into Player, fix player respawn position.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 14 Oct 2013 12:11:01 +0200
parents 1c891c71cf22
children 3d3285918ba1
comparison
equal deleted inserted replaced
493:26c082870dcf 494:6be9c99a3a24
76 76
77 77
78 cdef void on_collect(self, Player player): 78 cdef void on_collect(self, Player player):
79 cdef long level, poc 79 cdef long level, poc
80 80
81 player_state = player.state 81 old_power = player.power
82 old_power = player_state.power
83 score = 0 82 score = 0
84 label = None 83 label = None
85 color = 'white' 84 color = 'white'
86 player.play_sound('item00') 85 player.play_sound('item00')
87 86
88 if self._type == 0 or self._type == 2: # power or big power 87 if self._type == 0 or self._type == 2: # power or big power
89 if old_power < 128: 88 if old_power < 128:
90 player_state.power_bonus = 0 89 player.power_bonus = 0
91 score = 10 90 score = 10
92 player_state.power += (1 if self._type == 0 else 8) 91 player.power += (1 if self._type == 0 else 8)
93 if player_state.power > 128: 92 if player.power > 128:
94 player_state.power = 128 93 player.power = 128
95 for level in (8, 16, 32, 48, 64, 96): 94 for level in (8, 16, 32, 48, 64, 96):
96 if old_power < level and player_state.power >= level: 95 if old_power < level and player.power >= level:
97 label = self._game.new_label((self.x, self.y), b':') # Actually a “PowerUp” character. 96 label = self._game.new_label((self.x, self.y), b':') # Actually a “PowerUp” character.
98 color = 'blue' 97 color = 'blue'
99 label.set_color(color) 98 label.set_color(color)
100 labeled = True 99 labeled = True
101 else: 100 else:
102 bonus = player_state.power_bonus + (1 if self._type == 0 else 8) 101 bonus = player.power_bonus + (1 if self._type == 0 else 8)
103 if bonus > 30: 102 if bonus > 30:
104 bonus = 30 103 bonus = 30
105 if bonus < 9: 104 if bonus < 9:
106 score = (bonus + 1) * 10 105 score = (bonus + 1) * 10
107 elif bonus < 18: 106 elif bonus < 18:
109 elif bonus < 30: 108 elif bonus < 30:
110 score = (bonus - 17) * 1000 109 score = (bonus - 17) * 1000
111 elif bonus == 30: 110 elif bonus == 30:
112 score = 51200 111 score = 51200
113 color = 'yellow' 112 color = 'yellow'
114 player_state.power_bonus = bonus 113 player.power_bonus = bonus
115 self._game.modify_difficulty(+1) 114 self._game.modify_difficulty(+1)
116 115
117 elif self._type == 1: # point 116 elif self._type == 1: # point
118 player_state.points += 1 117 player.points += 1
119 poc = player.sht.point_of_collection 118 poc = player.sht.point_of_collection
120 if player_state.y < poc: 119 if player.y < poc:
121 score = 100000 120 score = 100000
122 self._game.modify_difficulty(+30) 121 self._game.modify_difficulty(+30)
123 color = 'yellow' 122 color = 'yellow'
124 else: 123 else:
125 #score = #TODO: find the formula. 124 #score = #TODO: find the formula.
126 self._game.modify_difficulty(+3) 125 self._game.modify_difficulty(+3)
127 126
128 elif self._type == 3: # bomb 127 elif self._type == 3: # bomb
129 if player_state.bombs < 8: 128 if player.bombs < 8:
130 player_state.bombs += 1 129 player.bombs += 1
131 self._game.modify_difficulty(+5) 130 self._game.modify_difficulty(+5)
132 131
133 elif self._type == 4: # full power 132 elif self._type == 4: # full power
134 score = 1000 133 score = 1000
135 player_state.power = 128 134 player.power = 128
136 135
137 elif self._type == 5: # 1up 136 elif self._type == 5: # 1up
138 if player_state.lives < 8: 137 if player.lives < 8:
139 player_state.lives += 1 138 player.lives += 1
140 self._game.modify_difficulty(+200) 139 self._game.modify_difficulty(+200)
141 player.play_sound('extend') 140 player.play_sound('extend')
142 141
143 elif self._type == 6: # star 142 elif self._type == 6: # star
144 score = 500 143 score = 500
145 144
146 if old_power < 128 and player_state.power == 128: 145 if old_power < 128 and player.power == 128:
147 #TODO: display “full power”. 146 #TODO: display “full power”.
148 self._game.change_bullets_into_star_items() 147 self._game.change_bullets_into_star_items()
149 148
150 if score > 0: 149 if score > 0:
151 player_state.score += score 150 player.score += score
152 if label is None: 151 if label is None:
153 label = self._game.new_label((self.x, self.y), str(score)) 152 label = self._game.new_label((self.x, self.y), str(score))
154 if color != 'white': 153 if color != 'white':
155 label.set_color(color) 154 label.set_color(color)
156 155
163 if self.frame == 60: 162 if self.frame == 60:
164 self.speed_interpolator = Interpolator((0.,), 60, 163 self.speed_interpolator = Interpolator((0.,), 60,
165 (3.,), 180) 164 (3.,), 180)
166 165
167 if self.player is not None: 166 if self.player is not None:
168 player_state = self.player.state 167 self.angle = atan2(self.player.y - self.y, self.player.x - self.x)
169 self.angle = atan2(player_state.y - self.y, player_state.x - self.x)
170 self.x += cos(self.angle) * self.speed 168 self.x += cos(self.angle) * self.speed
171 self.y += sin(self.angle) * self.speed 169 self.y += sin(self.angle) * self.speed
172 elif self.speed_interpolator is None: 170 elif self.speed_interpolator is None:
173 self.pos_interpolator.update(self.frame) 171 self.pos_interpolator.update(self.frame)
174 self.x, self.y = self.pos_interpolator.values 172 self.x, self.y = self.pos_interpolator.values