60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
import pygame
|
|
import numpy as np
|
|
import Math
|
|
import Types
|
|
|
|
# MAT_CART = 1 / (0.5 * 0.25 + 0.5 * 0.25) * np.array([[0.25, -0.25], [0.5, 0.5]])
|
|
|
|
|
|
class MapTile(pygame.sprite.Sprite):
|
|
size = 64
|
|
image = pygame.image.load("tileset/placeholder.png")
|
|
|
|
def __init__(self, x: int, y: int):
|
|
super(MapTile, self).__init__()
|
|
self.image = MapTile.image
|
|
# self.rect = self.image.get_rect()
|
|
self.rect = pygame.Rect(
|
|
x - MapTile.size / 2, y - MapTile.size / 2, MapTile.size, MapTile.size
|
|
)
|
|
# self.rect.center = (x, y)
|
|
|
|
|
|
class IsoMapTile(MapTile):
|
|
def __init__(
|
|
self,
|
|
u: int,
|
|
v: int,
|
|
elevation: int = 0,
|
|
origin: np.ndarray = np.array([0, 0]),
|
|
):
|
|
# vec = np.array([u, v]) @ MAT_ISO * tile_size + origin
|
|
vec = Math.from_iso(np.array([u, v], np.int32), MapTile.size, origin)
|
|
super(IsoMapTile, self).__init__(vec[0], vec[1] + MapTile.size / 8 * elevation)
|
|
self.u = u
|
|
self.v = v
|
|
self.elevation = elevation
|
|
|
|
def update(self, dx: int, dy: int):
|
|
self.rect.move_ip(-dx, -dy)
|
|
|
|
def move(self, uv: Types.IsoCoord, origin: Types.CartCoors):
|
|
vec = Math.from_iso(uv, MapTile.size, origin)
|
|
self.rect.center = (vec[0], vec[1] + MapTile.size / 8 * self.elevation)
|
|
|
|
|
|
class CursorTile(IsoMapTile):
|
|
image = pygame.image.load("tileset/cursor.png")
|
|
|
|
def __init__(
|
|
self,
|
|
uv: Types.IsoCoord,
|
|
elevation: int = 0,
|
|
origin: Types.CartCoors = np.array([0, 0]),
|
|
):
|
|
super(CursorTile, self).__init__(
|
|
u=uv[0], v=uv[1], elevation=elevation, origin=origin
|
|
)
|
|
|
|
self.image = CursorTile.image
|