void setup () {
size(700,500);
frameRate (40);
//background(200,100,200);
}
boolean key1=true;
boolean going=true;
int k = 0;
int l = 0;
int x = 0;
int y = 0;
void draw () {
background(200,100,200);
podRacer ();
obstacleOne ();
obstacleTwo ();
obstacleThree ();
Podcontrol ();
if(x==y || y==x)
l=l+0;
}
void Podcontrol () {
if(key1){
if(keyPressed)
if(key=='w' && y > 0){
y=y-5;
}
}
if(key1==true)
if(keyPressed)
if(key=='s' && y < 450){
y=y+5;
}
}
void obstacleOne () { //top of window...makes rectangluar obstacles
l=l-1;
for(int b=300;b<2000;b+=600)
for(int a=0;a<2000;a+=600)
if( a <200 )
rect(b+l,a,20,200);
}
void obstacleTwo () { //Bottom of window...makes rectangular prisms
l=l-1;
for(int b=400;b<2000;b+=600)
for(int a=0;a<2000;a+=600)
if( a <600)
rect(b+l,a+400,20,200);
}
void obstacleThree () { //middle of window...makes rectangular prisms
l=l-1;
for(int b=0;b<2000;b+=600)
for(int a=0;a<2000;a+=600)
if( a <400)
rect(50+b+l,a+180,20,200);
}
void podRacer () {
fill(200,100,100);
strokeWeight(3);
line(x+50,y+10,x+100,y+10);
line(x+50,y+40,x+100,y+40);
rect(x+50,y+0,20,50);
rect(x+100,y+10,20,50);
}
Some context would help a lot here. What platform are you using?
1 Like
i am using "processing 3.3.6
Sorry, does not compute.
Are you on sololearn?
You would need to set a game state variable, check the game state as part of the main game loop, and run a game_over function when the game over state is reached that blits your “GAME OVER” text to the canvas.
I did this with the ‘enum’ in Java, not sure what the processing.js equivalent is.
If I am not mistaken, the current version is called p5.js.
For games in JavaScript, I would be more inclined to use phaser.js