Added respawn method

This commit is contained in:
Marcin Kostrzewski 2020-05-16 12:47:40 +02:00
parent a45be130e6
commit 264aa2969c

View File

@ -31,7 +31,9 @@ class Map:
# lista wszystkich entity # lista wszystkich entity
self.entities = pygame.sprite.Group() self.entities = pygame.sprite.Group()
with open(filename, 'rt') as f: self.filename = filename
with open(self.filename, 'rt') as f:
for line in f: for line in f:
self.terrain.append(line) self.terrain.append(line)
@ -44,7 +46,7 @@ class Map:
self.terrainDraw() self.terrainDraw()
for entity in self.loadEntities(filename): for entity in self.loadEntities(self.filename):
self.addEntity(entity) self.addEntity(entity)
def loadEntities(self, mapFileName): def loadEntities(self, mapFileName):
@ -153,6 +155,18 @@ class Map:
self.screen.addSprite(object, Locations.MAP) self.screen.addSprite(object, Locations.MAP)
self.collidables.add(object) self.collidables.add(object)
def respawn(self):
"""
Respawns all entities on the map.
"""
for entity in self.entities.sprites():
entity.kill()
del entity
entites = self.loadEntities(self.filename)
for entity in entites:
self.addEntity(entity)
def getEntityOnCoord(self, coord, screenRelative=False): def getEntityOnCoord(self, coord, screenRelative=False):
""" """
Get an entity on a given coordinate Get an entity on a given coordinate