2024-07-10 20:08:18 +02:00
|
|
|
import pygame
|
|
|
|
import os
|
2024-07-12 16:56:47 +02:00
|
|
|
import numpy as np
|
2024-07-10 20:08:18 +02:00
|
|
|
TILE_DICT = {
|
2024-07-12 22:04:31 +02:00
|
|
|
1 : ('iso',0,True),
|
|
|
|
2 : ('iso',1,False),
|
|
|
|
3 : ('iso',2,False),
|
|
|
|
4 : ('iso',3,False),
|
|
|
|
5 : ('iso',4,False),
|
|
|
|
6 : ('iso',5,False)
|
2024-07-10 20:08:18 +02:00
|
|
|
}
|
|
|
|
BASE_IMG_PATH = 'data/images/'
|
|
|
|
def load_image(path):
|
|
|
|
img = pygame.image.load(BASE_IMG_PATH + path).convert()
|
|
|
|
img.set_colorkey((0,0,0))
|
|
|
|
return img
|
|
|
|
|
|
|
|
def load_images(path):
|
|
|
|
images = []
|
|
|
|
for img_name in sorted(os.listdir(BASE_IMG_PATH + path)):
|
|
|
|
images.append(load_image(path + '/' + img_name))
|
|
|
|
return images
|
2024-07-12 16:56:47 +02:00
|
|
|
def to_isometric(coord, tilesize):
|
|
|
|
#(1,0) -> (+tilesize[0]/2,+tilesize[1]/2)
|
|
|
|
#(0,1) -> (-tilesize[0]/2,+tilesize[1]/2)
|
|
|
|
#a must be (+tilesize[0]/2,-tilesize[0]/2)
|
|
|
|
# (+tilesize[1]/2,+tilesize[1]/2)
|
|
|
|
a = np.array([[1,-1],[1,1]])
|
|
|
|
a = 0.5 * a * tilesize[:,np.newaxis]
|
|
|
|
return np.squeeze(np.matmul(a,coord[:,np.newaxis]))
|
|
|
|
def to_cartesian(coord, tilesize):
|
|
|
|
#manually calculated the inverse of a in to_isometric
|
|
|
|
a = np.array([[1,1],[-1,1]])
|
|
|
|
a = a * (1/tilesize)
|
|
|
|
return np.squeeze(np.matmul(a,coord[:,np.newaxis]))
|
|
|
|
def to_isometric_pixel(coord):
|
|
|
|
a = np.array([[1,-1],[1,1]])
|
|
|
|
a = 0.5 * a
|
|
|
|
return np.squeeze(np.matmul(a,coord[:,np.newaxis]))
|