Hello everyone!
Basically the question. I am making a Pong Game and it is actually finished, but I just want to make it more perfect. I am only lacking these particular messages for when a winner has to be announced. I could only make “Player 1 won” and “Player 2 or Bot won”. But I would actually like the winnerAnnouncer() function to recognize which play mode was being played: if the onePlayer() or the twoPlayers().
So here is part of my code:
int gameState = 0; // 0: home menu, 1: one player, 2: two players, 3: instructions, 4: winnerAnnouncer
int player1Score = 0;
int player2Score = 0;
int winningScore = 3;
boolean gameStarted = false;
boolean showInstructions = false;
boolean isSinglePlayer = true;
Paddle player1, player2;
Ball ball;
void setup() {
size(600, 400);
rectMode(CENTER);
player1 = new Paddle(20, height/2);
player2 = new Paddle(width-20, height/2);
ball = new Ball();
}
void draw() {
background(0);
if (gameState == 0) {
homeMenu();
} else if (gameState == 1) {
onePlayer();
} else if (gameState == 2) {
twoPlayers();
} else if (gameState == 3) {
instructions();
} else if (gameState == 4) {
winnerAnnouncer();
}
}
void homeMenu() {
textAlign(CENTER);
textSize(64);
fill(255);
text("Pong", width/2, height/2-40);
textSize(32);
text("Press 1 for single player \n Press 2 for multiplayer \n Press 3 for instructions", width/2, height/2);
}
void onePlayer() {
if (!gameStarted) {
textAlign(CENTER);
textSize(48);
fill(255);
text("SINGLE PLAYER", width/2, height/2 - 20);
textSize(32);
text("Press any key to start.", width/2, height/2 + 20);
} else {
if (isSinglePlayer) {
player2.aiMove(ball);
}
updateGame();
}
}
void twoPlayers() {
if (!gameStarted) {
textAlign(CENTER);
textSize(48);
fill(255);
text("MULTIPLAYER", width/2, height/2 - 20);
textSize(32);
text("Press any key to start.", width/2, height/2 + 20);
} else {
updateGame();
}
}
void winnerAnnouncer() {
textAlign(CENTER);
fill(255);
textSize(48);
if (player1Score == winningScore) {
text("PLAYER 1 WON", width/2, height/2 - 20);
} else {
text("PLAYER 2 or BOT WON", width/2, height/2 - 20);
}
/*
if (isOnePlayerMode) {
if (player1Score == winningScore) {
text("YOU WON!", width/2, height/2 - 20);
} else if (player2Score == winningScore) {
text("BOT WON!", width/2, height/2 - 20);
}
} else {
if (player1Score == winningScore) {
text("PLAYER 1 WON!", width/2, height/2 - 20);
} else if (player2Score == winningScore) {
text("PLAYER 2 WON!", width/2, height/2 - 20);
}
}
*/
textSize(26);
text("Press any key to return to the HOME MENU.", width/2, height/2 + 20);
}
I only sent the relevant code functions, but tell me if it is necessary for me to send the whole thing, as I believe it is not runnable.
Thank you in advance!