# Proccessing Game Over funktion

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);
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;
}
}
``````
1 Like

I think one of the main issues is how the gameState variable is controlled by the mouse. Youâ€™re gonna get a lot of interference from the mouse if gameState is always set to 1 when the mouse is pressed

maybe move this code to void mousePressed() where it doesnâ€™t check every frame?

also I donâ€™t have your imagesâ€¦ maybe convert to them rect() whenever you post code

1 Like

The Problem of puting the Code in the "if (mousePressed){ " is that you canÂ´t die. Whenever you are pressing the mouse the game will keep runing. Thats why I created the gamestate variable.

Okay. Well as long as the game is running the player will never be able to die, since gameState will always be equal to 1

also the code

``````if (maus < fbx && x == gamestate) {
gamestate = 0;
}
``````

will never run since you havenâ€™t set x equal to anything

I think adding this code to the end will fix one of your problems

``````void mousePressed(){
gamestate=1;
}
``````

this is the code that causes your player to never die

``````if (mousePressed){
gamestate = 1;
}
else {
gamestate = 0;
}
``````
1 Like