Mercurial > touhou
comparison pytouhou/game/enemymanager.py @ 57:694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Tue, 23 Aug 2011 19:27:24 +0200 |
parents | 299de3a9b69f |
children | 1f591adcea04 |
comparison
equal
deleted
inserted
replaced
56:299de3a9b69f | 57:694f25881d0f |
---|---|
52 | 52 |
53 self.death_anim = None | 53 self.death_anim = None |
54 self.movement_dependant_sprites = None | 54 self.movement_dependant_sprites = None |
55 self.direction = None | 55 self.direction = None |
56 self.interpolator = None #TODO | 56 self.interpolator = None #TODO |
57 self.speed_interpolator = None | |
57 self.angle = 0. | 58 self.angle = 0. |
58 self.speed = 0. | 59 self.speed = 0. |
59 self.rotation_speed = 0. | 60 self.rotation_speed = 0. |
60 self.acceleration = 0. | 61 self.acceleration = 0. |
61 | 62 |
62 self.hitbox = (0, 0) | 63 self.hitbox = (0, 0) |
63 self.screen_box = None | 64 self.screen_box = None |
64 | 65 |
65 | 66 |
66 def set_bullet_attributes(self, bullet_anim, launch_anim, bullets_per_shot, | 67 def set_bullet_attributes(self, type_, bullet_anim, launch_anim, |
67 number_of_shots, speed, unknown, launch_angle, | 68 bullets_per_shot, number_of_shots, speed, unknown, |
68 angle, flags): | 69 launch_angle, angle, flags): |
69 self.bullet_attributes = (1, bullet_anim, launch_anim, bullets_per_shot, | 70 self.bullet_attributes = (type_, bullet_anim, launch_anim, bullets_per_shot, |
70 number_of_shots, speed, unknown, launch_angle, | 71 number_of_shots, speed, unknown, launch_angle, |
71 angle, flags) | 72 angle, flags) |
72 if not self.delay_attack: | 73 if not self.delay_attack: |
73 pass | 74 self.fire() |
74 #TODO: actually fire | 75 |
76 | |
77 def fire(self): | |
78 #TODO | |
79 pass | |
75 | 80 |
76 | 81 |
77 def select_player(self, players): | 82 def select_player(self, players): |
78 return players[0] #TODO | 83 return players[0] #TODO |
79 | 84 |
91 self.interpolator = Interpolator((x, y)) | 96 self.interpolator = Interpolator((x, y)) |
92 self.interpolator.set_interpolation_start(self.frame, (x, y)) | 97 self.interpolator.set_interpolation_start(self.frame, (x, y)) |
93 | 98 |
94 | 99 |
95 def move_to(self, duration, x, y, z): | 100 def move_to(self, duration, x, y, z): |
101 if not self.interpolator: | |
102 self.interpolator = Interpolator((self.x, self.y)) | |
103 self.interpolator.set_interpolation_start(self.frame, (self.x, self.y)) | |
96 self.interpolator.set_interpolation_end(self.frame + duration, (x, y)) | 104 self.interpolator.set_interpolation_end(self.frame + duration, (x, y)) |
105 | |
106 | |
107 def stop_in(self, duration): | |
108 if not self.speed_interpolator: | |
109 self.speed_interpolator = Interpolator((self.speed,)) | |
110 self.speed_interpolator.set_interpolation_start(self.frame, (self.speed,)) | |
111 self.speed_interpolator.set_interpolation_end(self.frame + duration, (0.,)) | |
97 | 112 |
98 | 113 |
99 def is_visible(self, screen_width, screen_height): | 114 def is_visible(self, screen_width, screen_height): |
100 if not self._sprite: | 115 if not self._sprite: |
101 return False | 116 return False |
130 return objects_by_texture | 145 return objects_by_texture |
131 | 146 |
132 | 147 |
133 def update(self, frame): | 148 def update(self, frame): |
134 x, y = self.x, self.y | 149 x, y = self.x, self.y |
135 if self.interpolator and self.interpolator.update(self.frame): | 150 if self.interpolator: |
151 self.interpolator.update(self.frame) | |
136 x, y = self.interpolator.values | 152 x, y = self.interpolator.values |
137 | 153 |
138 self.speed += self.acceleration #TODO: units? Execution order? | 154 self.speed += self.acceleration #TODO: units? Execution order? |
139 self.angle += self.rotation_speed #TODO: units? Execution order? | 155 self.angle += self.rotation_speed #TODO: units? Execution order? |
156 | |
157 | |
158 if self.speed_interpolator: | |
159 self.speed_interpolator.update(self.frame) | |
160 self.speed, = self.speed_interpolator.values | |
161 | |
140 | 162 |
141 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed | 163 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed |
142 if self._type & 2: | 164 if self._type & 2: |
143 x -= dx | 165 x -= dx |
144 else: | 166 else: |
145 x += dx | 167 x += dx |
146 y += dy | 168 y += dy |
147 | 169 |
148 if self.movement_dependant_sprites: | 170 if self.movement_dependant_sprites: |
149 #TODO: is that really how it works? | 171 #TODO: is that really how it works? Almost. |
172 # Sprite determination is done only once per changement, and is | |
173 # superseeded by ins_97. | |
150 if x < self.x: | 174 if x < self.x: |
151 self.set_anim(self.movement_dependant_sprites[2]) | 175 self.set_anim(self.movement_dependant_sprites[2]) |
152 self.direction = -1 | 176 self.direction = -1 |
153 elif x > self.x: | 177 elif x > self.x: |
154 self.set_anim(self.movement_dependant_sprites[3]) | 178 self.set_anim(self.movement_dependant_sprites[3]) |
232 # Filter out-of-screen enemies | 256 # Filter out-of-screen enemies |
233 for enemy in tuple(self.enemies): | 257 for enemy in tuple(self.enemies): |
234 if enemy._was_visible and not enemy in visible_enemies: | 258 if enemy._was_visible and not enemy in visible_enemies: |
235 enemy._removed = True | 259 enemy._removed = True |
236 self.enemies.remove(enemy) | 260 self.enemies.remove(enemy) |
261 | |
262 | |
263 #TODO: disable boss mode if it is dead/it has timeout | |
264 if self._game_state.boss and self._game_state.boss._removed: | |
265 self._game_state.boss = None | |
266 | |
237 | 267 |
238 # Add enemies to vertices/uvs | 268 # Add enemies to vertices/uvs |
239 self.objects_by_texture = {} | 269 self.objects_by_texture = {} |
240 for enemy in visible_enemies: | 270 for enemy in visible_enemies: |
241 if enemy.is_visible(384, 448): #TODO | 271 if enemy.is_visible(384, 448): #TODO |