Fixed map rendering
This commit is contained in:
parent
5b60ddb8da
commit
9ef8d99c61
@ -12,7 +12,7 @@ class Map:
|
|||||||
for line in f:
|
for line in f:
|
||||||
self.terrain.append(line)
|
self.terrain.append(line)
|
||||||
|
|
||||||
self.tileSize = self.screen.mapSize/20
|
self.tileSize = int(self.screen.mapSize/20)
|
||||||
|
|
||||||
self.tileWidth = len(self.terrain[0])
|
self.tileWidth = len(self.terrain[0])
|
||||||
self.tileHeight = len(self.terrain)
|
self.tileHeight = len(self.terrain)
|
||||||
@ -25,10 +25,10 @@ class Map:
|
|||||||
for row, tiles in enumerate(self.terrain):
|
for row, tiles in enumerate(self.terrain):
|
||||||
for col, tile in enumerate(tiles):
|
for col, tile in enumerate(tiles):
|
||||||
if tile == 'w':
|
if tile == 'w':
|
||||||
self.screen.draw(TerrainTile(self.game, col, row, 'wall.png', self.screen.mapSize), Locations.MAP, col, row)
|
self.screen.draw(TerrainTile('wall.png', self.tileSize), Locations.MAP, col*self.tileSize, row*self.tileSize)
|
||||||
if tile == ',':
|
elif tile == ',':
|
||||||
self.screen.draw(TerrainTile(self.game, col, row, 'floor.png', self.screen.mapSize), Locations.MAP, col, row)
|
self.screen.draw(TerrainTile('floor.png', self.tileSize), Locations.MAP, col*self.tileSize, row*self.tileSize)
|
||||||
if tile == '.':
|
elif tile == '.':
|
||||||
self.screen.draw(TerrainTile(self.game, col, row, 'grass.png', self.screen.mapSize), Locations.MAP, col, row)
|
self.screen.draw(TerrainTile('grass.png', self.tileSize), Locations.MAP, col*self.tileSize, row*self.tileSize)
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,18 +4,10 @@ from os import path
|
|||||||
|
|
||||||
|
|
||||||
class TerrainTile(pygame.sprite.Sprite):
|
class TerrainTile(pygame.sprite.Sprite):
|
||||||
def __init__(self, game, x, y, texture, mapSize):
|
def __init__(self, texture, tileSize):
|
||||||
self.tiles = []
|
super().__init__()
|
||||||
self.groups = game.spritesList
|
|
||||||
pygame.sprite.Sprite.__init__(self, self.groups)
|
|
||||||
self.game = game
|
|
||||||
self.imagesFolder = path.dirname("../data/images/")
|
self.imagesFolder = path.dirname("../data/images/")
|
||||||
self.terrainFolder = path.join(self.imagesFolder, 'terrain')
|
self.terrainFolder = path.join(self.imagesFolder, 'terrain')
|
||||||
self.image = pygame.image.load(os.path.join(self.terrainFolder, texture)).convert()
|
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.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
|
|
||||||
|
Loading…
Reference in New Issue
Block a user