-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile.py
36 lines (29 loc) · 999 Bytes
/
tile.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
import pygame
from config import *
class Tile:
def __init__(self, clazz : str, type : int, pos : tuple) -> None:
self.clazz = clazz
self.type = type
self.pos = pos
if self.clazz in Tile.collideables():
self.collisionRect = pygame.Rect(self.pos[0] * DEFAULT_TILESIZE, self.pos[1] * DEFAULT_TILESIZE, DEFAULT_TILESIZE, DEFAULT_TILESIZE)
else:
self.collisionRect = None
def toDict(self):
return {
'clazz' : self.clazz,
'type' : self.type,
'pos' : self.pos
}
@staticmethod
def fromDict(dictTile : dict):
return Tile(clazz=dictTile['clazz'], type=dictTile['type'], pos=tuple(dictTile['pos']))
@staticmethod
def collideables():
return ('crates', 'grass', 'platforms')
@staticmethod
def platforms():
return ('platforms', 'platforms_alt')
@staticmethod
def blocks():
return ('grass', 'crates')