Hi everyone! I’m doing a game using processing.
The game’s pretty simple: there’s a black bar that slowly rises when you get a point and your goal is to bring the bar up to the top. To get a point it works pretty much like Tetris, you have another small bar that falls from the top and you have to click on the mouse when the two bars are overlapping.
Our problem is that at the end of the game it should appear a “win” text and if you want to restart the game you should just click on the mouse. We cannot solve this last part, we tried with a delay but nothing it’s working can you help us?
Here’s the code:
int val;
//-- Import typography
PFont font;
//-- If "true" means that touch the bar, "false" that it doesn't
boolean colision = false;
//-- Variables of the rectangle
float pos_y=0; // Variable posición Y ficha inicializada a 0
float pos_x=250; // Variable posición X ficha iniciazada a 250
float vel=1.4; // Variable velocidad Y inicializada en 1
//-- Variables of the Bar
float posinicial=470; // Posicion inicial en y
float incremento=50; // Variable velocidad subida inicializada en 50
float posbarra=posinicial; // Variable posicion barra
//-- Variable of the safe zone
float safezone=10;
//-- Variable of the touching/colision point
float accierto=10;
//--Variables Colores
color negro=color(0, 0, 0);
color blanco=color(255, 255, 255);
color rosa=color(193, 80, 152);
color morado=color(117, 103, 171);
color azul=color(74, 158, 208);
color purpura=color(122, 55, 139);
void setup()
{
size(500, 500);
}
//-- drawing loop
void draw() {
//-- Paint white background
background(255);
//-- change position using speed variable
pos_y=pos_y+vel;
//-- if the rectangle reaches the bottom, restart from the top
if (pos_y>500) {
pos_y=0;
pos_x=100+random(300);
//posbarra=posbarra-20;
//vel=vel+1;
}
//-- drawing the rectangle
stroke(1);
rect(pos_x, pos_y, 50, 10);
//-- touching point zone (leer ultimo if)
fill(0, 255, 0);
noStroke();
rect(0, 0, 500, safezone);
//-- drawing the bar
fill(0);
rect(0, posbarra, 500, 10);
//-- loop if: if the bar and the rect are touching. If yes, the rect becomes pink.
if ( (pos_y > posbarra-accierto) && (pos_y < posbarra+accierto ) ) {
fill(rosa);
colision=true;
//-- If not, the variable is 'not' and so the rect is in red color
} else {
fill(255, 0, 0);
colision=false;
}
//--Loop if for touching point
//-- If you touch in the right moment, the bar goes up and the rect restarts from the top
if ( (colision) && ( mousePressed == true )) {
//-- bar going up
posbarra=posbarra-incremento;
//-- restart the rectangle position
pos_y=0;
pos_x=100+random(300);
}
//-- Loop if Error - if you click in the wrong moment of collision
if ( (pos_y > safezone) && (colision == false) && (mousePressed == true)) {
//-- bar goes back to start
posbarra=posinicial;
//-- pink error dispolay
background(rosa);
}
//-- Loop if with no click
//-- if you don't click the bar goes down of one step
if ( (pos_y > posbarra+accierto ) && (posbarra < posinicial) ) {
//-- bar goes down
posbarra=posbarra+incremento;
//-- back to last position
pos_y=0;
pos_x=100+random(300);
}
//-- if loop, when you finish the game and bar reaches the top
println(posbarra);
if (posbarra<30) {
fill(0);
rect(0, 0, 500, 500);
//-- put typography
font= loadFont("Bungee-Regular-48.vlw");
textFont(font, 32);
textSize(70);
fill(200, 0, 0);
text("YOU WIN!", 65, 260);
//frameRate(1);
textFont(font, 12);
textSize(70);
fill(200, 0, 0);
//text("push to restart", 65, 290);
posbarra=posinicial;
//frameRate(30);
}
}