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() func test_a_walking_figure_steps_and_faces_the_way_it_goes() -> void: var avatar := Avatar.new() avatar.is_walkable = _open_field avatar.position = GridMotion.tile_center(Vector2i(50, 50)) check(not avatar.moving, "standing at first") avatar.walk(Vector2.LEFT, 0.1) check(avatar.moving, "walking") check_eq(avatar.facing, -1.0, "facing left") check(avatar.step > 0.0, "the step turns") avatar.walk(Vector2.UP, 0.1) check_eq(avatar.facing, -1.0, "walking up keeps the way it faces") avatar.walk(Vector2.ZERO, 0.1) check(not avatar.moving, "standing again") avatar.free() func test_a_figure_stands_upright_in_its_tile() -> void: var rect := Avatar.figure_rect(Vector2(100, 100)) check_eq(rect.size, Vector2(GridMotion.TILE_SIZE, GridMotion.TILE_SIZE * 1.5), "a tile wide, one and a half tall") check_eq(rect.get_center().x, 100.0, "centred on the figure") check_eq(rect.end.y, 100.0 + Avatar.RADIUS + 1.0, "its feet just below its body")