Created
June 28, 2020 00:20
-
-
Save bitwes/4fef7c70d7e02d5aee90f03cfa1e7c74 to your computer and use it in GitHub Desktop.
Example of collision testing using GUT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This tests sets a car object and a checkpoint object (created in before_each) | |
# on a collision path and waits 1 second for the collision to occur. It then | |
# checks a property in the checkpoint to verify the collision happened. | |
func test_crosses_when_target_car_crosses(): | |
gr.checkpoint.set_position(Vector2(500, 0)) | |
var car = _g.r.TargetCarScene.instance() | |
car.set_global_position(Vector2(400, 300)) | |
add_child(car) | |
car.set_speed(200, 0) | |
car.set_z_index(500) | |
yield(yield_for(1), YIELD) | |
car.queue_free() | |
assert_true(gr.checkpoint.is_crossed()) | |
# This tests setups a flying saucer object and an object for it to chase | |
# and then waits for the saucer to emit the "abducted" signal or 10 seconds, | |
# whichever comes first. It then verifies that the signal was emitted. | |
func test_emits_signal_abducted_when_reaches_pos(): | |
gr.saucer.set_position(Vector2(80, 100)) | |
gr.chasee.set_position(Vector2(800, 100)) | |
gr.saucer.set_speed(400) | |
gr.saucer.set_chase_object(gr.chasee) | |
yield(yield_to(gr.saucer, 'abducted', 10), YIELD) | |
assert_signal_emitted(gr.saucer, 'abducted') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment