Equivalent of the function Go To in processing ?
in
Programming Questions
•
6 months ago
Hello everyone,
i apologise in advance for my english..
i'm hopeless at using processing, but i've to realise a programme.
To make it short : it is a game, and i need the user to choose the level of difficulty he wants. There are 3 levels : 1,2 and 3. And I have severals options to make him choose one :
- he clicks,
- he writes 1, 2 or 3
But, in all situations, if he doesn't click in the right place, or if he doesn't write the good number, the loop if with the conditions needs to keep looping. So I tried to insert a While just before but i don't manage to make it work. So, i was wondering if a function like Go To could exist in Processing to make the programme go to the first loop For i created if his action isn't a case i defined in the If.
For the moment i did that :
void setup() {
size(800,600);
}
void draw() {
text("Quel niveau de difficulté ?",10,30);
text("1, 2 ou 3 ?",10,50);
pushStyle();
fill(255,204,40);
rect(30,70,20,20);
rect(60,70,20,20);
rect(90,70,20,20);
popStyle();
text("1",40,90);
text("2",70,90);
text("3",100,90);
size(800,600);
}
void draw() {
text("Quel niveau de difficulté ?",10,30);
text("1, 2 ou 3 ?",10,50);
pushStyle();
fill(255,204,40);
rect(30,70,20,20);
rect(60,70,20,20);
rect(90,70,20,20);
popStyle();
text("1",40,90);
text("2",70,90);
text("3",100,90);
int dif=0;
int i = 0;
if (mousePressed==true) {
while(i != 1){
if (mouseX >29 && mouseX<51 && mouseY>69 && mouseY<91) {dif=1; i=1; }
else if (mouseX >59 && mouseX<71 && mouseY>69 && mouseY<91) {dif=2; i=1;}
else if (mouseX >89 && mouseX<101 && mouseY>69 && mouseY<91) {dif=3; i=1;}
else {i=0;}
}}
if (dif!=0) {
float x = random(1,4);
int newx = int(x);
PImage im;
im = loadImage(" http://******************+str(dif)+"/"+str(newx)+".jpg");
image(im,150,150,384,216);
}
}
int i = 0;
if (mousePressed==true) {
while(i != 1){
if (mouseX >29 && mouseX<51 && mouseY>69 && mouseY<91) {dif=1; i=1; }
else if (mouseX >59 && mouseX<71 && mouseY>69 && mouseY<91) {dif=2; i=1;}
else if (mouseX >89 && mouseX<101 && mouseY>69 && mouseY<91) {dif=3; i=1;}
else {i=0;}
}}
if (dif!=0) {
float x = random(1,4);
int newx = int(x);
PImage im;
im = loadImage(" http://******************+str(dif)+"/"+str(newx)+".jpg");
image(im,150,150,384,216);
}
}
Or if you have other ideas... I am desperate, i need to finish it in a short while!
Well, thank you in advance !
1