Improve arduino_pong.ino using enum to handle game statuses and switch case for better readibility and little memory improvements
Some checks failed
Some checks failed
This commit is contained in:
@@ -33,7 +33,7 @@ void point_scored(int &ball_x, int &ball_y, int &ball_delay, int players_scores[
|
||||
ball_delay= INITIAL_BALL_DELAY;
|
||||
}
|
||||
|
||||
bool move_ball(int &ball_x, int &ball_y, int &ball_delay, int players_coords[2], int players_scores[2], int &need_refresh) {
|
||||
bool move_ball(int &ball_x, int &ball_y, int &ball_delay, int players_coords[2], int players_scores[2]) {
|
||||
if (ball_x < 0 || ball_x > MATRIX_WIDTH-1 || ball_y < 0 || ball_y > MATRIX_HEIGHT-1) {
|
||||
// ball out of matrix limits
|
||||
ball_x= BALL_RESET_X;
|
||||
@@ -41,7 +41,6 @@ bool move_ball(int &ball_x, int &ball_y, int &ball_delay, int players_coords[2],
|
||||
return false;
|
||||
}
|
||||
|
||||
need_refresh= 1;
|
||||
bool scored= false;
|
||||
|
||||
// if ball is not moving, get random direction
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifndef PONG_BALL_H
|
||||
#define PONG_BALL_H
|
||||
|
||||
bool move_ball(int &ball_x, int &ball_y, int &loop_delay, int players_coords[2], int players_scores[2], int &need_refresh);
|
||||
|
||||
bool move_ball(int &ball_x, int &ball_y, int &loop_delay, int players_coords[2], int players_scores[2]);
|
||||
void foo();
|
||||
#endif
|
||||
|
||||
@@ -13,21 +13,21 @@ int ball_player_collision(int player, int ball_y) {
|
||||
int pong_move_p1(int &p1_start, int &need_refresh) {
|
||||
if (digitalRead(P1_BTN_UP) == LOW && p1_start > 0) {
|
||||
p1_start -= 1;
|
||||
need_refresh= 1;
|
||||
need_refresh= true;
|
||||
}
|
||||
else if (digitalRead(P1_BTN_BOTTOM) == LOW && p1_start < 5) {
|
||||
p1_start += 1;
|
||||
need_refresh= 1;
|
||||
need_refresh= true;
|
||||
}
|
||||
}
|
||||
|
||||
int pong_move_p2(int &p2_start, int &need_refresh) {
|
||||
if (digitalRead(P2_BTN_UP) == LOW && p2_start > 0) {
|
||||
p2_start -= 1;
|
||||
need_refresh= 1;
|
||||
need_refresh= true;
|
||||
}
|
||||
else if (digitalRead(P2_BTN_BOTTOM) == LOW && p2_start < 5) {
|
||||
p2_start += 1;
|
||||
need_refresh= 1;
|
||||
need_refresh= true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user