diff --git a/src/game/Map.py b/src/game/Map.py index 7ed7db2..0b60871 100644 --- a/src/game/Map.py +++ b/src/game/Map.py @@ -12,7 +12,7 @@ class Map: for line in f: self.terrain.append(line) - self.tileSize = self.screen.mapSize/20 + self.tileSize = int(self.screen.mapSize/20) self.tileWidth = len(self.terrain[0]) self.tileHeight = len(self.terrain) @@ -25,10 +25,10 @@ class Map: for row, tiles in enumerate(self.terrain): for col, tile in enumerate(tiles): if tile == 'w': - self.screen.draw(TerrainTile(self.game, col, row, 'wall.png', self.screen.mapSize), Locations.MAP, col, row) - if tile == ',': - self.screen.draw(TerrainTile(self.game, col, row, 'floor.png', self.screen.mapSize), Locations.MAP, col, row) - if tile == '.': - self.screen.draw(TerrainTile(self.game, col, row, 'grass.png', self.screen.mapSize), Locations.MAP, col, row) + self.screen.draw(TerrainTile('wall.png', self.tileSize), Locations.MAP, col*self.tileSize, row*self.tileSize) + elif tile == ',': + self.screen.draw(TerrainTile('floor.png', self.tileSize), Locations.MAP, col*self.tileSize, row*self.tileSize) + elif tile == '.': + self.screen.draw(TerrainTile('grass.png', self.tileSize), Locations.MAP, col*self.tileSize, row*self.tileSize) diff --git a/src/game/TerrainTile.py b/src/game/TerrainTile.py index dcebdc8..636838b 100644 --- a/src/game/TerrainTile.py +++ b/src/game/TerrainTile.py @@ -4,18 +4,10 @@ from os import path class TerrainTile(pygame.sprite.Sprite): - def __init__(self, game, x, y, texture, mapSize): - self.tiles = [] - self.groups = game.spritesList - pygame.sprite.Sprite.__init__(self, self.groups) - self.game = game + def __init__(self, texture, tileSize): + super().__init__() self.imagesFolder = path.dirname("../data/images/") self.terrainFolder = path.join(self.imagesFolder, 'terrain') self.image = pygame.image.load(os.path.join(self.terrainFolder, texture)).convert() - self.image.set_colorkey((0,100,0)) + self.image = pygame.transform.scale(self.image, (tileSize, tileSize)) self.rect = self.image.get_rect() - self.x = x - self.y = y - self.tileSize = mapSize/20 - self.rect.x = self.x * self.tileSize - self.rect.y = self.y * self.tileSize