Public Access
Pong: a paddle steered by tilting
The player's move goes from -1 to 1 instead of three steps, and two rules make it from the device's tilt: where the paddle is asked to be (it rolls to the low side, about 15 degrees for the whole height) and how to get there without overshooting. Host-tested. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0162FokPdvY2KsS4NBfwyWPk
This commit is contained in:
@@ -121,6 +121,25 @@ void test_pong_the_device_can_be_beaten() {
|
||||
TEST_ASSERT_TRUE(playerPoints > 0);
|
||||
}
|
||||
|
||||
void test_pong_a_tilt_puts_the_paddle_where_it_points() {
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.01, Pong::kHeight / 2, tiltTarget(0.3f, 0.3f)); // held as at the start: the middle
|
||||
TEST_ASSERT_TRUE(tiltTarget(0.2f, 0.3f) < Pong::kHeight / 2); // top lowered: up
|
||||
TEST_ASSERT_TRUE(tiltTarget(0.4f, 0.3f) > Pong::kHeight / 2);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.01, Pong::kPaddleH / 2, tiltTarget(-0.9f, 0.3f)); // and no further than the edge
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.01, Pong::kHeight - Pong::kPaddleH / 2, tiltTarget(0.9f, 0.3f));
|
||||
TEST_ASSERT_EQUAL_FLOAT(1, moveToward(20, 80));
|
||||
TEST_ASSERT_EQUAL_FLOAT(-1, moveToward(80, 20));
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.01, 0.5f, moveToward(60, 65));
|
||||
TEST_ASSERT_EQUAL_FLOAT(0, moveToward(60, 60));
|
||||
}
|
||||
|
||||
void test_pong_a_tilted_paddle_settles_on_its_target() {
|
||||
Pong p(3);
|
||||
float target = tiltTarget(0.4f, 0.3f);
|
||||
for (int i = 0; i < 200; i++) p.step(0.01f, moveToward(p.playerY(), target));
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.5, target, p.playerY());
|
||||
}
|
||||
|
||||
void test_pong_the_device_paddle_has_a_top_speed() {
|
||||
Pong p(13);
|
||||
float before = p.deviceY();
|
||||
@@ -658,6 +677,8 @@ int main() {
|
||||
RUN_TEST(test_pong_a_miss_is_a_point_for_the_other_side);
|
||||
RUN_TEST(test_pong_ends_at_seven);
|
||||
RUN_TEST(test_pong_the_device_can_be_beaten);
|
||||
RUN_TEST(test_pong_a_tilt_puts_the_paddle_where_it_points);
|
||||
RUN_TEST(test_pong_a_tilted_paddle_settles_on_its_target);
|
||||
RUN_TEST(test_pong_the_device_paddle_has_a_top_speed);
|
||||
RUN_TEST(test_snake_starts_in_the_middle_three_long);
|
||||
RUN_TEST(test_snake_moves_at_its_pace);
|
||||
|
||||
Reference in New Issue
Block a user