-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiles.py
53 lines (44 loc) · 1.64 KB
/
tiles.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
48
49
50
51
52
53
import pygame
from support import import_folder
class Tile(pygame.sprite.Sprite):
def __init__(self,size,x,y):
super().__init__()
self.image = pygame.Surface((size,size))
self.rect = self.image.get_rect(topleft = (x,y))
def update(self,x_shift):
self.rect.x += x_shift
class StaticTile(Tile):
def __init__(self,size,x,y,surface):
super().__init__(size,x,y)
self.image = surface
class Crate(StaticTile):
def __init__(self, size, x, y ):
super().__init__(size, x, y, pygame.image.load('graphics/terrain/crate.png').convert_alpha())
offset_y = y + size
self.rect = self.image.get_rect(bottomleft = (x,offset_y))
class AnimatedTile(Tile):
def __init__(self,size,x,y,path):
super().__init__(size,x,y)
self.frames = import_folder(path)
self.frame_index = 0
self.image = self.frames[self.frame_index]
def animate(self):
self.frame_index += 0.15
if self.frame_index >= len(self.frames):
self.frame_index = 0
self.image = self.frames[int(self.frame_index)]
def update(self, x_shift):
self.animate()
self.rect.x += x_shift
class Coin(AnimatedTile):
def __init__(self,size,x,y,path, value):
super().__init__(size,x,y,path)
center_x = x + int(size/2)
center_y = y + int(size/2)
self.rect = self.image.get_rect(center = (center_x,center_y))
self.value = value
class Palm(AnimatedTile):
def __init__(self,size,x,y,path,offset):
super().__init__(size,x,y,path)
offset_y = y - offset
self.rect.topleft = (x,offset_y)