-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCheckpoints.py
More file actions
63 lines (46 loc) · 1.58 KB
/
Copy pathCheckpoints.py
File metadata and controls
63 lines (46 loc) · 1.58 KB
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
import pygame as pg
from Config import SCREEN, CHECKPOINT
from AssetLoader import CHECKPOINTS
SCREEN_HEIGHT, SCREEN_WIDTH = SCREEN['SIZE']
class Checkpoint(pg.sprite.Sprite):
''' Checkpoint or finish '''
width, height = CHECKPOINT['SIZE']
level = None
tick = 1
state_img = 0
level = None
level_no = 0
def __init__(self, x,y, name='Flag', item='Flag'):
super(Checkpoint, self).__init__()
self.name = name
self.item = item
self.image = CHECKPOINTS[item][self.state_img]
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = SCREEN['SIZE'][1] - y #This used bottom right as 0,0 insted of top left
def update(self):
''' Update position, movementspeed and animation, called once every fps'''
# Update every 3
if self.tick == 3:
self.tick = 1
self._animation_tick()
self._tint_image()
else:
self.tick += 1
def _animation_tick(self):
''' Swap surface to next in animation '''
if self.state_img == len(CHECKPOINTS[self.item]):
self.state_img = 0
self.image = CHECKPOINTS[self.item][self.state_img]
# Get next image next tick
self.state_img += 1
def _change_state(self, new_state):
''' Update state with different behavior'''
self.state_img = 0
self.state = new_state
def _tint_image(self):
''' for subclasses to be able to tint '''
pass
if __name__ == '__main__':
p = Checkpoint()
pass