Mercurial > touhou
comparison pytouhou/game/bullet.py @ 86:a87a3c080585
Handle a few attack flags
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 04 Sep 2011 00:49:22 +0200 |
parents | 3804f07d3b0e |
children | 2cc60137d368 |
comparison
equal
deleted
inserted
replaced
85:3804f07d3b0e | 86:a87a3c080585 |
---|---|
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, atan2, pi | 15 from math import cos, sin, atan2, pi |
16 | 16 |
17 from pytouhou.utils.interpolator import Interpolator | |
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 class Bullet(object): | 22 class Bullet(object): |
22 __slots__ = ('x', 'y', 'angle', 'speed', | 23 __slots__ = ('x', 'y', 'angle', 'speed', 'frame', 'grazed', |
23 'flags', 'attributes', 'anim_idx', 'sprite_idx_offset', 'player', | 24 'flags', 'attributes', 'anim_idx', 'sprite_idx_offset', 'player', |
25 'speed_interpolator', | |
24 '_game_state', '_sprite', '_anmrunner', | 26 '_game_state', '_sprite', '_anmrunner', |
25 '_removed', '_launched') | 27 '_removed', '_launched') |
26 | 28 |
27 def __init__(self, pos, anim_idx, sprite_idx_offset, | 29 def __init__(self, pos, anim_idx, sprite_idx_offset, |
28 angle, speed, attributes, flags, player, game_state): | 30 angle, speed, attributes, flags, player, game_state): |
29 self._game_state = game_state | 31 self._game_state = game_state |
30 self._sprite = None | 32 self._sprite = None |
31 self._anmrunner = None | 33 self._anmrunner = None |
32 self._removed = False | 34 self._removed = False |
33 self._launched = False | 35 self._launched = False |
36 | |
37 self.speed_interpolator = None | |
38 self.frame = 0 | |
39 self.grazed = False | |
34 | 40 |
35 self.player = player | 41 self.player = player |
36 | 42 |
37 self.anim_idx = anim_idx | 43 self.anim_idx = anim_idx |
38 self.sprite_idx_offset = sprite_idx_offset | 44 self.sprite_idx_offset = sprite_idx_offset |
48 self.attributes = list(attributes) | 54 self.attributes = list(attributes) |
49 | 55 |
50 self.x, self.y = pos | 56 self.x, self.y = pos |
51 self.angle = angle | 57 self.angle = angle |
52 self.speed = speed | 58 self.speed = speed |
59 | |
60 if flags & 1: | |
61 self.speed_interpolator = Interpolator((speed + 5.,)) | |
62 self.speed_interpolator.set_interpolation_start(0, (speed + 5.,)) | |
63 self.speed_interpolator.set_interpolation_end(16, (speed,)) | |
53 | 64 |
54 | 65 |
55 def is_visible(self, screen_width, screen_height): | 66 def is_visible(self, screen_width, screen_height): |
56 if self._sprite: | 67 if self._sprite: |
57 tx, ty, tw, th = self._sprite.texcoords | 68 tx, ty, tw, th = self._sprite.texcoords |
89 if not self._sprite or self._sprite._removed: | 100 if not self._sprite or self._sprite._removed: |
90 self._launched = True | 101 self._launched = True |
91 self._sprite = Sprite() | 102 self._sprite = Sprite() |
92 self._anmrunner = ANMRunner(self._game_state.resources.etama_anm_wrappers[0], #TODO | 103 self._anmrunner = ANMRunner(self._game_state.resources.etama_anm_wrappers[0], #TODO |
93 self.anim_idx, self._sprite, self.sprite_idx_offset) | 104 self.anim_idx, self._sprite, self.sprite_idx_offset) |
94 #TODO: self._anmrunner.sprite_idx_offset = self.sprite_idx_offset | |
95 | 105 |
96 if self._anmrunner and not self._anmrunner.run_frame(): | 106 if self._anmrunner and not self._anmrunner.run_frame(): |
97 self._anmrunner = None | 107 self._anmrunner = None |
98 | 108 |
99 self._sprite.update() | 109 self._sprite.update() |
102 self._sprite.update_vertices_uvs_colors(angle_base=angle) | 112 self._sprite.update_vertices_uvs_colors(angle_base=angle) |
103 | 113 |
104 #TODO: flags | 114 #TODO: flags |
105 x, y = self.x, self.y | 115 x, y = self.x, self.y |
106 | 116 |
117 if self.flags & 16: | |
118 #TODO: duration, count | |
119 length, angle = self.attributes[4:6] | |
120 angle = self.angle if angle < -900.0 else angle #TODO: is that right? | |
121 dx = cos(self.angle) * self.speed + cos(angle) * length | |
122 dy = sin(self.angle) * self.speed + sin(angle) * length | |
123 self.speed = (dx ** 2 + dy ** 2) ** 0.5 | |
124 self.angle = atan2(dy, dx) | |
125 elif self.flags & 32: | |
126 #TODO: duration, count | |
127 #TODO: check | |
128 acceleration, angular_speed = self.attributes[4:6] | |
129 self.speed += acceleration | |
130 self.angle += angular_speed | |
131 #TODO: other flags | |
132 | |
133 if self.speed_interpolator: | |
134 self.speed_interpolator.update(self.frame) | |
135 self.speed, = self.speed_interpolator.values | |
136 | |
107 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed | 137 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed |
108 self.x, self.y = x + dx, y + dy | 138 self.x, self.y = x + dx, y + dy |
109 | 139 |
140 self.frame += 1 | |
141 |