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>
47 lines
1.9 KiB
GDScript
47 lines
1.9 KiB
GDScript
extends TestCase
|
|
## A 10 x 10 test grid in which tile (3, 1) and every tile outside are walls.
|
|
|
|
const SIZE := GridMotion.TILE_SIZE
|
|
const RADIUS := 5.0
|
|
|
|
|
|
func _walkable(x: int, y: int) -> bool:
|
|
if x < 0 or y < 0 or x >= 10 or y >= 10:
|
|
return false
|
|
return Vector2i(x, y) != Vector2i(3, 1)
|
|
|
|
|
|
func test_tile_of_and_tile_center_agree() -> void:
|
|
check_eq(GridMotion.tile_of(Vector2(0.0, 0.0)), Vector2i(0, 0), "origin")
|
|
check_eq(GridMotion.tile_of(Vector2(15.9, 16.0)), Vector2i(0, 1), "tile borders")
|
|
check_eq(GridMotion.tile_of(Vector2(-0.1, 3.0)), Vector2i(-1, 0), "left of the map")
|
|
check_eq(GridMotion.tile_center(Vector2i(2, 3)), Vector2(40.0, 56.0), "centre")
|
|
check_eq(GridMotion.tile_of(GridMotion.tile_center(Vector2i(7, 4))), Vector2i(7, 4), "round trip")
|
|
|
|
|
|
func test_free_movement_covers_the_full_distance() -> void:
|
|
var start := GridMotion.tile_center(Vector2i(5, 5))
|
|
var moved := GridMotion.move(start, Vector2(3.0, -2.0), RADIUS, _walkable)
|
|
check_eq(moved, start + Vector2(3.0, -2.0), "unblocked")
|
|
|
|
|
|
func test_a_wall_stops_the_body_before_it() -> void:
|
|
var position := GridMotion.tile_center(Vector2i(1, 1))
|
|
for step in 40:
|
|
position = GridMotion.move(position, Vector2(1.0, 0.0), RADIUS, _walkable)
|
|
check(position.x + RADIUS <= 3.0 * SIZE, "the body stays left of the wall at x = 48, ends at %s" % position.x)
|
|
check(position.x + RADIUS > 3.0 * SIZE - 1.0, "and gets close to it, ends at %s" % position.x)
|
|
|
|
|
|
func test_a_body_slides_along_a_wall() -> void:
|
|
var start := GridMotion.tile_center(Vector2i(2, 1))
|
|
var moved := GridMotion.move(start, Vector2(4.0, 2.0), RADIUS, _walkable)
|
|
check_eq(moved.x, start.x, "the blocked axis stays")
|
|
check_eq(moved.y, start.y + 2.0, "the free axis moves")
|
|
|
|
|
|
func test_the_edge_of_the_map_is_a_wall() -> void:
|
|
var start := Vector2(RADIUS, RADIUS)
|
|
var moved := GridMotion.move(start, Vector2(-1.0, -1.0), RADIUS, _walkable)
|
|
check_eq(moved, start, "no step off the map")
|