We are about to switch to a new forum software. Until then we have removed the registration on this forum.
PImage startscreen; int startscreen; int stage; int base=20; int x,y; int hit = 0; int miss = 0; int changeX=-5; int changeY=-5; int gameOver=0;
void setup(){
stage = 1;
startscreen = LoadImage("2teniscourt.jpg");
img(startscreen,0,0,600,600);
size(600, 600);
x=(int)random(width);
y=height-base;
}
void draw()
{
if(stage==1){
image(startscreen,600,600);
textAlign(CENTER);
textSize(45);
fill(66, 104, 244);
text("PONG GAME",100,170);
text("Press any key to start",100,170);
if (keyPressed == true){
stage = 2;
}
}
if (stage == 2){
background(100,200,100);
}
if(gameOver==0)
{
background(0);
fill(244, 66, 66);
text("hit: " + hit,50,40);
fill(66, 104, 244);
rect(mouseX,height-base,150,base);
ellipse(x,y,40,40);
x=x+changeX;
y=y+changeY;
if(x<0 | x>width)
{
changeX=-changeX;
}
if(y<0)
{
changeY=-changeY;
}
if(y>height-base)
{
//check if it is falling inside the screen or not
if(x>mouseX && x<mouseX+200)
{
changeY=-changeY; //bounce back
hit +=1;
}
else
{
gameOverSplash();
}
}
}
else
{
background(244, 78, 66);
fill(66, 104, 244);
text("Game Over!",width/2,height/2);
text("CLICK MOUSE TO RESTART",width/2,height/2+20);
}
}
void gameOverSplash()
{
gameOver=1;
}
void mouseClicked()
{
changeY=-changeY;
hit +=1;
gameOver=0;
}
Answers
you need to format the code for the fourm
edit your post, highlight the code, press ctrl-o
duplicate
@Chrisir, don't only scream "duplicate"; but please, provide along the link as well; so the thread can be closed and folks know where to go instead: :-@
https://forum.Processing.org/two/discussion/20024/urgent-please-i-want-to-create-a-startscreen-for-my-pong-game-what-am-i-doing-wrong