I have made a pong simulator game. I added a circle as a target but need to make it so that when the ball hits the target, the player wins and the game restarts. Help!!!
PImage dragon;
PFont font;
int base=40;
int x,y,gameScore=0;
int changeX=-5;
int changeY=-5;
int gameOver=0;
boolean win;
void setup(){
size(760, 640);
dragon = loadImage(“dragon.jpg”);
// x=(int)random(width); //x for the ball
x = width/2;
y = height/2;
//y=height-base; // y for the ball
font = loadFont (“HelveticaNeue-CondensedBlack-48.vlw”);
textFont(font);
win = false;
}
void draw(){
if(gameOver==0)
{
background(0);
image(dragon,0,2, 760, 640);
ellipse (200,200,50,50);
// target
if(win == true){
background(28,155,35);
textSize(26);
text(“YOU WIN!”,380,320);
textSize(26);
text(“CLICK TO RESTART”,380,320+20);
}
if( x > (200 - 100) &&
x < (200 + 100) &&
y > (200 + 100) &&
y == (200 + 100)
){
win = true;
}
//game score
text(“SCORE:”+gameScore+“00”,width/2,height/2);
// make the rectangle move with the mouse
rect(mouseX,height-base,200,base);
ellipse(x,y,10,10);
x=x+changeX; // x change
y=y+changeY; //y change
if(x<0 | x>width) //if x is less than 0
{
changeX=-changeX;
}
if(y<0)
{
changeY=-changeY;
}
if(y>height-base)
{
//check whether it is falling inside the rectangle or not
if(x>mouseX && x<mouseX+200)
{
changeY=-changeY; //bounce back
gameScore++; // if the ball bounces back off the rectangle, the gamescore goes up
}
else
{
gameOverSplash(); // if the ball misses the rectangle, game over
}
}
}
else
{
background(#A71627);
textSize(26);
text(“GAME OVER”,380,320);
textSize(26);
text(“CLICK TO RESTART”,380,320+20);
}
}
void gameOverSplash()
{
gameOver=1;
}
void mouseClicked()
{
changeY=-changeY;
gameScore=0;
gameOver=0;
}
void mousePressed(){
println(mouseX, mouseY);
}