You are on page 1of 23

Pong Game

To protect the ball bouncing in your wall is one of the mechanics of this game. By controlling
the paddle which will block the ball pass through the wall using the left and right arrow keys.
Also featured in this game is the random movement of the computer paddle which will move
accordingly after the ball movements.

Stage Size and Background

Procedure:

1. Open new Adobe Flash Animation CS6 project actionsrcipt 2.0.


2. Set the size of the stage at the menu bar, click modify and select document. Changing
the size of the stage into 400px width and 600px height also change the frame rates into
30fps.

See Figure:

3. Import the following files to be needed to accomplish this click game project. Go to menu
bar click file choose import and select import to library and look for the save file in your
computer the downloaded materials to be needed. All imported files stored in the library.
See Figure:

Then:
4. Change the layer 1 name into background then drag and drop the background cover
from the library to the stage. The picture is already edited using adobe photoshop
following the size of the stage must be fit and cover the whole stage. Add your name,
grade level, and section using a text tool. Follow shown on the figure below.

See Figure:
Adding Wall

1. Lock the background layer and add a new layer named it “Wall”. Cover the whole
side of the stage with a wall to stop the ball. Use a rectangle tool to create wall
objects.

o Right Wall:

Then:
o Left Wall:

Then:
o Top Wall:

Then:
o Bottom Wall:

Then:
Ball

1. Lock the wall layer and create a new layer and name it “Ball”. Drag and drop the ball
object from the library to the center of the stage as a starting point when the ball
moves. Convert the object into a movie clip with the symbol name of “ball mc” and
the registration point is in the middle. Assign the instance name “ball_mc”. 

See Figure:
 

Then:

2. To add effect to the ball, go inside the sub-timeline by double clicking on the object.
On frame 20 right click and select insert keyframe, then in the middle of the action
frame right click and select create classic tween. Go to the properties and change
the tweening setting. See the figure below. Press “Ctrl+Enter” to test if the rotation is
enough, adjust until you satisfy the speed of rotation. Go back to the main timeline to
resize the object. Lock the layer.

See Figure:
Then:

Then:
Paddle
1. Create another layer and name it “Paddle”. Go to the library, drag and drop the
“paddle 1” at the bottom of the stage and the “paddle 2” at the top of the stage.
Resize the paddle 1 and 2 using the properties position and size. Change the width
(W) and the height (H) of the object into W= 100 and H=25 and place in the middle.

See Figure:

Then:

Then:
2. For paddle 1:

Convert the object into a movie clip with the symbol name “paddle 1” and the instance name
is “paddle_1”.

See Figure:

Then:
3. Add the code written down below on the paddle 1 object.

Paddle 1 Codes:

onClipEvent(load)
{
speed=20;
}

onClipEvent(enterFrame)
{
if(Key.isDown(Key.LEFT))
{
_x-=speed;
}
if(Key.isDown(Key.RIGHT))
{
_x+=speed;
}
if(this.hitTest(_root.left_wall))
{
this._x+=15;
}
if(this.hitTest(_root.right_wall))
{
this._x-=15;
}
}

Note:
 The paddle 2 is controlled by the player using the left and right of the arrow keys.

See Figure:

4. For paddle 2:

Convert the object into a movie clip with the symbol name “paddle 2” and the instance name
is “paddle_2”.

See Figure:
Then:

5. Add the code written down below on the paddle 1 object.

Paddle 2 Codes:
onClipEvent(load)
{
distancex=0;
elasticityx=0;
}

onClipEvent(enterFrame)
{
distancex=this._x-this._parent.ball_mc._x;
elasticityx=elasticityx-(distancex/4);
elasticityx=elasticityx*0.1;
this._x=this._x+elasticityx;
}

Note:

 The paddle 2 is on random movement controlled by the computer.

See Figure:

Score
1. Create a new layer for the player and computer score. Rename the layer into
“Score”. Add two dynamic text with the instance name of “playerscore_text” and
“computerscore_text” respectively. Set the font embedding and check the numeral
option and click ok. Copy and paste the playerscore dynamic text and rename the
instance name to “computerscore_text”. Lock the layer.

See Figure:

Then:

Pong Game Codes


1. Add a new layer and rename it to “Codes”. On the first frame right click selection
action and type the following codes written below.

Pong Game Codes:

stop();

var score_computer=0;
var score_player=0;
computerscore_text.text=score_computer;
playerscore_text.text=score_player;
xmove=15;
ymove=15;

ball_mc.onEnterFrame=function()
{
this._x+=xmove;
this._y+=ymove;
if(ball_mc.hitTest(paddle_1))
{
ymove*=-1;
}
if(ball_mc.hitTest(paddle_2))
{
ymove*=-1;
}
if(ball_mc.hitTest(left_wall))
{
xmove*=-1;
computerscore_text.text=score_computer;
score_computer=score_computer;
playerscore_text.text=score_player;
score_player=score_player;
}
if(ball_mc.hitTest(right_wall))
{
xmove=Math.random()*-10;
computerscore_text.text=score_computer;
score_computer=score_computer;
playerscore_text.text=score_player;
score_player=score_player;
}
if(ball_mc.hitTest(top_wall))
{
ymove*=-1;
computerscore_text.text=score_computer;
score_computer=score_computer;
playerscore_text.text=score_player+1;
score_player=score_player+1;
}
if(ball_mc.hitTest(bottom_wall))
{
ymove*=-1;
computerscore_text.text=score_computer+1;
score_computer=score_computer+1;
playerscore_text.text=score_player;
score_player=score_player;
}
if(score_computer==5)
{
gotoAndStop(3);
}
if(score_player==5)
{
gotoAndStop(2);
}
}

See Figure:
And

2. Finally, on the background layer, insert key frame on frame 2 and 3. Add the
following static text “YOU WIN” and “YOU LOSE” respectively on each frame.

Note:
 If the player scores reach to 5 first, the player won.

 If the computer scores reach 5 first, the computer wins.

Frame 2:

Frame 3:
3. Press Ctrl+Enter to test if the project is working properly. If there is something wrong
with the swf kindly go back to the procedure where the error occurs and check again
if you missed any of the information. If the swf is working properly, save the project,
name it “Lastname, Firstname Pong Game Demo” and submit to our Google Drive
folder.

You might also like