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>
34 lines
1.1 KiB
GDScript
34 lines
1.1 KiB
GDScript
extends TestCase
|
|
|
|
|
|
func _open_field(x: int, y: int) -> bool:
|
|
return x >= 0 and y >= 0 and x < 100 and y < 100
|
|
|
|
|
|
func test_the_figure_walks_five_tiles_per_second() -> void:
|
|
var avatar := Avatar.new()
|
|
avatar.is_walkable = _open_field
|
|
avatar.position = GridMotion.tile_center(Vector2i(50, 50))
|
|
var start := avatar.position
|
|
for frame in 10:
|
|
avatar.walk(Vector2.RIGHT, 0.1)
|
|
check(is_equal_approx(avatar.position.x - start.x, 5.0 * GridMotion.TILE_SIZE), "five tiles in one second, moved %s" % (avatar.position.x - start.x))
|
|
avatar.free()
|
|
|
|
|
|
func test_a_long_frame_moves_the_figure_no_further_than_a_tenth_of_a_second() -> void:
|
|
var avatar := Avatar.new()
|
|
avatar.is_walkable = _open_field
|
|
avatar.position = GridMotion.tile_center(Vector2i(50, 50))
|
|
var start := avatar.position
|
|
avatar.walk(Vector2.DOWN, 3.0)
|
|
check(is_equal_approx(avatar.position.y - start.y, Avatar.SPEED * Avatar.MAX_STEP_SECONDS), "cut to a tenth of a second")
|
|
avatar.free()
|
|
|
|
|
|
func test_without_a_map_the_figure_stays() -> void:
|
|
var avatar := Avatar.new()
|
|
avatar.walk(Vector2.LEFT, 0.1)
|
|
check_eq(avatar.position, Vector2.ZERO, "no walkability callable")
|
|
avatar.free()
|