From 4bb6d6d6ee993a59124907cd24a23f65672bf8dc Mon Sep 17 00:00:00 2001 From: andrea Date: Thu, 19 Mar 2026 22:23:29 +0100 Subject: [PATCH] start thinking about MENU status --- arduino_pong.ino | 14 +++++++++++--- src/engine.cpp | 22 +++------------------- src/engine.h | 2 +- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/arduino_pong.ino b/arduino_pong.ino index 84d469c..be3f904 100644 --- a/arduino_pong.ino +++ b/arduino_pong.ino @@ -26,6 +26,7 @@ uint8_t hits= 0; long exec_t2= millis(); enum game_statuses : uint8_t { + MENU, TIMER, RUN, SCORE, @@ -38,7 +39,7 @@ Ball ball(4, 6); // HumanPaddle p1(1, P1_BTN_UP, P1_BTN_BOTTOM); // HumanPaddle p2(4, P2_BTN_UP, P2_BTN_BOTTOM); BotPaddle p1(1, 0, 2); -BotPaddle p2(4, MATRIX_WIDTH-1, 2); +BotPaddle p2(4, MATRIX_WIDTH-1, 1); Engine engine(p1, p2, ball, INITIAL_BALL_DELAY); Renderer renderer(p1, p2, ball, frame, matrix); @@ -60,6 +61,14 @@ void loop() { switch (game_status) { + case MENU: + // show menu on the matrix + // 1. P vs P + // 2. P vs CPU + // 3. CPU vs CPU + // slideshow menu + break; + case TIMER: for (int i = START_TIMER; i >= 0; i--) { renderer.render_timer(i); @@ -71,8 +80,7 @@ void loop() { break; case RUN: - // need_refresh= check_paddle_movements(p1, p2); - need_refresh= engine.control_players(exec_t2); + need_refresh= engine.control_players(); if (exec_t1 - exec_t2 > engine.ball_movement_delay()) { engine.run(); diff --git a/src/engine.cpp b/src/engine.cpp index aaa1252..19250e9 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -60,29 +60,13 @@ void Engine::run() { } } -bool Engine::control_players(long exec_t2) { +bool Engine::control_players() { bool need_refresh= false; if (_p1.is_human()) need_refresh |= _p1.check_pad_movement(); - else { - uint8_t ball_delay= this -> ball_movement_delay(); - long exec_t1= millis(); - uint8_t skill= _p1.get_skills(); - - if (exec_t1 - exec_t2 > ball_delay - (skill * 10)) { - need_refresh |= _p1.check_pad_movement(_ball); - } - } + else need_refresh |= _p1.check_pad_movement(); if (_p2.is_human()) need_refresh |= _p2.check_pad_movement(); - else { - uint8_t ball_delay= this -> ball_movement_delay(); - long exec_t1= millis(); - uint8_t skill= _p1.get_skills(); - - if (exec_t1 - exec_t2 > ball_delay - (skill * 10)) { - need_refresh |= _p2.check_pad_movement(_ball); - } - } + else need_refresh |= _p2.check_pad_movement(); return need_refresh; } diff --git a/src/engine.h b/src/engine.h index 0eec6d6..5f453c8 100644 --- a/src/engine.h +++ b/src/engine.h @@ -26,7 +26,7 @@ class Engine { : _p1(p_one), _p2(p_two), _ball(ball), _ball_mv_delay(ball_mv_delay) {} void run(); - bool control_players(long exec_t2); + bool control_players(); uint8_t ball_movement_delay(); EngineEvents get_event(); void restart_ball();