refactor TerrainTile

This commit is contained in:
Mateusz Tylka 2020-04-03 20:23:36 +02:00
parent 9f95091ff6
commit 815eb79452
3 changed files with 7 additions and 11 deletions

View File

@ -42,7 +42,7 @@ class Game:
# Start Map implement
self.mapDataFolder = path.dirname("../data/mapdata/")
self.map = Map(path.join(self.mapDataFolder, 'map.txt'), self, self.screen)
self.map = Map(path.join(self.mapDataFolder, 'map.txt'), self.screen)
# End Map implement
self.mainLoop()

View File

@ -3,8 +3,7 @@ from game.TerrainTile import TerrainTile
from game.Screen import Locations
class Map:
def __init__(self, filename, game, screen):
self.game = game
def __init__(self, filename, screen):
self.screen = screen
self.terrain = []
self.entities = []
@ -25,10 +24,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)
self.screen.draw(TerrainTile(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)
self.screen.draw(TerrainTile(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(col, row, 'grass.png', self.screen.mapSize), Locations.MAP, col, row)

View File

@ -4,11 +4,8 @@ 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, x, y, texture, mapSize):
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()