refactor TerrainTile
This commit is contained in:
parent
9f95091ff6
commit
815eb79452
@ -42,7 +42,7 @@ class Game:
|
|||||||
|
|
||||||
# Start Map implement
|
# Start Map implement
|
||||||
self.mapDataFolder = path.dirname("../data/mapdata/")
|
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
|
# End Map implement
|
||||||
|
|
||||||
self.mainLoop()
|
self.mainLoop()
|
||||||
|
@ -3,8 +3,7 @@ from game.TerrainTile import TerrainTile
|
|||||||
from game.Screen import Locations
|
from game.Screen import Locations
|
||||||
|
|
||||||
class Map:
|
class Map:
|
||||||
def __init__(self, filename, game, screen):
|
def __init__(self, filename, screen):
|
||||||
self.game = game
|
|
||||||
self.screen = screen
|
self.screen = screen
|
||||||
self.terrain = []
|
self.terrain = []
|
||||||
self.entities = []
|
self.entities = []
|
||||||
@ -25,10 +24,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(col, row, 'wall.png', self.screen.mapSize), Locations.MAP, col, row)
|
||||||
if tile == ',':
|
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 == '.':
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,11 +4,8 @@ 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, x, y, texture, mapSize):
|
||||||
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user