slop-commit. check out all code, test and take a look at notes in main, need to clean up it
This commit is contained in:
@@ -36,12 +36,55 @@ class Creature(Object):
|
||||
tasks: list = field(default_factory = list)
|
||||
inventory: dict = field(default_factory = dict)
|
||||
|
||||
def update(self):
|
||||
pass
|
||||
move_progress: float = 0.0 # 0.0 = старт клетки, 1.0 = конец клетки
|
||||
current_target: tuple = None # (row, col) следующая клетка
|
||||
move_speed: float = 0.02 # пикселей/кадр (настройте)
|
||||
render_offset: tuple = (0.0, 0.0)
|
||||
start_pos: tuple = None # (row, col) начальная позиция сегмента пути
|
||||
|
||||
|
||||
def move(self, cells, start, goal):
|
||||
from common import find_way
|
||||
self.waypoints = find_way(cells, start, goal)
|
||||
self.start_pos = start
|
||||
path = find_way(cells, start, goal)
|
||||
if path and len(path) > 1:
|
||||
self.waypoints = path[1:] # Убираем текущую позицию
|
||||
self.current_target = self.waypoints[0]
|
||||
self.move_progress = 0.0
|
||||
self.start_pos = start # ★ ТУТ - текущая позиция как стартовая для первого шага ★
|
||||
self.render_offset = (0.0, 0.0)
|
||||
|
||||
|
||||
def update(self, time_delta, cell_size, map_obj):
|
||||
if self.current_target is None or not self.waypoints:
|
||||
self.render_offset = (0.0, 0.0)
|
||||
return
|
||||
|
||||
self.move_progress += self.move_speed * time_delta * 60
|
||||
self.move_progress = min(self.move_progress, 1.0)
|
||||
|
||||
if self.move_progress >= 1.0:
|
||||
map_obj.move_obj('creature_obj', self.start_pos, self.current_target)
|
||||
|
||||
self.waypoints.pop(0)
|
||||
if self.waypoints:
|
||||
self.start_pos = self.current_target # Новая клетка как старт
|
||||
self.current_target = self.waypoints[0]
|
||||
self.move_progress = 0.0
|
||||
self.render_offset = (0.0, 0.0) # ← ДОБАВИТЬ!
|
||||
else:
|
||||
self.current_target = None
|
||||
self.render_offset = (0.0, 0.0)
|
||||
return
|
||||
|
||||
# ★ ТОЛЬКО интерполяция offset ★
|
||||
start_row, start_col = self.start_pos or (0, 0)
|
||||
target_row, target_col = self.current_target
|
||||
offset_x = (target_col - start_col) * cell_size * self.move_progress
|
||||
offset_y = (target_row - start_row) * cell_size * self.move_progress
|
||||
self.render_offset = (offset_x, offset_y)
|
||||
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
Reference in New Issue
Block a user