comparison pytouhou/game/laser.py @ 440:b9d2db93972f

Add a base Element class for every object in pytouhou.game.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 30 Aug 2013 14:16:08 +0200
parents 1222341ea22c
children 5bb7d2c0ff46
comparison
equal deleted inserted replaced
439:723a3e67a223 440:b9d2db93972f
12 ## GNU General Public License for more details. 12 ## GNU General Public License for more details.
13 ## 13 ##
14 14
15 from math import cos, sin, pi 15 from math import cos, sin, pi
16 16
17 from pytouhou.game.element import Element
17 from pytouhou.vm.anmrunner import ANMRunner 18 from pytouhou.vm.anmrunner import ANMRunner
18 from pytouhou.game.sprite import Sprite 19 from pytouhou.game.sprite import Sprite
19 20
20 21
21 STARTING, STARTED, STOPPING = range(3) 22 STARTING, STARTED, STOPPING = range(3)
22 23
23 24
24 class LaserLaunchAnim(object): 25 class LaserLaunchAnim(Element):
25 def __init__(self, laser, anm, index): 26 def __init__(self, laser, anm, index):
27 Element.__init__(self, (0, 0))
28
26 self._laser = laser 29 self._laser = laser
27 self.sprite = Sprite() 30 self.sprite = Sprite()
28 self.sprite.anm = anm 31 self.sprite.anm = anm
29 self.sprite.texcoords = anm.sprites[index] 32 self.sprite.texcoords = anm.sprites[index]
30 self.sprite.blendfunc = 1 33 self.sprite.blendfunc = 1
31 self.removed = False
32 self.objects = [self]
33 self.x, self.y = 0, 0
34 34
35 35
36 def update(self): 36 def update(self):
37 laser = self._laser 37 laser = self._laser
38 length = min(laser.end_offset - laser.start_offset, laser.max_length) 38 length = min(laser.end_offset - laser.start_offset, laser.max_length)
49 if laser.removed or scale <= 0.: 49 if laser.removed or scale <= 0.:
50 self.removed = True 50 self.removed = True
51 51
52 52
53 53
54 class Laser(object): 54 class Laser(Element):
55 def __init__(self, base_pos, laser_type, sprite_idx_offset, 55 def __init__(self, base_pos, laser_type, sprite_idx_offset,
56 angle, speed, start_offset, end_offset, max_length, width, 56 angle, speed, start_offset, end_offset, max_length, width,
57 start_duration, duration, stop_duration, 57 start_duration, duration, stop_duration,
58 grazing_delay, grazing_extra_duration, 58 grazing_delay, grazing_extra_duration,
59 game): 59 game):
60 Element.__init__(self, (0, 0))
61
60 self._game = game 62 self._game = game
61 launch_anim = LaserLaunchAnim(self, laser_type.anm, 63 launch_anim = LaserLaunchAnim(self, laser_type.anm,
62 laser_type.launch_anim_offsets[sprite_idx_offset] 64 laser_type.launch_anim_offsets[sprite_idx_offset]
63 + laser_type.launch_sprite_idx) 65 + laser_type.launch_sprite_idx)
64 self._game.effects.append(launch_anim) 66 self._game.effects.append(launch_anim)
65 self._laser_type = laser_type 67 self._laser_type = laser_type
66 self.state = STARTING 68 self.state = STARTING
67 self.sprite = None
68 self.anmrunner = None
69 self.removed = False
70 self.objects = [self]
71 69
72 #TODO: hitbox 70 #TODO: hitbox
73 71
74 self.frame = 0 72 self.frame = 0
75 self.start_duration = start_duration 73 self.start_duration = start_duration
78 self.grazing_delay = grazing_delay 76 self.grazing_delay = grazing_delay
79 self.grazing_extra_duration = grazing_extra_duration 77 self.grazing_extra_duration = grazing_extra_duration
80 78
81 self.sprite_idx_offset = sprite_idx_offset 79 self.sprite_idx_offset = sprite_idx_offset
82 self.base_pos = base_pos 80 self.base_pos = base_pos
83 self.x, self.y = 0, 0
84 self.angle = angle 81 self.angle = angle
85 self.speed = speed 82 self.speed = speed
86 self.start_offset = start_offset 83 self.start_offset = start_offset
87 self.end_offset = end_offset 84 self.end_offset = end_offset
88 self.max_length = max_length 85 self.max_length = max_length
193 self.sprite.changed = True #TODO 190 self.sprite.changed = True #TODO
194 191
195 self.frame += 1 192 self.frame += 1
196 193
197 194
198 class PlayerLaser(object): 195 class PlayerLaser(Element):
199 def __init__(self, laser_type, sprite_idx_offset, hitbox, damage, 196 def __init__(self, laser_type, sprite_idx_offset, hitbox, damage,
200 angle, offset, duration, origin): 197 angle, offset, duration, origin):
201 self.sprite = None 198 Element.__init__(self)
202 self.anmrunner = None 199
203 self.removed = False
204 self._laser_type = laser_type 200 self._laser_type = laser_type
205 self.origin = origin 201 self.origin = origin
206 self.objects = [self]
207 202
208 self.hitbox = hitbox[0], hitbox[1] 203 self.hitbox = hitbox[0], hitbox[1]
209 204
210 self.frame = 0 205 self.frame = 0
211 self.duration = duration 206 self.duration = duration