Merge remote-tracking branch 'origin/latestThing' into latestThing

This commit is contained in:
Michał Czekański 2020-04-26 13:47:40 +02:00
commit 0151413cdd

View File

@ -14,11 +14,13 @@ from src.entities.Statistics import Statistics
class Map: class Map:
def __init__(self, filename, screen): def __init__(self, filename, screen):
self.screen = screen self.screen = screen
# tekstowa macierz terenów
self.terrain = [] self.terrain = []
self.collidableTerrain = [] # tereny bez kolizji
self.terrainTilesList = [] self.terrainTilesList = []
# grupa objektów kolizyjnych (tereny kolizyjne i entities)
self.collidables = pygame.sprite.Group() self.collidables = pygame.sprite.Group()
# lista wszystkich entity
self.entities = [] self.entities = []
with open(filename, 'rt') as f: with open(filename, 'rt') as f:
@ -108,26 +110,33 @@ class Map:
result = entity result = entity
return result return result
# W przypadku podania kordynatów playera, powinno zwrócić teren na którym jest player
def getTileOnCoord(self, coord): def getTileOnCoord(self, coord):
result = None result = None
for entity in self.terrainTilesList: for tile in self.terrainTilesList:
if entity.rect.x == coord[0] and entity.rect.y == coord[1]: if tile.rect.x == coord[0] and tile.rect.y == coord[1]:
result = entity result = tile
return result return result
# TODO: REMOVE DONT ADD # TODO: REMOVE DONT ADD
def addEntity(self, entity, DONTADD=False): def addEntity(self, entity, DONTADD=False):
self.screen.draw(entity, Locations.MAP, 0, 0) self.screen.draw(entity, Locations.MAP, 0, 0)
# dodajemy bo wszystkie entity są kolizyjne
self.collidables.add(entity) self.collidables.add(entity)
if not DONTADD: if not DONTADD:
self.entities.append(entity) self.entities.append(entity)
def removeSpriteFromMap(self, entity): # Usuwa entity lub teren z mapy
if self.collidables.has(entity): def removeSpriteFromMap(self, sprite):
self.collidables.remove(entity) if self.collidables.has(sprite):
self.screen.removeSprite(entity) self.collidables.remove(sprite)
if sprite in self.entities:
self.entities.remove(sprite)
if sprite in self.terrainTilesList:
self.terrainTilesList.remove(sprite)
self.screen.removeSprite(sprite)
self.entities.remove(entity)
# add object to map.collidables list to be collidable # add object to map.collidables list to be collidable
def collision(self, x, y): def collision(self, x, y):