commit d7184ddab154b110f4c73d7752eb85b68291ed04 Author: shiva404 Date: Fri Feb 13 23:34:24 2026 +0300 hlwrld1 diff --git a/__pycache__/common.cpython-314.pyc b/__pycache__/common.cpython-314.pyc new file mode 100644 index 0000000..c46cf7e Binary files /dev/null and b/__pycache__/common.cpython-314.pyc differ diff --git a/__pycache__/eb_creatures.cpython-314.pyc b/__pycache__/eb_creatures.cpython-314.pyc new file mode 100644 index 0000000..dbddfa4 Binary files /dev/null and b/__pycache__/eb_creatures.cpython-314.pyc differ diff --git a/__pycache__/eb_engine.cpython-314.pyc b/__pycache__/eb_engine.cpython-314.pyc new file mode 100644 index 0000000..b004bc4 Binary files /dev/null and b/__pycache__/eb_engine.cpython-314.pyc differ diff --git a/__pycache__/eb_objects.cpython-314.pyc b/__pycache__/eb_objects.cpython-314.pyc new file mode 100644 index 0000000..de8cb94 Binary files /dev/null and b/__pycache__/eb_objects.cpython-314.pyc differ diff --git a/__pycache__/eb_terrain.cpython-314.pyc b/__pycache__/eb_terrain.cpython-314.pyc new file mode 100644 index 0000000..41fa81b Binary files /dev/null and b/__pycache__/eb_terrain.cpython-314.pyc differ diff --git a/__pycache__/objects.cpython-314.pyc b/__pycache__/objects.cpython-314.pyc new file mode 100644 index 0000000..0123d60 Binary files /dev/null and b/__pycache__/objects.cpython-314.pyc differ diff --git a/common.py b/common.py new file mode 100644 index 0000000..a71beb8 --- /dev/null +++ b/common.py @@ -0,0 +1,5 @@ +import json +import uuid +from dataclasses import dataclass, field +from copy import deepcopy +import pygame \ No newline at end of file diff --git a/def_map.json b/def_map.json new file mode 100644 index 0000000..7846886 --- /dev/null +++ b/def_map.json @@ -0,0 +1,978 @@ +{ + "0": [ + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + } + ], + "1": [ + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + } + ], + "2": [ + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + } + ], + "3": [ + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + } + ], + "4": [ + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + } + ], + "5": [ + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + } + ], + "6": [ + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + } + ], + "7": [ + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + }, + { + "type": "Ground", + "cell": { + "terrain_obj": { + "id": "1", + "name": "2", + "sprite": "grass_small.png" + }, + "creature_obj": {}, + "item_obj": {} + } + } + ] +} \ No newline at end of file diff --git a/eb_creatures.py b/eb_creatures.py new file mode 100644 index 0000000..cd5e4c5 --- /dev/null +++ b/eb_creatures.py @@ -0,0 +1,10 @@ +from common import dataclass +import eb_objects + +@dataclass +class Unit(eb_objects.Creature): + pass + +@dataclass +class Monster(eb_objects.Creature): + pass \ No newline at end of file diff --git a/eb_engine.py b/eb_engine.py new file mode 100644 index 0000000..c705e22 --- /dev/null +++ b/eb_engine.py @@ -0,0 +1,97 @@ +from common import pygame, json, uuid, deepcopy, dataclass, field +import eb_objects +import eb_terrain +import eb_creatures + +cell_classes = {"Ground": eb_terrain.Ground} + +@dataclass +class Cell: + terrain_obj: any + #item_obj: any + #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) + +class Map: + def __init__(self, name, cell_color = "gray57", active_cell_color = "gray57"): + self.name = name + 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 + + +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): + + ''' + #o = eb_terrain.Ground(1, 1, 1) + #c = eb_creatures.Unit(1, 1, 1) + #print(isinstance(o, eb_objects.Object)) + #print(isinstance(o, eb_objects.Terrain)) + #print(isinstance(c, eb_objects.Terrain)) + ''' + + easy_map = Map("def_map.json", "gray57") + print(1) + + # pygame setup + pygame.init() + screen = pygame.display.set_mode((self.width, self.height)) + clock = pygame.time.Clock() + running = True + dt = 0 + + player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2) + + while running: + # poll for events + # pygame.QUIT event means the user clicked X to close your window + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + # fill the screen with a color to wipe away anything from last frame + screen.fill("chartreuse4") + + #pygame.draw.circle(screen, "gray57", player_pos, 40) + + keys = pygame.key.get_pressed() + if keys[pygame.K_w]: + player_pos.y -= 300 * dt + if keys[pygame.K_s]: + player_pos.y += 300 * dt + if keys[pygame.K_a]: + player_pos.x -= 300 * dt + if keys[pygame.K_d]: + player_pos.x += 300 * dt + + # flip() the display to put your work on screen + pygame.display.flip() + + # limits FPS to 60 + # dt is delta time in seconds since last frame, used for framerate- + # independent physics. + dt = clock.tick(60) / 1000 + + pygame.quit() \ No newline at end of file diff --git a/eb_objects.py b/eb_objects.py new file mode 100644 index 0000000..56025f8 --- /dev/null +++ b/eb_objects.py @@ -0,0 +1,23 @@ +from common import dataclass + +@dataclass +class Object: + id: str + name: str + sprite: str + +@dataclass +class Terrain(Object): + pass + +@dataclass +class Creature(Object): + pass + +@dataclass +class Item(Object): + pass + +@dataclass +class Building(Object): + pass \ No newline at end of file diff --git a/eb_terrain.py b/eb_terrain.py new file mode 100644 index 0000000..6d37d2a --- /dev/null +++ b/eb_terrain.py @@ -0,0 +1,14 @@ +from common import dataclass +import eb_objects + +@dataclass +class Ground(eb_objects.Terrain): + pass + +@dataclass +class Water(eb_objects.Terrain): + pass + +@dataclass +class Rock(eb_objects.Terrain): + pass \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..47b345d --- /dev/null +++ b/main.py @@ -0,0 +1,18 @@ +import eb_engine + +def main(): + e = eb_engine.Engine(1280, 720) + e.main_loop() + +if __name__ == "__main__": + # pydantic instead of dataclasses? + # Отрисовка голой сетки, прокрутка + # Отрисовка спрайтов, масштаб + # Начало гуя - кнопка, строка ввода, клик + # Поиск пути + # Редактор карты + # Охотник - деревня + # Простой, но основательный гуй внизу экрана, глобальная карта и перемещение + # деревня на соседской локации и торговля с ней + # перемещение по воде, течение + main() \ No newline at end of file diff --git a/res/maps/map_editor.py b/res/maps/map_editor.py new file mode 100644 index 0000000..4baf62b --- /dev/null +++ b/res/maps/map_editor.py @@ -0,0 +1,19 @@ +import json +from copy import deepcopy + +width = 10 +height = 8 + +grass_def = {"id": "1", "name": "2", "sprite": "grass_small.png"} +cell_def = {"type": "Ground", "cell": {"terrain_obj": grass_def, "creature_obj": {}, "item_obj": {}}} + +out = {} + +for i in range(0, height): + buff = [] + for j in range(0, width): + buff.append(deepcopy(cell_def)) + out[i] = buff + +with open("def_map.json", "w") as file: + json.dump(out, file, indent = 4) \ No newline at end of file diff --git a/res/sprites/elf_left.png b/res/sprites/elf_left.png new file mode 100644 index 0000000..f636705 Binary files /dev/null and b/res/sprites/elf_left.png differ diff --git a/res/sprites/elf_right.png b/res/sprites/elf_right.png new file mode 100644 index 0000000..6667a19 Binary files /dev/null and b/res/sprites/elf_right.png differ diff --git a/res/sprites/grass.jpg b/res/sprites/grass.jpg new file mode 100644 index 0000000..f82cd98 Binary files /dev/null and b/res/sprites/grass.jpg differ diff --git a/res/sprites/grasss_small.jpg b/res/sprites/grasss_small.jpg new file mode 100644 index 0000000..e464a1f Binary files /dev/null and b/res/sprites/grasss_small.jpg differ