We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I've created a simple maze game. I'm trying to get it so after you reach the designated checkpoint and beat the first level, it loads the next picture and you start the next level. If anyone could help me that would be great. (P.S. the green square on the left is the checkpoint, the one on the right is just to throw people off).
PImage Maze;
PImage Maze2;
PImage Maze3;
int page = 1;
final int maxlevel = 3;
int x = 15;
int y = 40;
void setup()
{
Maze = loadImage("Maze design 1.png");
Maze2 = loadImage("Maze Design 2.png");
Maze3 = loadImage("Maze Design 3.png");
size(640,480);
}
void draw(){
image(Maze,0,0);
if((x > 111) && (x < 131) && (y > 250) && (y < 270))
if(page==1) {
textSize(48);
textAlign(CENTER);
fill(250,0,0);
text("YOU WIN!",width/2,height/2);
}
fill(250,0,0);
noStroke();
float touch = red(get(x,y));
ellipse(x,y,10,10);
fill(0, 250, 0);
stroke(0);
rect(320,110,20,20);
rect(111,250,20,20);
if(touch <= 200)
{
x = 15;
y = 40;
}
println(mouseX + "," + mouseY);
}
void keyPressed(){
if((key == CODED) && (keyCode == UP))
{
y-=20;
}
if((key == CODED) && (keyCode == DOWN))
{
y+=20;
}
if((key == CODED) && (keyCode == RIGHT))
{
x+=20;
}
if((key == CODED) && (keyCode == LEFT))
{
x-=20;
}
}
Answers
you already have a var page
in the forum it is often called state
the idea is that draw() runs 60 times per second so you need a way to tell whether you want to display the message you won or loose or a Maze. The var page tells you what to do.
to do so in draw() say
for the maze 0,1,2 I recommend a second similar var mazeNumber
now in case 0: above say
so when the maze is finished
mazeNumber++;
andpage=1;
so when keyPressed in page 1 say
page = 0;
Thank you, I will give this a try
in fact you need the same thing you have in draw in keyPressed as well
i would define constants for each state because 0, 1, 2, 3, 4 are meaningless.
Thank you both for your imput, it's really helped