allow user choose between game modes, pvp, pvc, cvc
This commit is contained in:
@@ -36,12 +36,15 @@ enum game_statuses : uint8_t {
|
|||||||
game_statuses game_status= TIMER;
|
game_statuses game_status= TIMER;
|
||||||
|
|
||||||
Ball ball(4, 6);
|
Ball ball(4, 6);
|
||||||
HumanPaddle p1(1, P1_BTN_UP, P1_BTN_BOTTOM);
|
|
||||||
// HumanPaddle p2(4, P2_BTN_UP, P2_BTN_BOTTOM);
|
Paddle* p1 = nullptr;
|
||||||
// BotPaddle p1(1, 0, 2);
|
Paddle* p2 = nullptr;
|
||||||
BotPaddle p2(4, MATRIX_WIDTH-1, 1);
|
HumanPaddle human_p1(1, P1_BTN_UP, P1_BTN_BOTTOM);
|
||||||
Engine engine(p1, p2, ball, INITIAL_BALL_DELAY);
|
HumanPaddle human_p2(4, P2_BTN_UP, P2_BTN_BOTTOM);
|
||||||
Renderer renderer(p1, p2, ball, frame, matrix);
|
BotPaddle bot_p1(1, 0, 2);
|
||||||
|
BotPaddle bot_p2(4, MATRIX_WIDTH-1, 1);
|
||||||
|
Engine engine(*p1, *p2, ball, INITIAL_BALL_DELAY);
|
||||||
|
Renderer renderer(*p1, *p2, ball, frame, matrix);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
@@ -62,11 +65,23 @@ void loop() {
|
|||||||
switch (game_status) {
|
switch (game_status) {
|
||||||
|
|
||||||
case MENU:
|
case MENU:
|
||||||
// show menu on the matrix
|
// TODO render menu on matrix
|
||||||
|
// i could use slideshow
|
||||||
// 1. P vs P
|
// 1. P vs P
|
||||||
|
if (digitalRead(P1_BTN_UP) == LOW) {
|
||||||
|
p1= &human_p1;
|
||||||
|
p2= &human_p2;
|
||||||
|
}
|
||||||
// 2. P vs CPU
|
// 2. P vs CPU
|
||||||
|
else if (digitalRead(P1_BTN_BOTTOM) == LOW) {
|
||||||
|
p1= &human_p1;
|
||||||
|
p2= &bot_p2;
|
||||||
|
}
|
||||||
// 3. CPU vs CPU
|
// 3. CPU vs CPU
|
||||||
// slideshow menu
|
else if (digitalRead(P2_BTN_UP) == LOW) {
|
||||||
|
p1= &bot_p1;
|
||||||
|
p2= &bot_p2;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TIMER:
|
case TIMER:
|
||||||
@@ -101,7 +116,7 @@ void loop() {
|
|||||||
renderer.render_score();
|
renderer.render_score();
|
||||||
engine.restart_ball();
|
engine.restart_ball();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
if (p1.get_score() >= MAX_POINTS || p2.get_score() >= MAX_POINTS)
|
if (p1->get_score() >= MAX_POINTS || p2->get_score() >= MAX_POINTS)
|
||||||
game_status= GAMEOVER;
|
game_status= GAMEOVER;
|
||||||
else {
|
else {
|
||||||
game_status= RUN;
|
game_status= RUN;
|
||||||
|
|||||||
Reference in New Issue
Block a user