Wednesday, September 19, 2012

Pong Mod - Individual Project

For my individual Pong mod, I created a field of red and blue circles between the two paddles.  The paddles are also now colored either red or blue.  Clicking the mouse changes the player one paddle color.  Pressing the alt key changes the paddle two color if playing in two player mode.  As the ball passes through the circles it takes on the color of the circles.  The paddle must be the same color as the ball in order to deflect it.  If the paddle is a different color from the ball, the ball simply passes through it. 

Click here to play this Pong mod.  

The circles are randomly generated using code similar to the randomly generated squares from the group Pong mod.  Where I used one for loop to generate a line of squares, here I used two for loops to create a grid of circles.  Plugging randomly generated numbers into the for loops breaks up the grid into a more interesting mess of circles. 

Unlike the squares (which were hidden for a time and then revealed with a new random color), the circles are destroyed when the ball passes through them.  The destruction of a circle triggers another piece of code that creates a new circle after a few seconds in a random place.  The reason for the two different methods is that I wanted to squares to always appear in the same line, and the circles to be more unpredictable.  Not destroying the squares was the easiest way to store the screen position.  Since nothing of the original circle would be needed for the regenerated circle, it made sense to just destroy the original and create a new one.

Mod game logic:

  • Same rules as regular pong plus below
  • Circles pass their color on the ball
    • Circle disappears
    • New circle appears after a few seconds
  • Players can switch between two paddle colors
  • If the paddle and ball colors match, the ball is deflected
  • If the paddle and ball colors do not match, the ball passes through the paddle



No comments:

Post a Comment