Hello everyone I have a presentation of a computer game and my program works very well but when I have to add a button there is a problem with void reset. I will need your help please to be able to add a menu with a button that directs me to the game. Thank you for your help. Here is the code:
PImage ile;//fond
bird b = new bird();//nouvelle partie
pillar[] p = new pillar[3];//batons
boolean end=false;
boolean intro=true;
int score=0;//score
void setup()
{
ile = loadImage(“Fond.png”);//fond
size(1000, 800);//ecran
for (int i = 0; i<3; i++) {
p[i]=new pillar(i);//batons
}
}
void draw() {
background(ile);//fond
if (end) {
b.move(); //mouvement de la balle
}
b.drawBird(); //vision de balle
if (end) {
b.drag(); //redessente
}
b.checkCollisions(); //collision
for (int i = 0; i<3; i++) {
p[i].drawPillar();//batons
p[i].checkPosition();//batons
}
fill(0);//couleur fond encadrement
textSize(32); //taille de l’écriture
if (end) {
rect(20, 20, 100, 50);//cadre score
fill(255);//texte score
text(score, 30, 58); //texte score
} else {
rect(150, 100, 220, 50);//encadrement
rect(150, 200, 220, 50);//encadrement
rect(150, 300, 220, 50);//encadrement
fill(255); //couleur
if (intro) {//debut
text("Flappy Rabbit", 155, 140);//titre debut
text("Click to Play ", 165, 240);//debut
text("Menu ", 175, 340);//menu
} else { //si perdu
text("Game Over", 170, 140);//fin
text("score", 180, 240);//score
text("menu", 175, 340);//score
}
}
}
class bird {
float xPos, yPos, ySpeed; //position de la balle
bird() {
xPos = 250;//position de la balle au début
yPos = 400;//position de la balle au début
}
void drawBird() {
stroke(#FFA500);
noFill();
strokeWeight(5);
ellipse(xPos, yPos, 20, 20);//boule
}
void jump() {
ySpeed=-10;//vitesse
}
void drag() {
ySpeed+=0.4;
}
void move() {
yPos+=ySpeed;
for (int i = 0; i<3; i++) {
p[i].xPos-=3;
}
}
void checkCollisions() {
if (yPos>800) {
end=false;
}
for (int i = 0; i<3; i++) {
if ((xPos<p[i].xPos+10&&xPos>p[i].xPos-10)&&(yPos<p[i].opening-100||yPos>p[i].opening+100)) {
end=false;
}
}
}
}
class pillar {
float xPos, opening;
boolean cashed = false;
pillar(int i) {
xPos = 100+(i200);
opening = random(600)+100;
}
void drawPillar() {
line(xPos, 0, xPos, opening-100);
line(xPos, opening+100, xPos, 800);
}
void checkPosition() {
if (xPos<0) {
xPos+=(2003);
opening = random(600)+100;
cashed=false;
}
if (xPos<250&&cashed==false) {
cashed=true;
score++;
}
}
}
void reset() {
end=true;
score=0;
b.yPos=400;
for (int i = 0; i<3; i++) {
p[i].xPos+=550;
p[i].cashed = false;
}
}
void mousePressed() {//sauter avec la souris
b.jump();
intro=false;
if (end==false) {
reset();
}
}
void keyPressed() {//sauter avec la barre d’espace
b.jump();
intro=false;
if (end==false) {
reset();
}
}