2021-03-14 17:12:11 +01:00
|
|
|
import os
|
|
|
|
|
|
|
|
from survival.textureatlas import TextureAtlas
|
|
|
|
from survival.tile import Tile
|
|
|
|
|
|
|
|
|
|
|
|
class TileLayer:
|
|
|
|
def __init__(self, width, height):
|
|
|
|
self.width = width
|
|
|
|
self.height = height
|
|
|
|
self.tiles = [[Tile() for x in range(self.width)] for y in range(self.height)]
|
|
|
|
self.atlas = TextureAtlas(os.path.join('..', 'assets', 'atlas.png'))
|
2021-03-14 18:42:40 +01:00
|
|
|
self.loadTiles()
|
|
|
|
|
|
|
|
def loadTiles(self):
|
|
|
|
for y in range(self.height):
|
|
|
|
for x in range(self.width):
|
|
|
|
self.tiles[y][x].image = self.atlas.image_at(self.tiles[y][x].origin, (32, 32))
|
2021-03-14 17:12:11 +01:00
|
|
|
|
|
|
|
def draw(self, window):
|
|
|
|
for y in range(self.height):
|
|
|
|
for x in range(self.width):
|
2021-03-14 18:42:40 +01:00
|
|
|
if self.tiles[y][x] is not None:
|
|
|
|
window.blit(self.tiles[y][x].image, (x * 32, y * 32))
|