Hello, I have created a little game in progress. You can move the character in the X position and fall down from above. You have a random X position and a random speed. If you run into an obstacle, I want the Gamestate variable to be set to 0 and die. I am new at Processing and do not know how to do that, can someone help me please?
Here is my code:
PImage bg,bg1,P1,fb;
int gamestate = 0;
int x,fbx, fby = - 200;
int speed = 5;
int score = 0 ;
int hgt = height;
int maus;
void setup()
{
//size(displayWidth,displayHeight);
size(600, 900);
orientation(PORTRAIT);
bg = loadImage("bgw.png");
bg1 = loadImage("bg1.jpg");
P1 = loadImage("P1.png");
fb = loadImage("fb.png");
imageMode(CENTER);
fbx = (int)random(0, width);
textSize(32);
hgt = height;
}
void draw()
{
maus = mouseX;
//TEST IF MOUSE IS CLICKING
if (mousePressed){
gamestate = 1;
}
else {
gamestate = 0;
}
//x = width/2;
// START SCREEN
fby += speed;
if(gamestate == 0) {
image(bg1, width/2,height/2,width,height);
fby = -200;
score = 0;
fbx = (int)random(0, width);
}
//MAIN GAME
else {
background(22, 22, 22);
//if(fby == height) {
if(fby > hgt) {
speed = 5;
fbx = (int)random(0, width);
fby = -200;
speed = (int)random(10, 20);
}
image(P1, mouseX, height/8*6,width/4,height/4); // Images are 1920 by 1080
image(fb, fbx,fby,width/3,height/3);
text(maus, 300,800);
score += 1;
}
//Try to make a game over funktion but its not working :(
if (maus < fbx && x == gamestate) {
gamestate = 0;
}
}