comparison pytouhou/game/laser.py @ 304:f3099ebf4f61

Update attribute names to reflect the actual interface.
author Thibaut Girka <thib@sitedethib.com>
date Tue, 13 Mar 2012 18:38:14 +0100
parents 94c636f8f863
children 14c9aca8e274
comparison
equal deleted inserted replaced
303:647bde10353d 304:f3099ebf4f61
22 22
23 23
24 class LaserLaunchAnim(object): 24 class LaserLaunchAnim(object):
25 def __init__(self, laser, anm_wrapper, index): 25 def __init__(self, laser, anm_wrapper, index):
26 self._laser = laser 26 self._laser = laser
27 self._sprite = Sprite() 27 self.sprite = Sprite()
28 self._sprite.anm, self._sprite.texcoords = anm_wrapper.get_sprite(index) 28 self.sprite.anm, self.sprite.texcoords = anm_wrapper.get_sprite(index)
29 self._sprite.blendfunc = 1 29 self.sprite.blendfunc = 1
30 self._removed = False 30 self.removed = False
31 self.x, self.y = 0, 0 31 self.x, self.y = 0, 0
32 32
33 33
34 def update(self): 34 def update(self):
35 laser = self._laser 35 laser = self._laser
39 39
40 self.x = laser.base_pos[0] + offset * dx 40 self.x = laser.base_pos[0] + offset * dx
41 self.y = laser.base_pos[1] + offset * dy 41 self.y = laser.base_pos[1] + offset * dy
42 42
43 scale = laser.width / 10. - (offset - laser.start_offset) 43 scale = laser.width / 10. - (offset - laser.start_offset)
44 self._sprite.rescale = (scale, scale) 44 self.sprite.rescale = (scale, scale)
45 self._sprite._changed = True 45 self.sprite.changed = True
46 46
47 if laser._removed or scale <= 0.: 47 if laser.removed or scale <= 0.:
48 self._removed = True 48 self.removed = True
49 49
50 50
51 51
52 class Laser(object): 52 class Laser(object):
53 def __init__(self, base_pos, laser_type, sprite_idx_offset, 53 def __init__(self, base_pos, laser_type, sprite_idx_offset,
58 self._game = game 58 self._game = game
59 launch_anim = LaserLaunchAnim(self, laser_type.anm_wrapper, 59 launch_anim = LaserLaunchAnim(self, laser_type.anm_wrapper,
60 laser_type.launch_anim_offsets[sprite_idx_offset] 60 laser_type.launch_anim_offsets[sprite_idx_offset]
61 + laser_type.launch_sprite_idx) 61 + laser_type.launch_sprite_idx)
62 self._game.effects.append(launch_anim) 62 self._game.effects.append(launch_anim)
63 self._sprite = None
64 self._anmrunner = None
65 self._removed = False
66 self._laser_type = laser_type 63 self._laser_type = laser_type
67 self.state = STARTING 64 self.state = STARTING
65 self.sprite = None
66 self.anmrunner = None
67 self.removed = False
68 68
69 #TODO: hitbox 69 #TODO: hitbox
70 70
71 self.frame = 0 71 self.frame = 0
72 self.start_duration = start_duration 72 self.start_duration = start_duration
91 def set_anim(self, sprite_idx_offset=None): 91 def set_anim(self, sprite_idx_offset=None):
92 if sprite_idx_offset is not None: 92 if sprite_idx_offset is not None:
93 self.sprite_idx_offset = sprite_idx_offset 93 self.sprite_idx_offset = sprite_idx_offset
94 94
95 lt = self._laser_type 95 lt = self._laser_type
96 self._sprite = Sprite() 96 self.sprite = Sprite()
97 self._sprite.angle = self.angle 97 self.sprite.angle = self.angle
98 self._anmrunner = ANMRunner(lt.anm_wrapper, lt.anim_index, 98 self.anmrunner = ANMRunner(lt.anm_wrapper, lt.anim_index,
99 self._sprite, self.sprite_idx_offset) 99 self.sprite, self.sprite_idx_offset)
100 self._anmrunner.run_frame() 100 self.anmrunner.run_frame()
101 101
102 102
103 def _check_collision(self, point, border_size): 103 def _check_collision(self, point, border_size):
104 x, y = point[0] - self.base_pos[0], point[1] - self.base_pos[1] 104 x, y = point[0] - self.base_pos[0], point[1] - self.base_pos[1]
105 dx, dy = cos(self.angle), sin(self.angle) 105 dx, dy = cos(self.angle), sin(self.angle)
156 self.frame = 0 156 self.frame = 0
157 self.state = STOPPING 157 self.state = STOPPING
158 158
159 159
160 def update(self): 160 def update(self):
161 if self._anmrunner is not None and not self._anmrunner.run_frame(): 161 if self.anmrunner is not None and not self.anmrunner.run_frame():
162 self._anmrunner = None 162 self.anmrunner = None
163 163
164 self.end_offset += self.speed 164 self.end_offset += self.speed
165 165
166 length = min(self.end_offset - self.start_offset, self.max_length) # TODO 166 length = min(self.end_offset - self.start_offset, self.max_length) # TODO
167 if self.state == STARTING: 167 if self.state == STARTING:
176 self.frame = 0 176 self.frame = 0
177 self.state = STOPPING 177 self.state = STOPPING
178 if self.state == STOPPING: 178 if self.state == STOPPING:
179 if self.frame == self.stop_duration: 179 if self.frame == self.stop_duration:
180 width = 0. 180 width = 0.
181 self._removed = True 181 self.removed = True
182 else: 182 else:
183 width = self.width * (1. - float(self.frame) / self.stop_duration) #TODO 183 width = self.width * (1. - float(self.frame) / self.stop_duration) #TODO
184 184
185 offset = self.end_offset - length / 2. 185 offset = self.end_offset - length / 2.
186 self.x, self.y = self.base_pos[0] + offset * cos(self.angle), self.base_pos[1] + offset * sin(self.angle) 186 self.x, self.y = self.base_pos[0] + offset * cos(self.angle), self.base_pos[1] + offset * sin(self.angle)
187 self._sprite.width_override = width or 0.01 #TODO 187 self.sprite.width_override = width or 0.01 #TODO
188 self._sprite.height_override = length or 0.01 #TODO 188 self.sprite.height_override = length or 0.01 #TODO
189 189
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 195
196 class PlayerLaser(object): 196 class PlayerLaser(object):
197 def __init__(self, laser_type, sprite_idx_offset, hitbox, damage, 197 def __init__(self, laser_type, sprite_idx_offset, hitbox, damage,
198 angle, offset, duration, origin): 198 angle, offset, duration, origin):
199 self._sprite = None 199 self.sprite = None
200 self._anmrunner = None 200 self.anmrunner = None
201 self._removed = False 201 self.removed = False
202 self._laser_type = laser_type 202 self._laser_type = laser_type
203 self.origin = origin 203 self.origin = origin
204 204
205 self.hitbox_half_size = hitbox[0] / 2., hitbox[1] / 2. 205 self.hitbox_half_size = hitbox[0] / 2., hitbox[1] / 2.
206 206
228 def set_anim(self, sprite_idx_offset=None): 228 def set_anim(self, sprite_idx_offset=None):
229 if sprite_idx_offset is not None: 229 if sprite_idx_offset is not None:
230 self.sprite_idx_offset = sprite_idx_offset 230 self.sprite_idx_offset = sprite_idx_offset
231 231
232 lt = self._laser_type 232 lt = self._laser_type
233 self._sprite = Sprite() 233 self.sprite = Sprite()
234 self._anmrunner = ANMRunner(lt.anm_wrapper, lt.anim_index, 234 self.anmrunner = ANMRunner(lt.anm_wrapper, lt.anim_index,
235 self._sprite, self.sprite_idx_offset) 235 self.sprite, self.sprite_idx_offset)
236 #self._sprite.blendfunc = 1 #XXX 236 #self.sprite.blendfunc = 1 #XXX
237 self._anmrunner.run_frame() 237 self.anmrunner.run_frame()
238 238
239 239
240 def cancel(self): 240 def cancel(self):
241 self._anmrunner.interrupt(1) 241 self.anmrunner.interrupt(1)
242 242
243 243
244 def update(self): 244 def update(self):
245 if self._anmrunner is not None and not self._anmrunner.run_frame(): 245 if self.anmrunner is not None and not self.anmrunner.run_frame():
246 self._anmrunner = None 246 self.anmrunner = None
247 self._removed = True 247 self.removed = True
248 248
249 length = self.origin.y 249 length = self.origin.y
250 if self.frame == self.duration: 250 if self.frame == self.duration:
251 self.cancel() 251 self.cancel()
252 252
253 self._sprite.height_override = length or 0.01 #TODO 253 self.sprite.height_override = length or 0.01 #TODO
254 self._sprite._changed = True #TODO 254 self.sprite.changed = True #TODO
255 255
256 self.frame += 1 256 self.frame += 1
257 257