Esempio n. 1
0
def test_update__SAS():
    sut = set_up_sluggish_player()

    # start turning
    sut.key_handler.on_key_press(key.RIGHT, None)

    sut.update(1.0)  # one 60 fps frame

    sut.key_handler.on_key_release(key.RIGHT, None)

    assert sut.rotation_speed == 15.0
    assert eq_within_epsilon(sut.rotation, 7.5)

    # engage SAS
    sut.key_handler.on_key_press(key.DOWN, None)

    sut.update(0.5)  # stabilize for half a second

    assert sut.rotation_speed == 7.5
    assert eq_within_epsilon(sut.rotation, 13.12)

    sut.key_handler.on_key_release(key.DOWN, None)

    sut.update(0.5)  # drift for half a second

    assert sut.rotation_speed == 7.5
    assert eq_within_epsilon(sut.rotation, 16.87)

    sut.key_handler.on_key_press(key.DOWN, None)

    sut.update(1.0)  # stabilize for a full second

    assert sut.rotation_speed == 0.0
    assert eq_within_epsilon(sut.rotation, 20.62)
Esempio n. 2
0
def test_update__turn_left():
    sut = set_up_sluggish_player()

    # turn left
    sut.key_handler.on_key_press(key.LEFT, None)

    sut.update(fps_to_s(60) * 1.5)

    assert sut.rotation_speed == -0.375
    assert eq_within_epsilon(sut.rotation, 359.9953, 0.0001)

    sut.update(fps_to_s(60) * 58.5)  # finish this second

    sut.key_handler.on_key_release(key.LEFT, None)

    assert sut.rotation_speed == -15
    assert eq_within_epsilon(sut.rotation, 352.5)

    sut.update(1.0)  # one second

    assert sut.rotation_speed == -15
    assert eq_within_epsilon(sut.rotation, 337.5)
Esempio n. 3
0
def test_update__turn_right():
    sut = set_up_sluggish_player()

    # turn right
    sut.key_handler.on_key_press(key.RIGHT, None)

    sut.update(fps_to_s(60))  # one 60 fps frame

    assert sut.rotation_speed == 0.25
    assert eq_within_epsilon(sut.rotation, 0.0021, 0.0001)

    sut.update(fps_to_s(60) * 59)  # finish this second

    sut.key_handler.on_key_release(key.RIGHT, None)

    assert sut.rotation_speed == 15.0
    assert eq_within_epsilon(sut.rotation, 7.5)

    sut.update(1.0)  # one second

    assert sut.rotation_speed == 15.0
    assert eq_within_epsilon(sut.rotation, 22.5)
Esempio n. 4
0
def test_update__thrust():
    sut = set_up_sluggish_player()

    # artificially set rotation
    sut.rotation = 45.0

    assert sut.velocity_x == 0.0
    assert sut.velocity_y == 0.0
    assert sut.x == 200.0
    assert sut.y == 300.0

    # engage thrust
    sut.key_handler.on_key_press(key.UP, None)
    sut.update(1.0)

    assert eq_within_epsilon(sut.velocity_x, 7.08)
    assert eq_within_epsilon(sut.velocity_y, 7.08)
    assert eq_within_epsilon(sut.x, 203.54)
    assert eq_within_epsilon(sut.y, 303.54)

    # stop thrust and drift
    sut.key_handler.on_key_release(key.UP, None)
    sut.update(2.0)

    assert eq_within_epsilon(sut.velocity_x, 7.08)
    assert eq_within_epsilon(sut.velocity_y, 7.08)
    assert eq_within_epsilon(sut.x, 217.68)
    assert eq_within_epsilon(sut.y, 317.68)

    # stop altogether
    sut.rotation += 180.0
    sut.key_handler.on_key_press(key.UP, None)
    sut.update(1.0)

    assert eq_within_epsilon(sut.velocity_x, 0.0)
    assert eq_within_epsilon(sut.velocity_y, 0.0)
    assert eq_within_epsilon(sut.x, 221.22)
    assert eq_within_epsilon(sut.y, 321.22)