Overflown/gamedata/objects/combat/tileset.py

52 lines
1.9 KiB
Python
Raw Normal View History

2021-06-25 16:13:52 +02:00
from gamedata.objects.base import BaseObject
class TilesetRenderer(BaseObject):
def __init__(self,x,y,game,mapfoldername):
2021-06-25 16:13:52 +02:00
super().__init__(x,y,game)
self.tilew = 64
self.tileh = 64
self.level = game.levels_lib[mapfoldername]
self.reinit_rects(self.level)
2021-06-25 16:13:52 +02:00
def draw(self):
for i in self.rects:
self.game.pygame.draw.rect(self.game.window,[255,0,0],(i[0:4]))
def reinit_rects(self,level):
json = level["data"]
name = level["name"]
self.rects = []
if "layers" in json.keys():
solidlayer = False
for layer in json["layers"]:
try:
if layer["name"] == "Solids" and "entities" in layer.keys() :
solidlayer = layer
break
except:
self.game.log("Erreur",name,"Les layers sont invalides")
if solidlayer:
if "gridCellWidth" in solidlayer.keys() and "gridCellHeight" in solidlayer.keys():
self.solidtilew = solidlayer["gridCellWidth"]
self.solidtileh = solidlayer["gridCellHeight"]
else:
self.solidtilew,self.solidtileh = 32,32
self.game.log("Erreur",name,"Pas de taille de tiles précisée, défaut à 32x32")
for entity in solidlayer["entities"]:
try:
x,y = entity["x"],entity["y"]
w,h = entity["width"],entity["height"]
self.rects.append(self.game.pygame.Rect(x,y,w,h))
except:
self.game.log("Erreur",name,"Propriétés invalides")
else:
self.game.log("Erreur",name,"Il manque les collisions, Entity Layer nommé Solids")
else:
self.game.log("Erreur",name,"Pas de layers")