Ajout de spawnpoints

This commit is contained in:
theo@manjaro 2021-07-03 00:26:02 +02:00
parent 40cb691157
commit 0d27a09e0c
4 changed files with 43 additions and 6 deletions

View File

@ -705,6 +705,22 @@
{"name": "Solid", "id": 21, "_eid": "17026310", "x": 80, "y": 192, "width": 64, "height": 48, "originX": 0, "originY": 0},
{"name": "Solid", "id": 22, "_eid": "17026310", "x": 32, "y": 208, "width": 48, "height": 16, "originX": 0, "originY": 0}
]
},
{
"name": "Spawns",
"_eid": "25815759",
"offsetX": 0,
"offsetY": 0,
"gridCellWidth": 16,
"gridCellHeight": 16,
"gridCellsX": 37,
"gridCellsY": 17,
"entities": [
{"name": "Spawns", "id": 0, "_eid": "25816588", "x": 416, "y": 160, "originX": 0, "originY": 0},
{"name": "Spawns", "id": 1, "_eid": "25816588", "x": 528, "y": 112, "originX": 0, "originY": 0},
{"name": "Spawns", "id": 2, "_eid": "25816588", "x": 160, "y": 160, "originX": 0, "originY": 0},
{"name": "Spawns", "id": 3, "_eid": "25816588", "x": 48, "y": 112, "originX": 0, "originY": 0}
]
}
]
}

View File

@ -2,13 +2,17 @@ from gamedata.objects.base import BaseObject
class Player(BaseObject):
def __init__(self,x,y,game):
def __init__(self,game):
self.sprite = game.sprite_lib["icon.png"]
tileset = game.gameloop.findname("TilesetRenderer")[0]
spawnpoint = game.lib.choice(tileset.spawns)
x,y = spawnpoint.center
super().__init__(x,y,game,self.sprite.get_width(),self.sprite.get_height())
tileset = game.gameloop.findname("TilesetRenderer")[0]
self.collisionrects = tileset.rects
self.tilew = tileset.solidtilew
self.tileh = tileset.solidtileh

View File

@ -26,12 +26,24 @@ class TilesetRenderer(BaseObject):
name = level["name"]
self.rects = []
self.layers = []
self.spawns = []
if "layers" in json.keys() and type(json["layers"]).__name__=="list":
solidlayer = False
for layer in json["layers"]:
try:
#try:
if True:
if layer["name"] == "Solids" and "entities" in layer.keys() : # Je trouve les collisions
solidlayer = layer
elif layer["name"] == "Spawns" and "entities" in layer.keys() : # Je trouve les spawns
for entity in layer["entities"]:
x,y = entity["x"],entity["y"]
w,h = layer["gridCellWidth"],layer["gridCellHeight"]
if "width" in entity.keys():
w = entity["width"]
if "height" in entity.keys():
h = entity["height"]
self.spawns.append(self.game.pygame.Rect((x,y,w,h)))
else: # J'ajoute un layer de tiles
tileset = level["tilesets"][layer["tileset"]]
tilew,tileh = layer["gridCellWidth"],layer["gridCellHeight"]
@ -47,7 +59,8 @@ class TilesetRenderer(BaseObject):
surface.blit(tileset,(x*tilew,y*tileh),area=areatocopy)
storedlayer["surface"] = surface
self.layers.append(storedlayer)
except:
#except:
else:
self.game.log("Erreur",name,"Les layers sont invalides")
if solidlayer: # Je crée les collisions
if "gridCellWidth" in solidlayer.keys() and "gridCellHeight" in solidlayer.keys():
@ -59,7 +72,11 @@ class TilesetRenderer(BaseObject):
for entity in solidlayer["entities"]:
try:
x,y = entity["x"],entity["y"]
w,h = entity["width"],entity["height"]
w,h = self.solidtilew,self.solidtileh
if "width" in entity.keys():
w = entity["width"]
if "height" in entity.keys():
h = entity["height"]
self.rects.append(self.game.pygame.Rect(x,y,w,h))
except:
self.game.log("Erreur",name,"Propriétés invalides")

View File

@ -21,7 +21,7 @@ def fight(game):
mapname = game.lib.choice(list(game.levels_lib.keys()))
tileset = TilesetRenderer(0,0,game,mapname)
game.gameloop.summon(tileset)
p1 = Player(70,50,game)
p1 = Player(game)
game.gameloop.summon(p1)
def options(game):