This commit is contained in:
shiva404
2026-02-13 23:34:24 +03:00
commit d7184ddab1
18 changed files with 1164 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

5
common.py Normal file
View File

@@ -0,0 +1,5 @@
import json
import uuid
from dataclasses import dataclass, field
from copy import deepcopy
import pygame

978
def_map.json Normal file
View File

@@ -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": {}
}
}
]
}

10
eb_creatures.py Normal file
View File

@@ -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

97
eb_engine.py Normal file
View File

@@ -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()

23
eb_objects.py Normal file
View File

@@ -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

14
eb_terrain.py Normal file
View File

@@ -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

18
main.py Normal file
View File

@@ -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()

19
res/maps/map_editor.py Normal file
View File

@@ -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)

BIN
res/sprites/elf_left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 KiB

BIN
res/sprites/elf_right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 KiB

BIN
res/sprites/grass.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 458 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB