
pROJECT pong o pong


This is the very first game that I have created. In this game, I have implemented some interesting features in the gameplay.
Paddle Movement
1. First of all, this Pong game is no ordinary Pong game. Player have to control not one but two paddles.
Player One will control the orange-coloured paddles.
Player Two will control the blue-coloured paddles.
The picture above shows the movement for the vertical orange-coloured paddle.
This piece of code also acts as boundary so that the paddle wont move out of the screen.
The logic is: If [ y-coordinate of my paddle ] is greater [ any y- coordinate on screen ]
Move the paddle to a higher position.
So, if the y-coordinate of my paddle is smaller than the input value. The paddle will not move up.
The same logic goes to the other movements such as down, left and right.
Ball Bounce
2. Now, the paddles are moving. The second thing we need to do is make the ball bounce whenever it hits a paddle. However, I encountered a problem.
The problem is if the ball is bounced back perpendicular to the paddle, the ball will bounce
back and forth endlessly. However, after a day brainstorming and Googling. The solution to the problem is pretty simple.
The picture above shows the ball bounce mechanic on the vertical orange-coloured paddle..
The logic is: If the ball hits the upper part of the paddle. A force will apply on the ball to push the
ball gently towards 90 degrees / upwards.
If the ball hits the lower part of the paddle. A force will apply on the ball to push the
gently towards 270 degress / downwards.
Using this way, the ball will not bounce back and forth perpendicular forever.
For the Bounce , this is basically a delay ( the 0.05 seconds ) set for the ball to leave the paddle when it bounces off the paddle. If this piece of code is absent the ball will jiggle on the paddle.
Powerup Mechanic
3. To spice things up, the third to add is powerups. The powerup mechanic is the toughest part to create for this game because it involves multiple objects.
In this game, 1 out of 3 powerups will spawn at the middle of the court. The 3 powerups are:
a. Ball Enlarge
The picture above shows when the ball hits the powerup and the effects of it.
The logic is: When the ball hits the powerup, the ball will enlarge to 2x of its size and then
remove the powerup icon. After 20 seconds, the ball will return to its normal size.
For the BallEnlargeIdentifier, it acts as a trigger for the effect.
The PowerupBoolean is use to ensure only 1 powerup is activated at a time.
b. Paddle Enlarge
The picture above shows when the ball hits the powerup and the effects of it.
The logic is: When the ball hits the powerup, the player who hit the ball to the powerup will have
his paddle enlarge in terms of length or width depending on the position of the
paddle. After 10 the paddles will return to its normal size.
However, a problem arised. How to determine who is the last player to hit the ball to the powerup?
There are 3 possible conditions when ball hits the powerup:
1. At the beginning of the stage, when no player hit the ball before.
2. When player 1 hit the ball
3. When player 2 hit the ball
Having brainstormed for an hour or so, I have figured out to use a BallPossession number
attribute to solve this problem.
The logic is: The BallPossession is originally set to 0. So, if the ball hits the powerup at the
beginning of the stage, nothing happens. When player 1 hits the ball, BallPossession
will set to 1, effects will apply on player 1. If player 2 hits the ball, BallPossession
will set to 2, effects will apply on player 2.
c. 1Up
The picture above shows when the ball hits the powerup and its effects.
The logic is: When the ball hits the powerup, minus the opponent's score based on the value of
BallPossession.
Demon Ball
The last mechanic that I am going to present is the Demon Ball Mechanic. This mechanic causes
the ball to transform into a Demon Ball and whoever scores it will gain 2 points.
The picture above shows the processes of Demon Ball mechanic.
I have create a BounceCounter to keep track of how many times the ball have bounced off a paddle.
The logic is: If the BounceCounter < 6, whoever player scores it will gain 1 point as usual.
However, if the BounceCounter > 5, whoever player scores it will gain 2 points.
When the ball is scored, the attributes will be resetted by setting all of them to 0.





