Help needed with visualising a recording app.
in
Programming Questions
•
9 months ago
Hello! I need help visualising a simple recording game. I am trying to find code for 2 lines to be present on the page for each player. The lines will rise when the user taps the space bar which registers a hit for the player.
Any help is appreciated! Thanks!
Here is the code I have already:
int[] player1 = new int[240]; //list frameStates , 240 entries.
int[] player2 = new int[240]; //list frameStates , 240 entries.
int currentPlayer = 1; //player 1 is playing
Boolean playerActive = false; // A control statement, player, playing, is not true
Boolean countdownActive = false; // countdown is on is not true.
String countDownText = "3";
int count = 0; //count from the start.
int countDown = 90; // the countdown will last for 3 seconds (90 milliseconds)
void setup()
{
size(600,600);
// flood list with zeros
for (int i = 0; i < player1.length; i++)
{
player1[i] = 0;
player2[i] = 0;
}
}
void draw()
{
background(0); // background is black
// NOTHING ACTIVE - waiting for user input
if ((playerActive == false) && (countdownActive == false))
{
text ("Welcome" , 250, 50);
text("Player " + currentPlayer ,260, 270); //show "player (player 1 or player 2) ready" 5, 20 = position.
text("Press P to change player", 160, 225);
textSize(25);
}
// COUNT DOWN ACTIVE - 3 second countdown add visuals here
if (countdownActive == true) // If the countdown starts
{
countDown--;
if ((countDown % 30) == 0 && (countDown / 30) == 2 ) countDownText = "2";
if ((countDown % 30) == 0 && (countDown / 30) == 1 ) countDownText = "1";
if ((countDown % 30) == 0 && (countDown / 30) == 0 ) countDownText = "0";
text(countDownText, 300, 300);
println(countDown); // write countdown
if (countDown == 0) // when countdown starts at 0
{
countdownActive = false; // when countdown has finished
countDown = 90; // when it reaches 90 milliseconds (3 seconds)
playerActive = true; // the player is in play
println("countdown ended - gameplay started"); // write " countdown ended - gameplay started"
delay(1000);
}
}
// GAME PLAY - anything visual or to do with game play.
if (playerActive == true) // if the player is playing
{
count++;
println(count); // write the milliseconds of the game
if (count > 240) // count down from 240
{
playerActive = false; // when 240 is reached then stop the player
count = 0; // when the count reaches 0
println("game ended"); // write game ended
}
{
}
}
}
void keyPressed()
{
switch(key)
{
case 'p':
switchPlayer(); // when the 'p' key is pressed, switch players, 1+2
break;
case ' ': // when spacebar is pressed, the gameplay has began
gamePlay();
break;
case 'r':
readOut(); //when 'r' is pressed, write out the results (zeros and ones)
break;
case 'c':
checkResult();
break;
}
}
void gamePlay() // gameplay
{
if (playerActive == false && countdownActive == false)
{
println("count down started"); // write out "count down started"
countdownActive = true; //when countdown has begun
}else
{
if (playerActive) // if the player is playing
{
if (currentPlayer == 1) // if player one is playing
{
player1[count] = 1; // count its ryththm
}else // if player one isnt playing
{
player2[count] = 1; // then player 2 is playing
}
}
}
}
void readOut() // write out in the console
{
String player1out = " "; // a result list from player 1, when space bar is pressed
String player2out = " "; // a result list from player 2, when space bar is pressed
for (int i = 0; i < player1.length; i++)
{
player1out = player1out + player1[i];
player2out = player2out + player2[i];
}
println(player1out);
println(player2out);
}
void switchPlayer()
{
if (playerActive == false && countdownActive == false)
{
if (currentPlayer == 1)
{
currentPlayer = 2;
}else
{
currentPlayer = 1;
}
}
}
void checkResult()
{
float score = 0.0;
for (int i = 0; i < player1.length; i++)
{
if (player1[i] == player2[i])
{
score++;
}
}
println((100.0 / 240.0) * score);
}
//make the game visual. Lines which show the two players pressing.
Any help is appreciated! Thanks!
Here is the code I have already:
int[] player1 = new int[240]; //list frameStates , 240 entries.
int[] player2 = new int[240]; //list frameStates , 240 entries.
int currentPlayer = 1; //player 1 is playing
Boolean playerActive = false; // A control statement, player, playing, is not true
Boolean countdownActive = false; // countdown is on is not true.
String countDownText = "3";
int count = 0; //count from the start.
int countDown = 90; // the countdown will last for 3 seconds (90 milliseconds)
void setup()
{
size(600,600);
// flood list with zeros
for (int i = 0; i < player1.length; i++)
{
player1[i] = 0;
player2[i] = 0;
}
}
void draw()
{
background(0); // background is black
// NOTHING ACTIVE - waiting for user input
if ((playerActive == false) && (countdownActive == false))
{
text ("Welcome" , 250, 50);
text("Player " + currentPlayer ,260, 270); //show "player (player 1 or player 2) ready" 5, 20 = position.
text("Press P to change player", 160, 225);
textSize(25);
}
// COUNT DOWN ACTIVE - 3 second countdown add visuals here
if (countdownActive == true) // If the countdown starts
{
countDown--;
if ((countDown % 30) == 0 && (countDown / 30) == 2 ) countDownText = "2";
if ((countDown % 30) == 0 && (countDown / 30) == 1 ) countDownText = "1";
if ((countDown % 30) == 0 && (countDown / 30) == 0 ) countDownText = "0";
text(countDownText, 300, 300);
println(countDown); // write countdown
if (countDown == 0) // when countdown starts at 0
{
countdownActive = false; // when countdown has finished
countDown = 90; // when it reaches 90 milliseconds (3 seconds)
playerActive = true; // the player is in play
println("countdown ended - gameplay started"); // write " countdown ended - gameplay started"
delay(1000);
}
}
// GAME PLAY - anything visual or to do with game play.
if (playerActive == true) // if the player is playing
{
count++;
println(count); // write the milliseconds of the game
if (count > 240) // count down from 240
{
playerActive = false; // when 240 is reached then stop the player
count = 0; // when the count reaches 0
println("game ended"); // write game ended
}
{
}
}
}
void keyPressed()
{
switch(key)
{
case 'p':
switchPlayer(); // when the 'p' key is pressed, switch players, 1+2
break;
case ' ': // when spacebar is pressed, the gameplay has began
gamePlay();
break;
case 'r':
readOut(); //when 'r' is pressed, write out the results (zeros and ones)
break;
case 'c':
checkResult();
break;
}
}
void gamePlay() // gameplay
{
if (playerActive == false && countdownActive == false)
{
println("count down started"); // write out "count down started"
countdownActive = true; //when countdown has begun
}else
{
if (playerActive) // if the player is playing
{
if (currentPlayer == 1) // if player one is playing
{
player1[count] = 1; // count its ryththm
}else // if player one isnt playing
{
player2[count] = 1; // then player 2 is playing
}
}
}
}
void readOut() // write out in the console
{
String player1out = " "; // a result list from player 1, when space bar is pressed
String player2out = " "; // a result list from player 2, when space bar is pressed
for (int i = 0; i < player1.length; i++)
{
player1out = player1out + player1[i];
player2out = player2out + player2[i];
}
println(player1out);
println(player2out);
}
void switchPlayer()
{
if (playerActive == false && countdownActive == false)
{
if (currentPlayer == 1)
{
currentPlayer = 2;
}else
{
currentPlayer = 1;
}
}
}
void checkResult()
{
float score = 0.0;
for (int i = 0; i < player1.length; i++)
{
if (player1[i] == player2[i])
{
score++;
}
}
println((100.0 / 240.0) * score);
}
//make the game visual. Lines which show the two players pressing.
1