def draw_hp(self): full_hp = TILE_COSTS[self.type] if full_hp == math.inf: return percent = int((full_hp - self.hp) / full_hp * 4) if 0 < percent < 4: # TODO: Move this to the main function gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) get_tile(percent, 3).blit(self.x, self.y)
B = BEDROCK = 5 P = PYRAMID = 6 TILE_COSTS = { TileType.ROAD: 0.5, TileType.GROUND: 1.0, TileType.WATER: 3.0, TileType.TREE: 2, TileType.STONE: 4, TileType.BEDROCK: math.inf, TileType.PYRAMID: math.inf, } TILE_IMAGES = { TileType.ROAD: get_tile(1, 5), TileType.GROUND: get_tile(1, 6), TileType.WATER: get_tile(0, 5), TileType.TREE: get_tile(10, 6), TileType.STONE: get_tile(8, 4), TileType.BEDROCK: get_tile(9, 4), TileType.PYRAMID: get_tile(0, 0), } class Tile(BetterSprite): def __init__(self, tile_type: TileType, world, x=0, y=0): self.type = tile_type self.hp = TILE_COSTS[self.type] img = TILE_IMAGES[self.type] super().__init__(img, x, y, TERRAIN_BATCH)
def __init__(self, x, y): # TODO: Build a big, multi-tile pyramid that changes by completion image = get_tile(0, 1) super().__init__(image, x, y, ITEMS_BATCH)
import pyglet from media import get_tile ITEMS_BATCH = pyglet.graphics.Batch() class ResourceType(enum.Enum): WOOD = 0 WATER = 1 STONE = 2 RESOURCE_IMAGES = { ResourceType.WATER: get_tile(0, 4), ResourceType.STONE: get_tile(1, 2), ResourceType.WOOD: get_tile(2, 2), } RESOURCE_COLORS = { ResourceType.WATER: get_tile(10, 5), ResourceType.STONE: get_tile(8, 4), ResourceType.WOOD: get_tile(11, 7) } class Resource(pyglet.sprite.Sprite): def __init__(self, resource_type: ResourceType, x: int, y: int): self.type = resource_type img = RESOURCE_IMAGES[self.type]
import math import weakref import pyglet from media import get_tile from pathfinding import find_path from resources import Resource from tiles import DIGGABLE_TYPES, TileType, TILE_COSTS WORKERS_BATCH = pyglet.graphics.Batch() WORKER_IMAGE = get_tile(14, 0) class Worker(pyglet.sprite.Sprite): speed = 32 def __init__(self, x, y, world): super().__init__(WORKER_IMAGE, x=x * 16, y=y * 16, batch=WORKERS_BATCH) self.path = [] self.orders = None self.inventory = None self._world = weakref.proxy(world) @property def current_location(self): return (self.x + 8) // 16, (self.y + 8) // 16 def update(self, dt): tile = self._world.tiles[self.current_location]