I am trying to limit the number of characters are in a section before the user cannot type anymore.
Any help would be great! here is what I have in that section already:
if (textBoxFocus == 0)title += key; //if the 'title' box is selected, let the user write in it.
if (textBoxFocus == 1)description += key; //if the 'description' box is selected, let the user write in it.
if ((title.length() % 12) == 0) title+='\n'; //if the letters writen in the'title' section reach over 12, start a new line.
if ((description.length() % 20) == 0) description+='\n';// if the letters in the 'description' section reach over 20, start a new line.
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 == 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];
}
Hi, I am making a small game which allows users to 'record' their moves.
The next step in my project is when the user presses the space bar, it will take them back to their last move. The user will only be able to go back 4 steps. Here is what I have so far:
int xPos = 85;
int yPos = 85;
int [] myArray = new int [3];
float speed = 1;
void setup ()
{
size(200, 200);
noStroke();
for (int i = 0; i < myArray.length; i++) {
myArray [i] = 0;
}
}
void draw ()
{
background (0);
if (xPos > width) {
xPos = 0;
fill (215, 0, 35);
}
if (yPos > height) {
yPos = 0;
fill (200, 56, 35);
}
if (xPos < 0) {
xPos = width;
fill (190, 86, 23);
}
if (yPos < 0) {
yPos = height;
fill (150, 0, 65);
}
rect (xPos, yPos, 30, 20);
}
void keyPressed () {
if (key == CODED) {
if (keyCode == LEFT) {
xPos = xPos - 10;
} else if (keyCode == RIGHT) {
xPos = xPos + 10;
}
else if (keyCode == UP)
{
yPos = yPos -10;
}
else if (keyCode == DOWN)
{
yPos = yPos + 10;
//hit space bar to show the last move. With a maximum of 4 steps.