Mercurial > touhou
comparison pytouhou/game/laser.py @ 294:94c636f8f863
Add player lasers for MarisaB.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 21 Feb 2012 14:28:38 +0100 |
parents | ab618c2bbce8 |
children | f3099ebf4f61 |
comparison
equal
deleted
inserted
replaced
293:ab618c2bbce8 | 294:94c636f8f863 |
---|---|
190 self._sprite.update_orientation(pi/2. - self.angle, True) | 190 self._sprite.update_orientation(pi/2. - self.angle, True) |
191 self._sprite._changed = True #TODO | 191 self._sprite._changed = True #TODO |
192 | 192 |
193 self.frame += 1 | 193 self.frame += 1 |
194 | 194 |
195 | |
196 class PlayerLaser(object): | |
197 def __init__(self, laser_type, sprite_idx_offset, hitbox, damage, | |
198 angle, offset, duration, origin): | |
199 self._sprite = None | |
200 self._anmrunner = None | |
201 self._removed = False | |
202 self._laser_type = laser_type | |
203 self.origin = origin | |
204 | |
205 self.hitbox_half_size = hitbox[0] / 2., hitbox[1] / 2. | |
206 | |
207 self.frame = 0 | |
208 self.duration = duration | |
209 | |
210 self.sprite_idx_offset = sprite_idx_offset | |
211 self.angle = angle | |
212 self.offset = offset | |
213 self.damage = damage | |
214 | |
215 self.set_anim() | |
216 | |
217 | |
218 @property | |
219 def x(self): | |
220 return self.origin.x + self.offset * cos(self.angle) | |
221 | |
222 | |
223 @property | |
224 def y(self): | |
225 return self.origin.y / 2. + self.offset * sin(self.angle) | |
226 | |
227 | |
228 def set_anim(self, sprite_idx_offset=None): | |
229 if sprite_idx_offset is not None: | |
230 self.sprite_idx_offset = sprite_idx_offset | |
231 | |
232 lt = self._laser_type | |
233 self._sprite = Sprite() | |
234 self._anmrunner = ANMRunner(lt.anm_wrapper, lt.anim_index, | |
235 self._sprite, self.sprite_idx_offset) | |
236 #self._sprite.blendfunc = 1 #XXX | |
237 self._anmrunner.run_frame() | |
238 | |
239 | |
240 def cancel(self): | |
241 self._anmrunner.interrupt(1) | |
242 | |
243 | |
244 def update(self): | |
245 if self._anmrunner is not None and not self._anmrunner.run_frame(): | |
246 self._anmrunner = None | |
247 self._removed = True | |
248 | |
249 length = self.origin.y | |
250 if self.frame == self.duration: | |
251 self.cancel() | |
252 | |
253 self._sprite.height_override = length or 0.01 #TODO | |
254 self._sprite._changed = True #TODO | |
255 | |
256 self.frame += 1 | |
257 |