### 123mylist.com

##### Basic Pong Game using Processing Language

Last Week, I visited my cousin and saw her playing the “Pong Game” in her handheld video gaming device. Looking at her excitement, I too wanted to play that game and ended up programming that game in my Laptop using “Processing” programming language.

The program was simple enough but the adventure of programming was exciting. So, I thought of sharing the game codes with everyone.

In this game, the task of the player is to prevent the ball from falling down by obstructing the path of the ball using the paddle. This is similar to the physical game of Table Tennis. Currently this is basic Pong having paddle on one side. Soon I will try to update this game by providing players on both sides which is called “Advanced Ping Pong”.

You can see the snapshot of the game below:

 Screen Shot of Pong Game Window

The code for this game programmed using Processing language is given below:

``````
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;
}
``````
You can also download the full source code and executable application (.exe for windows) from this link.

Update: (21st of December 2013)

I have updated my program to make it a 2 paddle based game and added little colour for good looks. The updated game screenshot can be seen below:

 Pong Version 2