Optimized map respawn method

This commit is contained in:
Marcin Kostrzewski 2020-05-17 00:14:42 +02:00
parent dcc8da6d2a
commit 584d371ec1

View File

@ -31,6 +31,8 @@ class Map:
# lista wszystkich entity # lista wszystkich entity
self.entities = pygame.sprite.Group() self.entities = pygame.sprite.Group()
self.entitiesRawData = []
self.filename = filename self.filename = filename
with open(self.filename, 'rt') as f: with open(self.filename, 'rt') as f:
@ -47,6 +49,7 @@ class Map:
self.terrainDraw() self.terrainDraw()
for entity in self.loadEntities(self.filename): for entity in self.loadEntities(self.filename):
self.entitiesRawData.append(entity)
self.addEntity(entity) self.addEntity(entity)
def loadEntities(self, mapFileName): def loadEntities(self, mapFileName):
@ -161,10 +164,8 @@ class Map:
""" """
for entity in self.entities.sprites(): for entity in self.entities.sprites():
entity.kill() entity.kill()
del entity
entites = self.loadEntities(self.filename) for entity in self.entitiesRawData:
for entity in entites:
self.addEntity(entity) self.addEntity(entity)
def getEntityOnCoord(self, coord, screenRelative=False): def getEntityOnCoord(self, coord, screenRelative=False):