comparison pytouhou/game/laser.py @ 290:18e4ed141dd8

Display lasers' “launch anim”.
author Thibaut Girka <thib@sitedethib.com>
date Wed, 15 Feb 2012 18:37:52 +0100
parents 13dcde917083
children ab618c2bbce8
comparison
equal deleted inserted replaced
289:e7f40bff72fc 290:18e4ed141dd8
19 19
20 20
21 STARTING, STARTED, STOPPING = range(3) 21 STARTING, STARTED, STOPPING = range(3)
22 22
23 23
24 class LaserLaunchAnim(object):
25 def __init__(self, laser, anm_wrapper, index):
26 self._laser = laser
27 self._sprite = Sprite()
28 self._sprite.anm, self._sprite.texcoords = anm_wrapper.get_sprite(index)
29 self._sprite.blendfunc = 1
30 self._removed = False
31 self.x, self.y = 0, 0
32
33
34 def update(self):
35 laser = self._laser
36 length = min(laser.end_offset - laser.start_offset, laser.max_length)
37 offset = laser.end_offset - length
38 dx, dy = cos(laser.angle), sin(laser.angle)
39
40 self.x = laser.base_pos[0] + offset * dx
41 self.y = laser.base_pos[1] + offset * dy
42
43 scale = laser.width / 10. - (offset - laser.start_offset)
44 self._sprite.rescale = (scale, scale)
45 self._sprite._changed = True
46
47 if laser._removed or scale <= 0.:
48 self._removed = True
49
50
51
24 class Laser(object): 52 class Laser(object):
25 def __init__(self, base_pos, laser_type, sprite_idx_offset, 53 def __init__(self, base_pos, laser_type, sprite_idx_offset,
26 angle, speed, start_offset, end_offset, max_length, width, 54 angle, speed, start_offset, end_offset, max_length, width,
27 start_duration, duration, stop_duration, 55 start_duration, duration, stop_duration,
28 grazing_delay, grazing_extra_duration, 56 grazing_delay, grazing_extra_duration,
29 game): 57 game):
30 self._game = game 58 self._game = game
31 #TODO: aux sprite 59 launch_anim = LaserLaunchAnim(self, laser_type.anm_wrapper,
60 laser_type.launch_anim_offsets[sprite_idx_offset]
61 + laser_type.launch_sprite_idx)
62 self._game.effects.append(launch_anim)
32 self._sprite = None 63 self._sprite = None
33 self._anmrunner = None 64 self._anmrunner = None
34 self._removed = False 65 self._removed = False
35 self._laser_type = laser_type 66 self._laser_type = laser_type
36 self.state = STARTING 67 self.state = STARTING