Mercurial > touhou
comparison pytouhou/game/enemy.py @ 100:5c40cc1b8019
Use game's frame for interpolation. No more time manipulation interfering with interpolators!
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Mon, 05 Sep 2011 00:29:31 +0200 |
parents | d141c851c598 |
children | 789994275968 |
comparison
equal
deleted
inserted
replaced
99:68aa8bf00c88 | 100:5c40cc1b8019 |
---|---|
128 | 128 |
129 | 129 |
130 def set_pos(self, x, y, z): | 130 def set_pos(self, x, y, z): |
131 self.x, self.y = x, y | 131 self.x, self.y = x, y |
132 self.interpolator = Interpolator((x, y)) | 132 self.interpolator = Interpolator((x, y)) |
133 self.interpolator.set_interpolation_start(self.frame, (x, y)) | 133 self.interpolator.set_interpolation_start(self._game_state.frame, (x, y)) |
134 | 134 |
135 | 135 |
136 def move_to(self, duration, x, y, z, formula): | 136 def move_to(self, duration, x, y, z, formula): |
137 if not self.interpolator: | 137 if not self.interpolator: |
138 frame = self._game_state.frame | |
138 self.interpolator = Interpolator((self.x, self.y), formula) | 139 self.interpolator = Interpolator((self.x, self.y), formula) |
139 self.interpolator.set_interpolation_start(self.frame, (self.x, self.y)) | 140 self.interpolator.set_interpolation_start(frame, (self.x, self.y)) |
140 self.interpolator.set_interpolation_end(self.frame + duration - 1, (x, y)) | 141 self.interpolator.set_interpolation_end(frame + duration - 1, (x, y)) |
141 | 142 |
142 self.speed = 0. | 143 self.speed = 0. |
143 self.angle = atan2(y - self.y, x - self.x) | 144 self.angle = atan2(y - self.y, x - self.x) |
144 | 145 |
145 | 146 |
146 def stop_in(self, duration, formula): | 147 def stop_in(self, duration, formula): |
147 if not self.speed_interpolator: | 148 if not self.speed_interpolator: |
149 frame = self._game_state.frame | |
148 self.speed_interpolator = Interpolator((self.speed,), formula) | 150 self.speed_interpolator = Interpolator((self.speed,), formula) |
149 self.speed_interpolator.set_interpolation_start(self.frame, (self.speed,)) | 151 self.speed_interpolator.set_interpolation_start(frame, (self.speed,)) |
150 self.speed_interpolator.set_interpolation_end(self.frame + duration - 1, (0.,)) | 152 self.speed_interpolator.set_interpolation_end(frame + duration - 1, (0.,)) |
151 | 153 |
152 self.speed = 0. | 154 self.speed = 0. |
153 | 155 |
154 | 156 |
155 def is_visible(self, screen_width, screen_height): | 157 def is_visible(self, screen_width, screen_height): |
193 | 195 |
194 | 196 |
195 def update(self): | 197 def update(self): |
196 x, y = self.x, self.y | 198 x, y = self.x, self.y |
197 if self.interpolator: | 199 if self.interpolator: |
198 self.interpolator.update(self.frame) | 200 self.interpolator.update(self._game_state.frame) |
199 x, y = self.interpolator.values | 201 x, y = self.interpolator.values |
200 | 202 |
201 self.speed += self.acceleration #TODO: units? Execution order? | 203 self.speed += self.acceleration #TODO: units? Execution order? |
202 self.angle += self.rotation_speed #TODO: units? Execution order? | 204 self.angle += self.rotation_speed #TODO: units? Execution order? |
203 | 205 |
204 | 206 |
205 if self.speed_interpolator: | 207 if self.speed_interpolator: |
206 self.speed_interpolator.update(self.frame) | 208 self.speed_interpolator.update(self._game_state.frame) |
207 self.speed, = self.speed_interpolator.values | 209 self.speed, = self.speed_interpolator.values |
208 | 210 |
209 | 211 |
210 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed | 212 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed |
211 if self._type & 2: | 213 if self._type & 2: |