import pygame import os import numpy as np TILE_DICT = { 1 : ('iso',0), 2 : ('iso',1), 3 : ('iso',2), 4 : ('iso',3), 5 : ('iso',4), 6 : ('iso',5) } 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 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]))