|
1 | 1 | import bisect |
2 | 2 | import logging |
3 | | -import math |
4 | 3 |
|
5 | 4 | from arcade import Texture |
6 | | -from arcade.types import Point2 |
7 | | - |
8 | | -from .enums import ( |
9 | | - FACE_DOWN, |
10 | | - FACE_LEFT, |
11 | | - FACE_RIGHT, |
12 | | - FACE_UP, |
13 | | -) |
| 5 | + |
14 | 6 | from .sprite import Sprite |
15 | 7 |
|
16 | 8 | logger = logging.getLogger("arcade") |
@@ -211,156 +203,3 @@ def update_animation(self, delta_time: float = 1 / 60, **kwargs) -> None: |
211 | 203 | if index != self._current_keyframe_index: |
212 | 204 | self._current_keyframe_index = index |
213 | 205 | self.texture = keyframe.texture |
214 | | - |
215 | | - |
216 | | -class AnimatedWalkingSprite(Sprite): |
217 | | - """ |
218 | | - Deprecated Sprite for platformer games that supports walking animations. |
219 | | - Make sure to call update_animation after loading the animations so the |
220 | | - initial texture can be set. Or manually set it. |
221 | | -
|
222 | | - It is highly recommended you create your own version of this class rather than |
223 | | - try to use this pre-packaged one. |
224 | | -
|
225 | | - For an example, see this section of the platformer tutorial: |
226 | | - :ref:`platformer_part_twelve`. |
227 | | -
|
228 | | - Args: |
229 | | - scale: |
230 | | - Initial scale of the sprite. |
231 | | - center_x: |
232 | | - Initial x position of the sprite. |
233 | | - center_y: |
234 | | - Initial y position of the sprite. |
235 | | - **kwargs: |
236 | | - Passed to :py:class:`~arcade.Sprite`, such as ``angle``, ``scale`` or ``visible``. |
237 | | - """ |
238 | | - |
239 | | - def __init__( |
240 | | - self, |
241 | | - scale: float | Point2 = 1.0, |
242 | | - center_x: float = 0.0, |
243 | | - center_y: float = 0.0, |
244 | | - **kwargs, |
245 | | - ): |
246 | | - super().__init__( |
247 | | - None, |
248 | | - scale=scale, |
249 | | - center_x=center_x, |
250 | | - center_y=center_y, |
251 | | - **kwargs, |
252 | | - ) |
253 | | - self.state = FACE_RIGHT |
254 | | - self.stand_right_textures: list[Texture] = [] |
255 | | - self.stand_left_textures: list[Texture] = [] |
256 | | - self.walk_left_textures: list[Texture] = [] |
257 | | - self.walk_right_textures: list[Texture] = [] |
258 | | - self.walk_up_textures: list[Texture] = [] |
259 | | - self.walk_down_textures: list[Texture] = [] |
260 | | - self.cur_texture_index = 0 |
261 | | - self.texture_change_distance = 20 |
262 | | - self.last_texture_change_center_x: float = 0.0 |
263 | | - self.last_texture_change_center_y: float = 0.0 |
264 | | - |
265 | | - def update_animation(self, delta_time: float = 1 / 60) -> None: |
266 | | - """ |
267 | | - Logic for texture animation. |
268 | | -
|
269 | | - Args: |
270 | | - delta_time: Time since last update. |
271 | | - """ |
272 | | - x1 = self.center_x |
273 | | - x2 = self.last_texture_change_center_x |
274 | | - y1 = self.center_y |
275 | | - y2 = self.last_texture_change_center_y |
276 | | - distance = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) |
277 | | - texture_list: list[Texture] = [] |
278 | | - |
279 | | - change_direction = False |
280 | | - if ( |
281 | | - self.change_x > 0 |
282 | | - and self.change_y == 0 |
283 | | - and self.state != FACE_RIGHT |
284 | | - and len(self.walk_right_textures) > 0 |
285 | | - ): |
286 | | - self.state = FACE_RIGHT |
287 | | - change_direction = True |
288 | | - elif ( |
289 | | - self.change_x < 0 |
290 | | - and self.change_y == 0 |
291 | | - and self.state != FACE_LEFT |
292 | | - and len(self.walk_left_textures) > 0 |
293 | | - ): |
294 | | - self.state = FACE_LEFT |
295 | | - change_direction = True |
296 | | - elif ( |
297 | | - self.change_y < 0 |
298 | | - and self.change_x == 0 |
299 | | - and self.state != FACE_DOWN |
300 | | - and len(self.walk_down_textures) > 0 |
301 | | - ): |
302 | | - self.state = FACE_DOWN |
303 | | - change_direction = True |
304 | | - elif ( |
305 | | - self.change_y > 0 |
306 | | - and self.change_x == 0 |
307 | | - and self.state != FACE_UP |
308 | | - and len(self.walk_up_textures) > 0 |
309 | | - ): |
310 | | - self.state = FACE_UP |
311 | | - change_direction = True |
312 | | - |
313 | | - if self.change_x == 0 and self.change_y == 0: |
314 | | - if self.state == FACE_LEFT: |
315 | | - self.texture = self.stand_left_textures[0] |
316 | | - elif self.state == FACE_RIGHT: |
317 | | - self.texture = self.stand_right_textures[0] |
318 | | - elif self.state == FACE_UP: |
319 | | - self.texture = self.walk_up_textures[0] |
320 | | - elif self.state == FACE_DOWN: |
321 | | - self.texture = self.walk_down_textures[0] |
322 | | - |
323 | | - elif change_direction or distance >= self.texture_change_distance: |
324 | | - self.last_texture_change_center_x = self.center_x |
325 | | - self.last_texture_change_center_y = self.center_y |
326 | | - |
327 | | - if self.state == FACE_LEFT: |
328 | | - texture_list = self.walk_left_textures |
329 | | - if texture_list is None or len(texture_list) == 0: |
330 | | - raise RuntimeError( |
331 | | - "update_animation was called on a sprite that doesn't have a " |
332 | | - "list of walk left textures." |
333 | | - ) |
334 | | - elif self.state == FACE_RIGHT: |
335 | | - texture_list = self.walk_right_textures |
336 | | - if texture_list is None or len(texture_list) == 0: |
337 | | - raise RuntimeError( |
338 | | - "update_animation was called on a sprite that doesn't have a list of " |
339 | | - "walk right textures." |
340 | | - ) |
341 | | - elif self.state == FACE_UP: |
342 | | - texture_list = self.walk_up_textures |
343 | | - if texture_list is None or len(texture_list) == 0: |
344 | | - raise RuntimeError( |
345 | | - "update_animation was called on a sprite that doesn't have a list of " |
346 | | - "walk up textures." |
347 | | - ) |
348 | | - elif self.state == FACE_DOWN: |
349 | | - texture_list = self.walk_down_textures |
350 | | - if texture_list is None or len(texture_list) == 0: |
351 | | - raise RuntimeError( |
352 | | - "update_animation was called on a sprite that doesn't " |
353 | | - "have a list of walk down textures." |
354 | | - ) |
355 | | - |
356 | | - self.cur_texture_index += 1 |
357 | | - if self.cur_texture_index >= len(texture_list): |
358 | | - self.cur_texture_index = 0 |
359 | | - |
360 | | - self.texture = texture_list[self.cur_texture_index] |
361 | | - |
362 | | - if self._texture is None: |
363 | | - logger.warning("Error, no texture set") |
364 | | - else: |
365 | | - self.width = self._texture.width * self.scale_x |
366 | | - self.height = self._texture.height * self.scale_y |
0 commit comments