comparison pytouhou/game/bullet.py @ 123:d1c82d43bbf3

Various optimizations
author Thibaut Girka <thib@sitedethib.com>
date Sat, 10 Sep 2011 11:58:24 +0200
parents 174324a4da51
children f06e96dbed4e
comparison
equal deleted inserted replaced
122:174324a4da51 123:d1c82d43bbf3
18 from pytouhou.vm.anmrunner import ANMRunner 18 from pytouhou.vm.anmrunner import ANMRunner
19 from pytouhou.game.sprite import Sprite 19 from pytouhou.game.sprite import Sprite
20 20
21 21
22 class Bullet(object): 22 class Bullet(object):
23 def __init__(self, pos, type_idx, sprite_idx_offset, 23 def __init__(self, pos, bullet_type, sprite_idx_offset,
24 angle, speed, attributes, flags, player, game_state): 24 angle, speed, attributes, flags, player, game_state):
25 self._game_state = game_state 25 self._game_state = game_state
26 self._sprite = None 26 self._sprite = None
27 self._anmrunner = None 27 self._anmrunner = None
28 self._removed = False 28 self._removed = False
29 self._launched = False 29 self._launched = False
30 self._bullet_type = game_state.bullet_types[type_idx] 30 self._bullet_type = bullet_type
31 31
32 self.speed_interpolator = None 32 self.speed_interpolator = None
33 self.frame = 0 33 self.frame = 0
34 self.grazed = False 34 self.grazed = False
35 35
46 dx, dy = cos(angle) * speed, sin(angle) * speed 46 dx, dy = cos(angle) * speed, sin(angle) * speed
47 self.delta = dx, dy 47 self.delta = dx, dy
48 48
49 #TODO 49 #TODO
50 if flags & 14: 50 if flags & 14:
51 bt = self._bullet_type
52 if flags & 2: 51 if flags & 2:
53 index = bt.launch_anim2_index 52 index = bullet_type.launch_anim2_index
54 launch_mult = bt.launch_anim_penalties[0] 53 launch_mult = bullet_type.launch_anim_penalties[0]
55 elif flags & 4: 54 elif flags & 4:
56 index = bt.launch_anim4_index 55 index = bullet_type.launch_anim4_index
57 launch_mult = bt.launch_anim_penalties[1] 56 launch_mult = bullet_type.launch_anim_penalties[1]
58 else: 57 else:
59 index = bt.launch_anim8_index 58 index = bullet_type.launch_anim8_index
60 launch_mult = bt.launch_anim_penalties[2] 59 launch_mult = bullet_type.launch_anim_penalties[2]
61 self.launch_delta = dx * launch_mult, dy * launch_mult 60 self.launch_delta = dx * launch_mult, dy * launch_mult
62 self._sprite = Sprite() 61 self._sprite = Sprite()
63 self._anmrunner = ANMRunner(bt.anm_wrapper, 62 self._anmrunner = ANMRunner(bullet_type.anm_wrapper,
64 index, self._sprite, 63 index, self._sprite,
65 bt.launch_anim_offsets[sprite_idx_offset]) 64 bullet_type.launch_anim_offsets[sprite_idx_offset])
66 self._anmrunner.run_frame() 65 self._anmrunner.run_frame()
67 else: 66 else:
68 self.launch() 67 self.launch()
69 68
70 self._sprite.angle = angle 69 self._sprite.angle = angle
71 70
72 71
73 def is_visible(self, screen_width, screen_height): 72 def is_visible(self, screen_width, screen_height):
74 tx, ty, tw, th = self._sprite.texcoords 73 tx, ty, tw, th = self._sprite.texcoords
75 if self._sprite.corner_relative_placement: 74 x, y = self.x, self.y
76 raise Exception #TODO
77 75
78 max_x = tw / 2. 76 max_x = tw / 2.
79 max_y = th / 2. 77 max_y = th / 2.
80 78
81 if any((max_x < self.x - screen_width, 79 if (max_x < x - screen_width
82 max_x < -self.x, 80 or max_x < -x
83 max_y < self.y - screen_height, 81 or max_y < y - screen_height
84 max_y < -self.y)): 82 or max_y < -y):
85 return False 83 return False
86 return True 84 return True
87 85
88 86
89 def set_anim(self, sprite_idx_offset=None): 87 def set_anim(self, sprite_idx_offset=None):