[Solved] Less code with mouseX and mouseY condition
in
Programming Questions
•
3 years ago
Hello,
I'm a beginner in programming and I search a method for making a minimal code (a fonction?)
My code
- // PERSO_0
- if(mouseX <= 100 && mouseY <= 200){
- imgPerso =loadImage(perso[0]);
- image(imgPerso,0,0);
- }
- else if(mouseX <= 100 && mouseY <= 400){
- imgPerso =loadImage(perso[0]);
- imgPersoTitle =loadImage(persoTitle[0]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- }
- else if(mouseX <= 100 && mouseY <= 600){
- imgPerso =loadImage(perso[0]);
- imgPersoTitle =loadImage(persoTitle[0]);
- imgPersoFonction =loadImage(persoFonction[0]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- image(imgPersoFonction,0,300);
- }
- // PERSO_1
- else if(mouseX <= 200 && mouseY <= 200){
- imgPerso =loadImage(perso[1]);
- image(imgPerso,0,0);
- }
- else if(mouseX <= 200 && mouseY <= 400){
- imgPerso =loadImage(perso[1]);
- imgPersoTitle =loadImage(persoTitle[1]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- }
- else if(mouseX <= 200 && mouseY <= 600){
- imgPerso =loadImage(perso[1]);
- imgPersoTitle =loadImage(persoTitle[1]);
- imgPersoFonction =loadImage(persoFonction[1]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- image(imgPersoFonction,0,300);
- }
- // PERSO_2
- else if(mouseX <= 300 && mouseY <= 200){
- imgPerso =loadImage(perso[2]);
- image(imgPerso,0,0);
- }
- else if(mouseX <= 300 && mouseY <= 400){
- imgPerso =loadImage(perso[2]);
- imgPersoTitle =loadImage(persoTitle[2]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- }
- else if(mouseX <= 300 && mouseY <= 600){
- imgPerso =loadImage(perso[2]);
- imgPersoTitle =loadImage(persoTitle[2]);
- imgPersoFonction =loadImage(persoFonction[2]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- image(imgPersoFonction,0,300);
- }
- //PERSO_3
- else if(mouseX <= 400 && mouseY <= 200){
- imgPerso =loadImage(perso[3]);
- image(imgPerso,0,0);
- }
- else if(mouseX <= 400 && mouseY <= 400){
- imgPerso =loadImage(perso[3]);
- imgPersoTitle =loadImage(persoTitle[3]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- }
- else if(mouseX <= 400 && mouseY <= 600){
- imgPerso =loadImage(perso[3]);
- imgPersoTitle =loadImage(persoTitle[3]);
- imgPersoFonction =loadImage(persoFonction[3]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- image(imgPersoFonction,0,300);
- }
- // PERSO_4
- else if(mouseX <= 500 && mouseY <= 200){
- imgPerso =loadImage(perso[4]);
- image(imgPerso,0,0);
- }
- else if(mouseX <= 500 && mouseY <= 400){
- imgPerso =loadImage(perso[4]);
- imgPersoTitle =loadImage(persoTitle[4]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- }
- else if(mouseX <= 500 && mouseY <= 600){
- imgPerso =loadImage(perso[4]);
- imgPersoTitle =loadImage(persoTitle[4]);
- imgPersoFonction =loadImage(persoFonction[4]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- image(imgPersoFonction,0,300);
- }
- // PERSO_5
- else if(mouseX <= 600 && mouseY <= 200){
- imgPerso =loadImage(perso[5]);
- image(imgPerso,0,0);
- }
- else if(mouseX <= 600 && mouseY <= 400){
- imgPerso =loadImage(perso[5]);
- imgPersoTitle =loadImage(persoTitle[5]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- }
- else if(mouseX <= 600 && mouseY <= 600){
- imgPerso =loadImage(perso[5]);
- imgPersoTitle =loadImage(persoTitle[5]);
- imgPersoFonction =loadImage(persoFonction[5]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- image(imgPersoFonction,0,300);
- }
- // PERSO_6
- else if(mouseX <= 700 && mouseY <= 200){
- imgPerso =loadImage(perso[6]);
- image(imgPerso,0,0);
- }
- else if(mouseX <= 700 && mouseY <= 400){
- imgPerso =loadImage(perso[6]);
- imgPersoTitle =loadImage(persoTitle[6]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- }
- else if(mouseX <= 700 && mouseY <= 600){
- imgPerso =loadImage(perso[6]);
- imgPersoTitle =loadImage(persoTitle[6]);
- imgPersoFonction =loadImage(persoFonction[6]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- image(imgPersoFonction,0,300);
- }
- // PERSO_7
- else if(mouseX <= 800 && mouseY <= 200){
- imgPerso =loadImage(perso[7]);
- image(imgPerso,0,0);
- }
- else if(mouseX <= 800 && mouseY <= 400){
- imgPerso =loadImage(perso[7]);
- imgPersoTitle =loadImage(persoTitle[7]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- }
- else if(mouseX <= 800 && mouseY <= 600){
- imgPerso =loadImage(perso[7]);
- imgPersoTitle =loadImage(persoTitle[7]);
- imgPersoFonction =loadImage(persoFonction[7]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- image(imgPersoFonction,0,300);
- }
- // PERSO_8
- else if(mouseX <= 900 && mouseY <= 200){
- imgPerso =loadImage(perso[8]);
- image(imgPerso,0,0);
- }
- else if(mouseX <= 900 && mouseY <= 400){
- imgPerso =loadImage(perso[8]);
- imgPersoTitle =loadImage(persoTitle[8]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- }
- else if(mouseX <= 900 && mouseY <= 600){
- imgPerso =loadImage(perso[8]);
- imgPersoTitle =loadImage(persoTitle[8]);
- imgPersoFonction =loadImage(persoFonction[8]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- image(imgPersoFonction,0,300);
- }
- // PERSO_9
- else if(mouseX <= 1000 && mouseY <= 200){
- imgPerso =loadImage(perso[9]);
- image(imgPerso,0,0);
- }
- else if(mouseX <= 1000 && mouseY <= 400){
- imgPerso =loadImage(perso[9]);
- imgPersoTitle =loadImage(persoTitle[9]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- }
- else if(mouseX <= 1000 && mouseY <= 600){
- imgPerso =loadImage(perso[9]);
- imgPersoTitle =loadImage(persoTitle[9]);
- imgPersoFonction =loadImage(persoFonction[9]);
- image(imgPerso,0,0);
- image(imgPersoTitle,0,0);
- image(imgPersoFonction,0,300);
- }
Do you have solutions?
Excuse me for my English, my basis language isn't English.
1