You still need to learn how to post code correctly. I described it above.
This is quite at the beginning of draw() and it makes no sense:
if (mousePressed && (mouseButton == LEFT)) { //appuyer sur le bouton
fill(48);
} else {
fill(0);
}
rect(340, 200, 220, 50);//encadrement
rect(340, 300, 220, 50);//encadrement
it makes no sense because both buttons light up (not one) when you click somewhere on the screen. What you really want to achieve is that the button you hover over with the mouse (without clicking) lights up.
I deleted this part.
Chrisir
entire sketch
PImage img;
PImage ile;//fond
bird b = new bird();//nouvelle partie
pillar[] p = new pillar[3];//batons
int score=0;//score
int state = 0;
void setup() {
img = loadImage("boule.png");
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(0);//ile/ fond
if (state==0) {
// intro
textSize(35); //taille de l’écriture
fill(#FFA500); //couleur écriture
fill(#FF0000); //couleur cadre
rect(310, 50, 300, 100);//encadrement
fill(255); //couleur
text("Flappy Rabbit", 350, 115);//titre debut
text("Click to Play ", 350, 240);//debut
text("Instructions ", 355, 340);//menu
}
// ---------------------------
else if (state==1) {
// GAME
background(0);//ile/ fond
rect(20, 20, 100, 50);//cadre score
fill(230);//texte score
text(score, 30, 58); //texte score
b.move(); //mouvement de la balle
b.drawBird(); //vision de balle
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
//
}
// ---------------------------
else if (state==2) {
//
//si perdu
//
textSize(32); //taille de l’écriture
fill(#FF0000);
rect(340, 100, 220, 50);//encadrement
rect(340, 200, 220, 50);//encadrement
fill(255); //couleur
text("Game Over", 350, 140);//fin
text("Accueil", 390, 235);//score
}
// ---------------------------
else if (state==3) {
background(#1601FD);// fond
textSize(32); //taille de l’écriture
fill(#21F904); //couleur texte
text("REGLE DU JEU", 350, 75);
fill(0); //couleur
text("Le but du jeu est de:", 15, 150);
fill(#FF0000); //couleur
text("-passer entre les poteaux sans les toucher ", 15, 225);
text("-marquer le plus de points", 15, 300);
fill(0); //couleur
text("Comment jouer?", 15, 375);
fill(#FF0000); //couleur
text("-appuyer sur la barre espace pour sauter ", 15, 450);
text("-appuyer sur toutes les touches", 15, 525);
rect(400, 600, 220, 50);//encadrement
fill(0); //couleur
text("RETOUR", 440, 640);
}
}//func
void reset() { //recomencer
score=0;
b.yPos=400;
b.ySpeed=0;
for (int i = 0; i<3; i++) {
p[i].xPos+=550;
p[i].cashed = false;
}
}
void mousePressed() {
//sauter avec la souris
switch(state) {
// -------
case 0:
float x1=340; //emplacement cadre
float y1=200;
float w1=220;
float h1=50;
if (mouseX > x1 && //selection cadre
mouseX < x1 + w1 &&
mouseY > y1 &&
mouseY < y1 + h1) {
state=1;
reset(); //recomence
}
float x2=340; //emplacement cadre
float y2=300;
float w2=220;
float h2=50;
if (mouseX > x2 && //selection cadre
mouseX < x2 + w2 &&
mouseY > y2 &&
mouseY < y2 + h2) {
state=3;
reset();
}
break;
// -------
case 3:
float x3=400; //emplacement cadre
float y3=600;
float w3=220;
float h3=50;
if (mouseX > x3 && //selection cadre
mouseX < x3 + w3 &&
mouseY > y3 &&
mouseY < y3 + h3) {
state=0;
reset();
}
break;
// -------
case 2:
float x4=340; //emplacement cadre
float y4=200;
float w4=220;
float h4=50;
if (mouseX > x4 && //selection cadre
mouseX < x4 + w4 &&
mouseY > y4 &&
mouseY < y4 + h4) {
state=0;
reset();
}//if
break;
// -------
}//switch
}//func
void keyPressed() {
//sauter avec la barre d’espace
switch(state) {
case 0:
state=1;
reset();
break;
case 1:
b.jump();
break;
case 2:
reset();
state=0;
break;
//
case 3:
state=3;
reset();
break;
}//switch
}//func
// ============================================================================================
// from now on only classes
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() { //balle
stroke(#FFA500);
noFill();
strokeWeight(5);
if (yPos<10)
yPos=10;
// image(img, b.xPos, b.yPos); // balle
ellipse (b.xPos, b.yPos, 7, 7); // balle
}
void jump() { //monter
ySpeed=-10;
}
void drag() { //avancer
ySpeed+=0.4;
}
void move() { //bouger
yPos+=ySpeed;
for (int i = 0; i<3; i++) {
p[i].xPos-=3;
}
}
void checkCollisions() { //collision avec poteau
if (yPos>800) {
state=2;
}
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)) {
state=2;
}
}
}
}//class
class pillar {
//poteau
float xPos, opening;
boolean cashed = false;
pillar(int i) {
xPos = 100+(i*200);
opening = random(600)+100;
}
void drawPillar() { //poteau
line(xPos, 0, xPos, opening-100);
line(xPos, opening+100, xPos, 800);
}
void checkPosition() { //poisition
if (xPos<0) {
xPos+=(2003);
opening = random(600)+100;
cashed=false;
}
if (xPos<250&&cashed==false) {
cashed=true;
score++;
}
}
}//class
//