class_name Avatar extends Node2D ## The local player's figure. It moves outside the lockstep simulation; only ## its pickaxe hits become commands. ## Walking speed: five tiles per second. const SPEED := 5.0 * GridMotion.TILE_SIZE const RADIUS := 5.0 ## Longest frame that moves the figure in one go. Longer frames are cut, so ## that the figure cannot pass through a wall after a stall. const MAX_STEP_SECONDS := 0.1 ## Callable(x: int, y: int) -> bool that says whether a tile can be walked on. var is_walkable: Callable func _process(delta: float) -> void: walk(Input.get_vector("move_left", "move_right", "move_up", "move_down"), delta) ## Moves the figure in `direction` for `delta` seconds, sliding along walls. func walk(direction: Vector2, delta: float) -> void: if direction == Vector2.ZERO or not is_walkable.is_valid(): return var motion := direction * SPEED * minf(delta, MAX_STEP_SECONDS) position = GridMotion.move(position, motion, RADIUS, is_walkable) func _draw() -> void: draw_circle(Vector2.ZERO, RADIUS + 1.0, Color(0.15, 0.1, 0.05)) draw_circle(Vector2.ZERO, RADIUS, Color(0.95, 0.85, 0.6))