render visual menu on led matrix to easly allow user choose the game modes
This commit is contained in:
@@ -35,6 +35,10 @@ enum game_statuses : uint8_t {
|
|||||||
};
|
};
|
||||||
game_statuses game_status= MENU;
|
game_statuses game_status= MENU;
|
||||||
|
|
||||||
|
enum game_modes : uint8_t {PVP, PVC, CVC};
|
||||||
|
game_modes game_mode = PVP;
|
||||||
|
|
||||||
|
|
||||||
Ball ball(4, 6);
|
Ball ball(4, 6);
|
||||||
|
|
||||||
Paddle* p1= nullptr;
|
Paddle* p1= nullptr;
|
||||||
@@ -44,6 +48,10 @@ HumanPaddle human_pad2(4, P2_BTN_UP, P2_BTN_BOTTOM);
|
|||||||
BotPaddle bot_pad1(1, 0, 2);
|
BotPaddle bot_pad1(1, 0, 2);
|
||||||
BotPaddle bot_pad2(4, MATRIX_WIDTH-1, 2);
|
BotPaddle bot_pad2(4, MATRIX_WIDTH-1, 2);
|
||||||
|
|
||||||
|
uint8_t current_gmode_idx= 0;
|
||||||
|
bool update_menu= 1;
|
||||||
|
bool mode_selected= 0;
|
||||||
|
|
||||||
Engine engine(ball, INITIAL_BALL_DELAY);
|
Engine engine(ball, INITIAL_BALL_DELAY);
|
||||||
Renderer renderer(ball, frame, matrix);
|
Renderer renderer(ball, frame, matrix);
|
||||||
|
|
||||||
@@ -65,35 +73,49 @@ void loop() {
|
|||||||
|
|
||||||
switch (game_status) {
|
switch (game_status) {
|
||||||
|
|
||||||
case MENU:
|
case MENU: {
|
||||||
// show menu on the matrix
|
if (digitalRead(P2_BTN_BOTTOM) == LOW && current_gmode_idx < sizeof(frame_gmodes)/sizeof(frame_gmodes[0]) -1) {
|
||||||
// matrix.renderBitmap(pvp_frame, MATRIX_HEIGHT, MATRIX_WIDTH);
|
current_gmode_idx += 1;
|
||||||
|
update_menu= true;
|
||||||
|
}
|
||||||
|
else if (digitalRead(P2_BTN_UP) == LOW && current_gmode_idx > 0) {
|
||||||
|
update_menu= true;
|
||||||
|
current_gmode_idx -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
// 1. P vs P
|
// 1. P vs P
|
||||||
if (digitalRead(P1_BTN_UP) == LOW) {
|
else if (digitalRead(P1_BTN_UP) == LOW || digitalRead(P1_BTN_BOTTOM) == LOW && game_modes(current_gmode_idx) == PVP) {
|
||||||
p1= &human_pad1;
|
p1= &human_pad1;
|
||||||
p2= &human_pad2;
|
p2= &human_pad2;
|
||||||
engine.set_players(p1, p2);
|
mode_selected= true;
|
||||||
renderer.set_players(p1, p2);
|
|
||||||
game_status= TIMER;
|
|
||||||
}
|
}
|
||||||
// 2. P vs CPU
|
// 2. P vs CPU
|
||||||
else if (digitalRead(P1_BTN_BOTTOM) == LOW) {
|
else if (digitalRead(P1_BTN_UP) == LOW || digitalRead(P1_BTN_BOTTOM) == LOW && game_modes(current_gmode_idx) == PVC) {
|
||||||
p1= &human_pad1;
|
p1= &human_pad1;
|
||||||
p2= &bot_pad2;
|
p2= &bot_pad2;
|
||||||
engine.set_players(p1, p2);
|
mode_selected= true;
|
||||||
renderer.set_players(p1, p2);
|
|
||||||
game_status= TIMER;
|
|
||||||
}
|
}
|
||||||
// 3. CPU vs CPU
|
// 3. CPU vs CPU
|
||||||
else if (digitalRead(P2_BTN_UP) == LOW) {
|
else if (digitalRead(P1_BTN_UP) == LOW || digitalRead(P1_BTN_BOTTOM) == LOW && game_modes(current_gmode_idx) == CVC) {
|
||||||
p1= &bot_pad1;
|
p1= &bot_pad1;
|
||||||
p2= &bot_pad2;
|
p2= &bot_pad2;
|
||||||
|
mode_selected= true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (update_menu) {
|
||||||
|
// show menu on the matrix
|
||||||
|
const byte (*current_gmode)[12]= frame_gmodes[current_gmode_idx];
|
||||||
|
matrix.loadPixels((uint8_t*)current_gmode, MATRIX_HEIGHT * MATRIX_WIDTH);
|
||||||
|
update_menu= false;
|
||||||
|
delay(300);
|
||||||
|
}
|
||||||
|
else if (mode_selected) {
|
||||||
engine.set_players(p1, p2);
|
engine.set_players(p1, p2);
|
||||||
renderer.set_players(p1, p2);
|
renderer.set_players(p1, p2);
|
||||||
game_status= TIMER;
|
game_status= TIMER;
|
||||||
}
|
}
|
||||||
// slideshow menu
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case TIMER:
|
case TIMER:
|
||||||
for (int i = START_TIMER; i >= 0; i--) {
|
for (int i = START_TIMER; i >= 0; i--) {
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ const byte font_pong[10][8][3] = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const byte pvp_frame[MATRIX_HEIGHT][MATRIX_WIDTH] = {
|
const byte frame_pvp[MATRIX_HEIGHT][MATRIX_WIDTH] = {
|
||||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||||
{ 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0 },
|
{ 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0 },
|
||||||
{ 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0 },
|
{ 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0 },
|
||||||
@@ -189,7 +189,7 @@ const byte pvp_frame[MATRIX_HEIGHT][MATRIX_WIDTH] = {
|
|||||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
const byte pvc_frame[MATRIX_HEIGHT][MATRIX_WIDTH] = {
|
const byte frame_pvc[MATRIX_HEIGHT][MATRIX_WIDTH] = {
|
||||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||||
{ 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0 },
|
{ 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0 },
|
||||||
{ 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
|
{ 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
|
||||||
@@ -200,7 +200,7 @@ const byte pvc_frame[MATRIX_HEIGHT][MATRIX_WIDTH] = {
|
|||||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
const byte cvc_frame[MATRIX_HEIGHT][MATRIX_WIDTH] = {
|
const byte frame_cvc[MATRIX_HEIGHT][MATRIX_WIDTH] = {
|
||||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||||
{ 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0 },
|
{ 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0 },
|
||||||
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
|
||||||
@@ -211,4 +211,4 @@ const byte cvc_frame[MATRIX_HEIGHT][MATRIX_WIDTH] = {
|
|||||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
const byte (*game_modes[3])[12]= {pvp_frame, pvc_frame, cvc_frame};
|
const byte (*frame_gmodes[3])[12]= {frame_pvp, frame_pvc, frame_cvc};
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ extern const uint32_t pone_wins[5][4];
|
|||||||
extern const uint32_t ptwo_wins[5][4];
|
extern const uint32_t ptwo_wins[5][4];
|
||||||
extern const byte font_pong[10][8][3];
|
extern const byte font_pong[10][8][3];
|
||||||
|
|
||||||
extern const byte pvp_frame[MATRIX_HEIGHT][MATRIX_WIDTH];
|
extern const byte frame_pvp[MATRIX_HEIGHT][MATRIX_WIDTH];
|
||||||
extern const byte pvc_frame[MATRIX_HEIGHT][MATRIX_WIDTH];
|
extern const byte frame_pvc[MATRIX_HEIGHT][MATRIX_WIDTH];
|
||||||
extern const byte cvc_frame[MATRIX_HEIGHT][MATRIX_WIDTH];
|
extern const byte frame_cvc[MATRIX_HEIGHT][MATRIX_WIDTH];
|
||||||
extern const byte (*game_modes[3])[MATRIX_WIDTH];
|
extern const byte (*frame_gmodes[3])[12];
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user