Fixed map rendering

This commit is contained in:
Marcin Kostrzewski 2020-04-03 23:07:12 +02:00
parent 5b60ddb8da
commit 9ef8d99c61
2 changed files with 9 additions and 17 deletions

View File

@ -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)

View File

@ -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