2021-05-10 11:02:36 +02:00
|
|
|
from survival.generators.tile_generator import TileGenerator
|
2021-05-10 13:06:29 +02:00
|
|
|
from survival.image import Image
|
2021-05-10 12:56:08 +02:00
|
|
|
from survival.tile import Tile
|
2021-03-14 17:12:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TileLayer:
|
|
|
|
def __init__(self, width, height):
|
|
|
|
self.width = width
|
|
|
|
self.height = height
|
2021-05-10 12:56:08 +02:00
|
|
|
self.tiles: list[list[Tile]] = TileGenerator.generate_biome_tiles(width, height)
|
|
|
|
# self.tiles: list[list[Tile]] = TileGenerator.generate_random_tiles(width, height)
|
2021-03-14 22:43:26 +01:00
|
|
|
self.image = Image('atlas.png')
|
2021-03-14 17:12:11 +01:00
|
|
|
|
2021-03-15 14:10:19 +01:00
|
|
|
def draw(self, camera, visible_area):
|
2021-03-28 18:05:52 +02:00
|
|
|
for y in range(int(visible_area.top / 32), int(visible_area.height / 32) + 1):
|
|
|
|
for x in range(int(visible_area.left / 32), int(visible_area.width / 32) + 1):
|
2021-03-28 18:56:32 +02:00
|
|
|
if y >= self.height or x >= self.width:
|
|
|
|
continue
|
|
|
|
|
2021-03-15 14:10:19 +01:00
|
|
|
self.image.pos = (x * 32, y * 32)
|
2021-03-14 22:43:26 +01:00
|
|
|
self.image.origin = self.tiles[y][x].origin
|
2021-03-15 13:31:25 +01:00
|
|
|
camera.draw(self.image)
|
2021-05-09 18:11:25 +02:00
|
|
|
|
|
|
|
def get_cost(self, pos):
|
|
|
|
return self.tiles[pos[1]][pos[0]].cost
|