move_obj func was added to Map class. Also console now can execute any command with exec.
This commit is contained in:
Binary file not shown.
Binary file not shown.
28
eb_engine.py
28
eb_engine.py
@@ -8,7 +8,8 @@ import eb_creature_objects
|
|||||||
import gc, psutil, os
|
import gc, psutil, os
|
||||||
|
|
||||||
cell_classes = {"grass_small": eb_terrain_objects.Ground,
|
cell_classes = {"grass_small": eb_terrain_objects.Ground,
|
||||||
"sword_default": eb_objects.Item, "elf_watching": eb_creature_objects.Unit}
|
"sword_default": eb_objects.Item, "elf_watching": eb_creature_objects.Unit,
|
||||||
|
"rock_small": eb_terrain_objects.Rock}
|
||||||
|
|
||||||
main_dir = os.path.dirname(os.path.abspath(__file__))
|
main_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
sprites_dir = os.path.join(main_dir, "res", "sprites")
|
sprites_dir = os.path.join(main_dir, "res", "sprites")
|
||||||
@@ -40,6 +41,8 @@ class Map:
|
|||||||
cam_y: int = 0
|
cam_y: int = 0
|
||||||
cell_dist: int = 1
|
cell_dist: int = 1
|
||||||
|
|
||||||
|
#action_time_multiplier
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
self.cells = {}
|
self.cells = {}
|
||||||
with open(self.name, 'r') as file:
|
with open(self.name, 'r') as file:
|
||||||
@@ -57,6 +60,23 @@ class Map:
|
|||||||
|
|
||||||
self.cells[line].append(final_cell)
|
self.cells[line].append(final_cell)
|
||||||
|
|
||||||
|
def move_obj(self, type, s_x, s_y, d_x, d_y):
|
||||||
|
if d_y >= len(self.cells) or d_x >= len(self.cells[s_y]) or s_y >= len(self.cells) or s_x >= len(self.cells[s_y]):
|
||||||
|
return False
|
||||||
|
source_cell = self.cells[s_y][s_x]
|
||||||
|
dest_cell = self.cells[d_y][d_x]
|
||||||
|
obj = getattr(source_cell, type)
|
||||||
|
|
||||||
|
if obj is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
setattr(source_cell, type, None)
|
||||||
|
setattr(dest_cell, type, obj)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def get_way(self, s_x, s_y, d_x, d_y):
|
||||||
|
pass
|
||||||
|
|
||||||
def draw_map(self, screen, current_frame, grid = True):
|
def draw_map(self, screen, current_frame, grid = True):
|
||||||
for j in range(len(self.cells)):
|
for j in range(len(self.cells)):
|
||||||
for i, cell in enumerate(self.cells[j]):
|
for i, cell in enumerate(self.cells[j]):
|
||||||
@@ -212,11 +232,12 @@ class Engine:
|
|||||||
|
|
||||||
if event.type == pygame_gui.UI_TEXT_ENTRY_FINISHED and event.ui_element == input_entry:
|
if event.type == pygame_gui.UI_TEXT_ENTRY_FINISHED and event.ui_element == input_entry:
|
||||||
user_text = input_entry.get_text()
|
user_text = input_entry.get_text()
|
||||||
#print(user_text)
|
exec(user_text)
|
||||||
if user_text.strip():
|
if user_text.strip():
|
||||||
output_log += f">>> {user_text}\n"
|
output_log += f">>> {user_text}\n"
|
||||||
output_box.set_text(output_log)
|
output_box.set_text(output_log)
|
||||||
input_entry.set_text("")
|
input_entry.set_text("")
|
||||||
|
user_text = ""
|
||||||
console_active = False
|
console_active = False
|
||||||
|
|
||||||
console_active = bool(input_entry.get_text().strip())
|
console_active = bool(input_entry.get_text().strip())
|
||||||
@@ -244,7 +265,6 @@ class Engine:
|
|||||||
|
|
||||||
easy_map.draw_map(self.screen, current_frame + 1)
|
easy_map.draw_map(self.screen, current_frame + 1)
|
||||||
manager.draw_ui(self.screen)
|
manager.draw_ui(self.screen)
|
||||||
#print(easy_map.cells[0][0].item_obj.sprite_cache)
|
|
||||||
|
|
||||||
if not console_active:
|
if not console_active:
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
@@ -278,6 +298,6 @@ class Engine:
|
|||||||
|
|
||||||
if global_counter % 10 == 0:
|
if global_counter % 10 == 0:
|
||||||
current_fps = clock.get_fps()
|
current_fps = clock.get_fps()
|
||||||
print(f"Current FPS: {current_fps:.2f}")
|
#print(f"Current FPS: {current_fps:.2f}")
|
||||||
|
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
@@ -7,6 +7,9 @@ class Object:
|
|||||||
sprite_name: str
|
sprite_name: str
|
||||||
sprite_state: int = 0
|
sprite_state: int = 0
|
||||||
|
|
||||||
|
# weight
|
||||||
|
# effects = {}
|
||||||
|
|
||||||
def draw(self, draw_data):
|
def draw(self, draw_data):
|
||||||
if draw_data["spr_up"] == 0:
|
if draw_data["spr_up"] == 0:
|
||||||
if self.sprite_state == len(draw_data["sprites"][self.sprite_name]) - 1:
|
if self.sprite_state == len(draw_data["sprites"][self.sprite_name]) - 1:
|
||||||
@@ -18,6 +21,8 @@ class Object:
|
|||||||
rect = sp.get_rect(center = (draw_data["x"] + draw_data["w"] /2, draw_data["y"] + draw_data["h"]/ 2))
|
rect = sp.get_rect(center = (draw_data["x"] + draw_data["w"] /2, draw_data["y"] + draw_data["h"]/ 2))
|
||||||
draw_data["screen"].blit(sp, rect)
|
draw_data["screen"].blit(sp, rect)
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
pass
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Terrain(Object):
|
class Terrain(Object):
|
||||||
@@ -25,16 +30,27 @@ class Terrain(Object):
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Creature(Object):
|
class Creature(Object):
|
||||||
pass
|
current_action: int = 0
|
||||||
#status
|
quick_actions: list = field(default_factory = list)
|
||||||
#actions
|
tasks: list = field(default_factory = list)
|
||||||
#tasks
|
inventory: dict = field(default_factory = dict)
|
||||||
#items
|
|
||||||
|
def update(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Item(Object):
|
class Item(Object):
|
||||||
|
# passive_abilities = {}
|
||||||
|
# active_abilities = {}
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Container(Item):
|
||||||
|
# content = {}
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Building(Object):
|
class Building(Object):
|
||||||
pass
|
pass
|
||||||
1
main.py
1
main.py
@@ -29,7 +29,6 @@ if __name__ == "__main__":
|
|||||||
# pydantic instead of dataclasses?
|
# pydantic instead of dataclasses?
|
||||||
# почитать про Surface, Display, доку к pygame-gui
|
# почитать про Surface, Display, доку к pygame-gui
|
||||||
# проверить дефолтдикт field и None = None
|
# проверить дефолтдикт field и None = None
|
||||||
# техдолг - draw_data to dd
|
|
||||||
# изучить pypmler
|
# изучить pypmler
|
||||||
# настроить логирование всего
|
# настроить логирование всего
|
||||||
# SLOP: load_sprites
|
# SLOP: load_sprites
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 68 KiB |
BIN
res/rocks-2.jpg
Normal file
BIN
res/rocks-2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 258 KiB |
BIN
res/sprites/rock_small_1.png
Normal file
BIN
res/sprites/rock_small_1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 62 KiB |
Reference in New Issue
Block a user