Add tile cost

This commit is contained in:
Jakub Klupieć 2021-05-09 16:36:28 +02:00
parent 4ceaf4904b
commit 89ad35bdf9
4 changed files with 24 additions and 9 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1,9 +1,5 @@
import random
class Tile: class Tile:
origins = [(0, 0), (32, 0), (64, 0), (96, 0)] def __init__(self, origin, cost):
self.origin = origin
def __init__(self, origin=(0, 0)): self.cost = cost
self.origin = random.choice(Tile.origins)
self.image = None self.image = None

View File

@ -0,0 +1,19 @@
import random
from survival.tile import Tile
class TileGenerator:
templates = [
[(0, 0), 1], # Grass 1
[(32, 0), 1], # Grass 2
[(64, 0), 1], # Grass 3
[(96, 0), 1], # Grass 4
[(64, 64), 2], # Sand
[(96, 64), 2], # Poddle
]
@staticmethod
def get_random_tile():
template = random.choice(TileGenerator.templates)
return Tile(template[0], template[1])

View File

@ -1,12 +1,12 @@
from survival.image import Image from survival.image import Image
from survival.tile import Tile from survival.tile_generator import TileGenerator
class TileLayer: class TileLayer:
def __init__(self, width, height): def __init__(self, width, height):
self.width = width self.width = width
self.height = height self.height = height
self.tiles = [[Tile() for x in range(self.width)] for y in range(self.height)] self.tiles = [[TileGenerator.get_random_tile() for x in range(self.width)] for y in range(self.height)]
self.image = Image('atlas.png') self.image = Image('atlas.png')
def draw(self, camera, visible_area): def draw(self, camera, visible_area):