2607df8a97
TickClock rechnet Bildzeit in Takte um und holt nach einem Ruckler höchstens fünf Takte auf. GridMotion bewegt einen Körper über das Kachelraster und lässt ihn an Wänden entlanggleiten. Die Figur läuft fünf Felder pro Sekunde, außerhalb des Gleichschritts. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
32 lines
1.1 KiB
GDScript
32 lines
1.1 KiB
GDScript
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))
|