Pong Game


ma7730

Screen Shot 2014-08-18 at 8.21.50 PM

This is a classic arcade game played by two individuals in a head-to-head competition. Each player controls a paddle and hits the ball back to the other player, somewhat like Ping Pong. The classic game goes from right to left but I decided to change it up and add some color. I used the Processing language to program the game. I also implemented an overlap detection algorithm. It works like this.

void checkPaddleCollision() {
if ((ballX+ballR)>paddle1X && (ballX-ballR)<paddle1X+paddleWidth) {
if (ballY+ballR>paddle1Y)  {
speedY*=-1.1; //revese ball direction

}
}
if ((ballX+ballR)>paddle2X && (ballX-ballR)<paddle2X+paddleWidth) {
if (ballY-ballR<paddle2Y+paddleHeight)  {
speedY*=-1.1;
}
}
//Prevents the paddle from going off the screen
if (paddle1X<=0) {
paddle1X=paddle1Speed;
}
if (paddle2X<=0) {
paddle2X=paddle1Speed;
}

For all the code click here.

View original post

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s