Hi all, I’m new on this forum. I’ve writing my first game to processing and I’m trying to add score and ending to my game. I’ve just add some lines of code but don’t work. Someone can help me?
Here the code:
float x = 360;
float y = random(0,360);
float x2 = 360;
float y2 = random(0,360);
float x3 = 360;
float y3 = random(0,255);
PFont f;
int score = 0;
int lives = 5;
boolean lost = false;
void setup() {
size(400,400);
background(255);
f = createFont("Times New Roman",25,true);
}
void randomrect() {
fill(0);
rect(x,y,40,40);
x = x - 2;
if(x<-40) {
x = 360;
y = random(0,360);
}
}
void randomrect2() {
fill(0);
rect(x2,y2,40,40);
x2 = x2 - 2;
if(x2<-40) {
x2 = 360;
y2 = random(0,360);
}
}
void randomrect3() {
fill(0);
rect(x3,y3,40,40);
x3 = x3 - 2;
if(x3<-40) {
x3 = 360;
y3 = random(0,360);
}
}
for(int count = 0; count <= 5 ; count = count+1) {
void gameover(float squarex, float squarey) {
if(((mouseY>squarey) && (mouseY<squarey+40) && (squarex <= 80) && (squarex >= 0)) || ((mouseY+40>squarey) && (mouseY+40<squarey+40) && (squarex <= 80) && (squarex >= 0))) {
lives- -;
}
else {
if((lives<=0) && (count>=0)) {
textFont (f,25);
fill(255,0,0);
text("GAME OVER",140,160);
noLoop();
}
}
}
}
void draw() {
println(x,y,x2,y2);
background(255);
noStroke();
fill(200,0,0);
rect(40,mouseY,40,40);
text("score=" + score,340,20);
text("lives=" + lives, 0,20);
score++;
gameover(x,y);
gameover(x2,y2);
gameover(x3,y3);
randomrect();
if(frameCount>60) {
randomrect2();
}
if (frameCount>120) {
randomrect3();
}
if (lives<=0) {
lost = true;
noLoop();
textSize(20);
text("Click to Restart", 125,100);
textSize(13);
}
}
Thanks for the replies.