Pong

I started with Pong that I got from a site: http://www.123mylist.com/2013/12/basic-pong-game-using-processing.html

I t was pretty great so I practiced for a while. Below is the code for the basic. Once I had my fill, I started changing the different parameters. First I had to understand what the deal was so I added comments and then changed things.

FYI – this is the most addicting thing ever!

int base=40;
int x,y,gameScore=0;
int changeX=-5;
int changeY=-5;
int gameOver=0;
void setup()
{
size(760, 640);
x=(int)random(width);
y=height-base;
}
void draw()
{
if(gameOver==0)
{
background(0);
text(“SCORE:”+gameScore+”00”,width/2,height/2);
rect(mouseX,height-base,200,base);
ellipse(x,y,10,10);
x=x+changeX;
y=y+changeY;
if(x<0 | x>width)
{
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++;

}
else
{
gameOverSplash();
}
}
}
else
{
background(100,100,200);
text(“Game Over!”,width/2,height/2);
text(“CLICK TO RESTART”,width/2,height/2+20);
}
}
void gameOverSplash()
{
gameOver=1;
}
void mouseClicked()
{
changeY=-changeY;
gameScore=0;
gameOver=0;

}

Comments are closed.