Hey for a school project I am making a little game where you control a spaceship with your mouse and you have to go between the walls. If you hit one of the walls you fail. (It is like a flappy bird game)
But the problem is that I cannot find how to put a scoreboard and I am also struggling with making a collision detector on the walls that are moving.
Here is my code:
PImage arriereplan;
PImage oiseau;
PImage comete;
PImage depart;
PFont dream;
PFont BebasNeue;
int gamestate = 1;
int score = 0;
int highScore =0;
int x= -200, y;
int[] wx= new int[2];
int[] wy= new int[2];
void setup() {
size(852,480);
fill(255);
textSize(40);
frameRate(60);
oiseau = loadImage("Sans titre-1.png");
arriereplan = loadImage("28592983256_79fcee4451_b.jpg");
depart = loadImage("depart.jpg");
comete = loadImage("Sans titre-3.jpg");
dream = createFont("Dream MMA.ttf",50);
BebasNeue = createFont("Dream MMA.ttf",50);
}
void draw() { //runs 60 times a second
if(gamestate == 0) {
text("Space Rocket" , width/2, height/2);
imageMode(CORNER);
image(arriereplan, 0, 0);
image(oiseau, width/2, y);
x = mouseX;
y = mouseY;
for(int i = 0 ; i < 2; i++) {
imageMode(CENTER);
image(comete, wx[i], wy[i] - (comete.height/2+75));
image(comete, wx[i], wy[i] + (comete.height/2+75));
if(wx[i] < 0) {
wy[i] = (int)random(50,height-50);
wx[i] = 852;
}
wx[i] -= 5;
if(wx[i] == 0) highScore = max(++score, highScore);
if(y>height||y<0||(abs(width/2-wx[i])<25 && abs(y-wy[i])>100)) gamestate=1;
text(""+score, 780, 460);
}
}
else {
imageMode(CENTER);
image(depart, width/2,height/2);
textFont(dream);
text("space rocket", 160, 190);
textSize(35);
text("play", 160, 270);
textSize(35);
text("high score: "+highScore, 350, 270); //display the score
rect(145, 230, 170, 55);
noFill();
stroke(255);
}
}
void mousePressed() {
if(gamestate==1) {
wx[0] = 600;
wy[0] = y = height/2;
wx[1] = 900;
wy[1] = 600;
x = gamestate = 0;
}
}