1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
import pygame
#import os
#import random
class AnimatedSprite(pygame.sprite.Sprite):
"""
AnimatedSprite is a custom Sprite class for animated objects
images: list with sprite images
frames: list with image# for every frame
next_frames: list with next frame from current one
dxs: list with dx for current frame
dys: list with dy for current frame
xini: initial x position
yini: initial y position
fps: fps
"""
def __init__(self, images, frames, next_frames,
dxs, dys, xini, yini, fps = 10):
pygame.sprite.Sprite.__init__(self)
self._images = images
self._start = pygame.time.get_ticks()
self._delay = 1000 / fps
self._last_update = 0
self._frame = 0
self._frames = frames
self._next_frames = next_frames
self._dxs = dxs
self._dys = dys
self.x = xini
self.y = yini
self.move = 0
self.image = self._images[self._frames[self._frame]]
# self.update(pygame.time.get_ticks())
def update(self, t, grid):
# if t - self._last_update > self._delay:
# print("Can't reach fps.")
self.do_move(grid)
self.image = self._images[self._frames[self._frame]]
self._last_update = t
def render(self, screen):
screen.blit(self.image, (self.x, self.y))
# pygame.draw.rect(screen,(0,0,0),(self.x+15, self.y+38, 38, 38),1)
def do_move(self, grid):
pass
def update_frame(self, fr):
self._frame = fr
def update_move(self,move):
self.move = move
if __name__ == "__main__":
print("You can't run this file.")
print("You have to import AnimatedSprite from another Python file.")
|