move_obj func was added to Map class. Also console now can execute any command with exec.

This commit is contained in:
shiva404
2026-02-19 19:55:07 +03:00
parent bf4a80a54a
commit 197469350d
8 changed files with 46 additions and 11 deletions

View File

@@ -8,7 +8,8 @@ import eb_creature_objects
import gc, psutil, os
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__))
sprites_dir = os.path.join(main_dir, "res", "sprites")
@@ -40,6 +41,8 @@ class Map:
cam_y: int = 0
cell_dist: int = 1
#action_time_multiplier
def __post_init__(self):
self.cells = {}
with open(self.name, 'r') as file:
@@ -57,6 +60,23 @@ class Map:
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):
for j in range(len(self.cells)):
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:
user_text = input_entry.get_text()
#print(user_text)
exec(user_text)
if user_text.strip():
output_log += f">>> {user_text}\n"
output_box.set_text(output_log)
input_entry.set_text("")
user_text = ""
console_active = False
console_active = bool(input_entry.get_text().strip())
@@ -244,7 +265,6 @@ class Engine:
easy_map.draw_map(self.screen, current_frame + 1)
manager.draw_ui(self.screen)
#print(easy_map.cells[0][0].item_obj.sprite_cache)
if not console_active:
keys = pygame.key.get_pressed()
@@ -278,6 +298,6 @@ class Engine:
if global_counter % 10 == 0:
current_fps = clock.get_fps()
print(f"Current FPS: {current_fps:.2f}")
#print(f"Current FPS: {current_fps:.2f}")
pygame.quit()