commit 95cd888aedc42c4b653f02e53fbcdafe47112374 Author: Acereca Date: Sat Jun 4 18:07:47 2022 +0200 initial setup with working isometric grid transoform diff --git a/Tiles.py b/Tiles.py new file mode 100644 index 0000000..449920a --- /dev/null +++ b/Tiles.py @@ -0,0 +1,31 @@ +import pygame +import numpy as np + +tile_size = 64 +MAT_ISO = np.array([[0.5, 0.25], [-0.5, 0.25]]) + + +class MapTile(pygame.sprite.Sprite): + def __init__(self, x: int, y: int): + super(MapTile, self).__init__() + self.image = pygame.image.load("tileset/placeholder.png") + self.rect = self.image.get_rect() + self.rect.center = (x, y) + + +class IsoMapTile(MapTile): + def __init__( + self, + u: int, + v: int, + elevation: int = 0, + origin: np.ndarray = np.array([100, 100]), + ): + vec = np.array([u, v]) @ MAT_ISO * tile_size + origin + super(IsoMapTile, self).__init__(vec[0], vec[1] + tile_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) diff --git a/main.py b/main.py new file mode 100755 index 0000000..f2a11e1 --- /dev/null +++ b/main.py @@ -0,0 +1,87 @@ +import pygame +import pygame_gui as pgg +import numpy as np +import Tiles + +screen_size = np.array([16 / 9 / 2, 1]) * 1440 + +origin = np.array([screen_size[0] / 2, Tiles.tile_size]) + + +def load_map(map_file="map.dnd"): + for u, v, elevation, tile in lines: + getattr(Tiles, tile)(u, v, elevation) + + +def save_map(map_tiles: pygame.sprite.RenderPlain, map_file: str = "map.dnd"): + for tile in map_tiles.sprites(): + (tile.u, tile.v, tile.elevation, type(tile)) + + +def main(): + pygame.init() + # pygame.font.init() + # font = pygame.font.SysFont("Raleway", 12) + screen = pygame.display.set_mode(screen_size) + bg = pygame.Surface(screen_size) + bg.fill(pygame.Color("#cccccc")) + clock = pygame.time.Clock() + + # gui_manager = pgg.UIManager(screen_size) + # save_btn = pgg.elements.UIButton( + # relative_rect=pygame.Rect((0, 0), (100, 20)), + # text="Save", + # manager=gui_manager, + # ) + + # mouse_prev_x, mouse_prev_y = pygame.mouse.get_pos() + + # map_text = font.render("test", True, (0, 0, 0)) + map_tiles = pygame.sprite.RenderPlain() + for xix in range(10): + for yix in range(10): + tile = Tiles.IsoMapTile(xix, yix, 0, origin) + map_tiles.add(tile) + + gameit = 0 + is_running = True + while is_running: + time_delta = clock.tick(60) / 1000 + + # events + # mouse_x, mouse_y = pygame.mouse.get_pos() + + # if pygame.mouse.get_pressed()[1]: + # map_tiles.update(mouse_prev_x - mouse_x, mouse_prev_y - mouse_y) + + # mouse_prev_x = mouse_x + # mouse_prev_y = mouse_y + for evt in pygame.event.get(): + if evt.type == pygame.QUIT: + is_running = False + if evt.type == pygame.KEYDOWN: + if evt.key == pygame.K_ESCAPE: + is_running = False + + # if evt.type == pgg.UI_BUTTON_PRESSED: + # if evt.ui_element == save_btn: + # save_map(map_tiles) + # gui_manager.process_events(evt) + + # gui_manager.update(time_delta) + + # Drawing + screen.blit(bg, (0, 0)) + map_tiles.draw(screen) + + # gui_manager.draw_ui(screen) + pygame.display.flip() + + gameit += 1 + + pygame.quit() + + +if __name__ == "__main__": + + main() diff --git a/tileset/placeholder.png b/tileset/placeholder.png new file mode 100644 index 0000000..bec9dd8 Binary files /dev/null and b/tileset/placeholder.png differ