-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMSprite.py
48 lines (37 loc) · 1.3 KB
/
MSprite.py
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
import pygame as pg
from pygame.locals import *
from time import time
import random
from Sprite import Sprite
from Pos import Pos
from time import time
class MSprite:
def __init__(self,sprite_list:list,
should_shuffle:bool=False,
tick_speed_list:list[float]=[0.5]):
self.last_epoch:float = time()
self.tick_speed:float = random.choice(tick_speed_list)
self.x_flipped:bool = False
self.y_flipped:bool = False
self.should_shuffle = should_shuffle
self.image_index:int = 0
self.sprite_list:list = sprite_list
def do_flips(self):
for i in self.sprite_list:
i.x_flipped = self.x_flipped
i.y_flipped = self.y_flipped
i.do_flips()
def tick(self):
if self.should_shuffle:
self.image_index = random.randint(0,len(self.sprite_list)-1)
return
self.image_index += 1
if self.image_index>=len(self.sprite_list):
self.image_index = 0
def check_events(self):
T2 = time()
if self.last_epoch + self.tick_speed < T2:
self.last_epoch = T2
self.tick()
def render(self,screen:pg.surface.Surface,top_left_pos:Pos):
self.sprite_list[self.image_index].render(screen,top_left_pos)