diff --git a/__pycache__/eb_engine.cpython-314.pyc b/__pycache__/eb_engine.cpython-314.pyc index b004bc4..9ac0886 100644 Binary files a/__pycache__/eb_engine.cpython-314.pyc and b/__pycache__/eb_engine.cpython-314.pyc differ diff --git a/eb_engine.py b/eb_engine.py index c705e22..76bbee8 100644 --- a/eb_engine.py +++ b/eb_engine.py @@ -12,38 +12,47 @@ class Cell: #creature_obj: any is_target: bool = False - def draw(self, screen, bord_color, x, y, size, bord_size): - pygame.draw.rect(screen, bord_color, pygame.Rect(x, y, size, size), bord_size) - +@dataclass class Map: - def __init__(self, name, cell_color = "gray57", active_cell_color = "gray57"): - self.name = name + name: str + cells: dict = None + color: str = "gray57" + target_color: str = "gold" + size: int = 150 + bord: int = 5 + scale: float = 1 + cam_x: int = 0 + cam_y: int = 0 + cell_dist: int = 2 + + def __post_init__(self): self.cells = {} with open(self.name, 'r') as file: buff = json.load(file) - for line in range(len(buff)): self.cells[line] = [] for cell in buff[str(line)]: final_cell = Cell(cell_classes[cell["type"]](**cell["cell"]["terrain_obj"])) self.cells[line].append(deepcopy(final_cell)) - self.cell_color = cell_color - - def draw(self, scale_size): - for line in range(len(self.cells)): - for cell in line: - pass + def draw(self, screen): + for l in range(len(self.cells)): + for i, cell in enumerate(self.cells[l]): + x = int((i * self.size + self.cam_x) * self.scale) + y = int((l * self.size + self.cam_y) * self.scale) + w = int(self.size * self.scale - self.cell_dist) + h = int(self.size * self.scale - self.cell_dist) + pygame.draw.rect(screen, self.color, pygame.Rect(x, y, w, h), self.bord) + class Engine: def __init__(self, width, height, scale_size = 5, camera_pos = pygame.Vector2(0, 0)): self.width = width self.height = height self.scale_size = scale_size - self.camera_pos = camera_pos - def main_loop(self): + def main_loop(self): ''' #o = eb_terrain.Ground(1, 1, 1) #c = eb_creatures.Unit(1, 1, 1) @@ -52,8 +61,7 @@ class Engine: #print(isinstance(c, eb_objects.Terrain)) ''' - easy_map = Map("def_map.json", "gray57") - print(1) + easy_map = Map("def_map.json") # pygame setup pygame.init() @@ -61,6 +69,8 @@ class Engine: clock = pygame.time.Clock() running = True dt = 0 + camera_step = 10 + scale_step = 0.1 player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2) @@ -74,19 +84,24 @@ class Engine: # fill the screen with a color to wipe away anything from last frame screen.fill("chartreuse4") - #pygame.draw.circle(screen, "gray57", player_pos, 40) + easy_map.draw(screen) keys = pygame.key.get_pressed() if keys[pygame.K_w]: - player_pos.y -= 300 * dt + easy_map.cam_y -= camera_step if keys[pygame.K_s]: - player_pos.y += 300 * dt + easy_map.cam_y += camera_step if keys[pygame.K_a]: - player_pos.x -= 300 * dt + easy_map.cam_x -= camera_step if keys[pygame.K_d]: - player_pos.x += 300 * dt + easy_map.cam_x += camera_step + if keys[pygame.K_q]: + easy_map.scale += scale_step + if keys[pygame.K_e]: + easy_map.scale -= scale_step # flip() the display to put your work on screen + #pygame.time.wait(20) pygame.display.flip() # limits FPS to 60 @@ -94,4 +109,5 @@ class Engine: # independent physics. dt = clock.tick(60) / 1000 + pygame.quit() \ No newline at end of file diff --git a/main.py b/main.py index 47b345d..b5846a4 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,13 @@ import eb_engine def main(): - e = eb_engine.Engine(1280, 720) + e = eb_engine.Engine(1600, 900) e.main_loop() if __name__ == "__main__": # pydantic instead of dataclasses? - # Отрисовка голой сетки, прокрутка - # Отрисовка спрайтов, масштаб + # Отрисовка голой сетки, прокрутка, масштаб + + # Отрисовка спрайтов # Начало гуя - кнопка, строка ввода, клик # Поиск пути # Редактор карты