Diagonal pathfinding and moving works great! Fixed teleport bug and terrain overlay.

This commit is contained in:
shiva404
2026-02-20 04:53:33 +03:00
parent 7fbc1b38c2
commit 2b114ddd2d
7 changed files with 199 additions and 37 deletions

View File

@@ -114,13 +114,13 @@ class Map:
def draw_map(self, screen, current_frame, grid=True):
terrain_list = []
creature_list = []
# ★ 1 ПАСС: собираем terrain и creatures ★
for j in range(len(self.cells)):
for i, cell in enumerate(self.cells[j]):
base_x = i * self.cell_size + self.cam_x
base_y = j * self.cell_size + self.cam_y
# Terrain данные
terrain_dd = {
"x": int(base_x * self.scale), "y": int(base_y * self.scale),
@@ -130,7 +130,7 @@ class Map:
"sprites": self.sprites, "scale": self.scale, "screen": screen
}
terrain_list.append((cell.terrain_obj, terrain_dd))
# Creature данные (если есть)
if cell.creature_obj:
offset_x, offset_y = cell.creature_obj.render_offset
@@ -138,15 +138,15 @@ class Map:
creature_dd["x"] = int((base_x + offset_x) * self.scale)
creature_dd["y"] = int((base_y + offset_y) * self.scale)
creature_list.append((cell.creature_obj, creature_dd))
# ★ 2 ПАСС: рисуем terrain ★
for obj, dd in terrain_list:
obj.draw(dd)
# ★ 3 ПАСС: рисуем ВСЕХ creatures ПОСЛЕ terrain ★
for obj, dd in creature_list:
obj.draw(dd)
# ★ 4 ПАСС: grid поверх всего ★
for j in range(len(self.cells)):
for i, cell in enumerate(self.cells[j]):
@@ -383,7 +383,7 @@ class Engine:
easy_map.cells[active_cell[0]][active_cell[1]].creature_obj is not None):
cell_coords = easy_map.get_cell_at_mouse(mouse_pos)
if cell_coords:
print(f"Движение: {active_cell} -> {cell_coords}")
#print(f"Движение: {active_cell} -> {cell_coords}")
easy_map.cells[active_cell[0]][active_cell[1]].creature_obj.move(
easy_map.cells, active_cell, cell_coords)
@@ -401,6 +401,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()