Project+Pong

Here is //our// first project:

Here is how a project works: You need to start to participate by and sharing ideas!! Sharing ideas will allow us, as a whole, to understand the project in detail and also allow us to break down the project step by step. Coding is not a 1 step process and good coding requires good planning. Once we have a plan then we can make it at school to be efficient with our time.

=Pong=

What exactly is Pong? This is Pong media type="youtube" key="LPkUvfL8T1I?fs=1" height="306" width="383"

What are the components in Pong? - 2 paddles controlled by user(s) - a ball that bounces off walls and paddles - a boundary (on the top and bottom for the ball to ricochet off

What are the game's objectives? - to get the ball past the enemy's paddle

Questions you should be asking: - How do we detect collisions? code if (this.hitTest(_root.otherObject)) { //this code is executed when this object hits the other movie clip called "otherObject" }

code - How does the ball move like that?

You need to use trigonometry. What is that?

sine (z) = opposite / hypotenuse cosine (z) = adjacent / hypotenuse tangent (z) = opposite / adjacent

In terms of programming: Math.sin (z) = y / velocity Math.cos (z) = x / velocity Math.tan (z) = y / x

Think about this.

- What mathematical formulas should we use to create that trajectory?

After searching Google for other versions of Pong on Flash, I found out that they are all of lower quality so here is what I interpret Pong as:

media type="file" key="aiPongv3.swf" width="360" height="270"
 * impossible-to-win version*

Use the up and down arrow keys to move the green paddle. The red paddle is the AI (artificial intelligence). Click on the ending message to repeat.

Here is an example of 2 AI controlled players. Brilliant programming huh?

media type="file" key="aiVSaiPong.swf" width="360" height="270"

Click on the ending message to repeat.

=Here is how you make Pong (2 human players / no AI)=

First you draw a paddle for one player on the side of the screen. Make it into a movie clip and paste in the following code. code onClipEvent (load) { this._x = 50; this._y = 200; } onClipEvent (enterFrame) { if (Key.isDown(87)) {//W this._y -= 4; }    if (Key.isDown(83)) {//S this._y += 4; }    if (this.hitTest(_root.ball)) { _root.ball._x += _root.ball.speed; _root.ball._rotation = 90-1.5*(this._y-_root.ball._y); _root.ball.speed += 0.01*(Math.abs(this._y-_root.ball._y)); }    if (this._y<20) { this._y += 4; }    if (this._y>380) { this._y -= 4; } } code Then you draw a paddle for the second player on the right side of the screen. Make it into a movie clip and paste in the following code. code onClipEvent (load) { this._x = 500; this._y = 200; } onClipEvent (enterFrame) { if (Key.isDown(Key.UP)) { this._y -= 4; }    if (Key.isDown(Key.DOWN)) {//S this._y += 4; }    if (this.hitTest(_root.ball)) { _root.ball._x -= _root.ball.speed; _root.ball._rotation = -90+1.5*(this._y-_root.ball._y); _root.ball.speed += 0.01*(Math.abs(this._y-_root.ball._y)); }    if (this._y<20) { this._y += 4; }    if (this._y>380) { this._y -= 4; } }
 * //Set the FPS to 120.//**

code Then you draw a **small** ball in the centre of the screen. Make it into a movie clip and paste in the following code. code onClipEvent (load) { this._x = 275; this._y = 200; this._rotation = 90; speed = 1.5; if (Math.random>=0.5) { this._rotation = 90; }    if (Math.random<=0.5) { this._rotation = -90; } } onClipEvent (enterFrame) { this._y -= speed*Math.sin((90-this._rotation)/180*Math.PI); this._x += speed*Math.cos((90-this._rotation)/180*Math.PI); if (this._y<0) { this._y += speed*Math.sin((90-this._rotation)/180*Math.PI); this._x -= speed*Math.cos((90-this._rotation)/180*Math.PI); if (this._rotation>=0) { this._rotation += (90-this._rotation)*2; } else { this._rotation -= (-90+this._rotation)*2; }    } else if (this._y>400) { this._y += speed*Math.sin((90-this._rotation)/180*Math.PI); this._x -= speed*Math.cos((90-this._rotation)/180*Math.PI); if (this._rotation>=0) { this._rotation -= (-90+this._rotation)*2; } else { this._rotation += (90-this._rotation)*2; }    }     if (speed>7) { speed = 7; }    if (this._x<0) { _root.win2._x = 275; _root.win2._y = 200; _root.win2.onRelease = function { _root.win1._x = 10000; _root.win2._x = 10000; _root.ball._x = 275; _root.ball._y = 200; _root.ball._rotation = 90; _root.ball.speed = 1.5; if (Math.random>=0.5) { _root.ball._rotation = 90; }              if (Math.random<=0.5) { _root.ball._rotation = -90; }              _root.p1._x = 50; _root.p1._y = 200; _root.p2._x = 500; _root.p2._y = 200; };    } else if (this._x>550) { _root.win1._x = 275; _root.win1._y = 200; _root.win1.onRelease = function { _root.win1._x = 10000; _root.win2._x = 10000; _root.ball._x = 275; _root.ball._y = 200; _root.ball._rotation = 90; _root.ball.speed = 1.5; if (Math.random>=0.5) { _root.ball._rotation = 90; }              if (Math.random<=0.5) { _root.ball._rotation = -90; }              _root.p1._x = 50; _root.p1._y = 200; _root.p2._x = 500; _root.p2._y = 200; };    } } code Now read over the code and ask questions in the next meeting. You must name the left paddle "p2", the ball as "ball", the right paddle as "p1". You must draw 2 win messages outside of the screen. The one for player 1 victory should be named "win1" and the other one should be called "win2". FPS must be set to 120. Also, your game should look like this but the speed varies on your fps settings:

media type="file" key="basicPongv2.swf" width="360" height="270"