move some logics to loop()

This commit is contained in:
andrea
2026-03-18 18:12:38 +01:00
parent 48c2610561
commit 48fef4be86
3 changed files with 17 additions and 19 deletions

View File

@@ -23,7 +23,7 @@ void Engine::_print_score() {
Serial.println();
}
void Engine::run(uint8_t &ball_delay) {
void Engine::run() {
_event= NONE;
_ball.move();
uint8_t bx= _ball.get_x();
@@ -33,15 +33,12 @@ void Engine::run(uint8_t &ball_delay) {
if (!this -> _check_pad_ball_collision(_p1)) {
// p2 scores
_p2.increase_score();
_ball.reset_position(); // XXX this is probably too early i reset the position before render
ball_delay= INITIAL_BALL_DELAY;
Serial.println("Player 2 Scores");
this -> _print_score();
_event= P2SCORE;
return;
}
else {
_hits += 1;
_ball.bounce_on_pad();
_event= P2_COLLISION;
}
@@ -50,15 +47,12 @@ void Engine::run(uint8_t &ball_delay) {
if (!this -> _check_pad_ball_collision(_p2)) {
// p1 scores
_p1.increase_score();
_ball.reset_position(); // XXX this is probably too early i reset the position before render
ball_delay= INITIAL_BALL_DELAY;
Serial.println("Player 1 Scores");
this -> _print_score();
_event= P1SCORE;
return;
}
else {
_hits += 1;
_ball.bounce_on_pad();
_event= P1_COLLISION;
}
@@ -68,13 +62,6 @@ void Engine::run(uint8_t &ball_delay) {
_ball.bounce_on_sides();
_event= WALL_COLLISION;
}
// increase ball speed every 6 hits on pads
// if ball is not at max speed
if (_hits >= 6 && ball_delay >= 80) {
_hits= 0;
ball_delay-= 20; // XXX handle it on loop()
}
}
EngineEvents Engine::get_event() {

View File

@@ -14,7 +14,6 @@ class Engine {
Paddle& _p1;
Paddle& _p2;
Ball& _ball;
uint8_t _hits;
EngineEvents _event= NONE;
bool _check_pad_ball_collision(Paddle &p);
@@ -25,7 +24,7 @@ class Engine {
Engine(Paddle &p_one, Paddle &p_two, Ball &ball)
: _p1(p_one), _p2(p_two), _ball(ball) {}
void run(uint8_t &ball_delay);
void run();
EngineEvents get_event();
void reset();
};