Headshotz
11-15-2005, 09:47 AM
Hello,
I know alot of beginners want to know how to make pong. I wrote
a full remake from scratch and I just need someone to turn it into
a tutorial. Thanks to vengeance from sfdt for finsing the deathbug.
//**********
//CODE BY: Headshotz
//TUTORIAL WRITTEN BY: Yourusername
//THANKS TO: Vengeance from for finding that bug
//SUBJECT: Classic game
//NAME: Pong!
//**********
//++++++++++
//STAGE 1 - DRAW EVERYTHING WITH ACTIONSCRIPT
//++++++++++
//Start by drawing and filling the background
createEmptyMovieClip("background1", 0);
background1.beginFill(0x000000, 100);
background1.lineTo(0, 0);
background1.lineTo(550, 0);
background1.lineTo(550, 400);
background1.lineTo(0, 400);
background1.lineTo(0, 0);
//Now time for the left paddle
createEmptyMovieClip("Left", 1);
Left.beginFill(0xFFFFFF, 100);
Left.lineTo(0, 0);
Left.lineTo(11, 0);
Left.lineTo(11, 34);
Left.lineTo(0, 34);
Left.lineTo(0, 0);
//Now we align it
Left._x = 40;
Left._y = (200-34);
//Now the Right paddle
createEmptyMovieClip("Right", 2);
Right.beginFill(0xFFFFFF, 100);
Right.lineTo(0, 0);
Right.lineTo(11, 0);
Right.lineTo(11, 34);
Right.lineTo(0, 34);
Right.lineTo(0, 0);
//Now we align it to the right
Right._x = 499;
Right._y = (200-34);
//Now we have our paddles drawn and aligned we can move onto the ball
createEmptyMovieClip("Ball", 3);
Ball.beginFill(0xFFFFFF, 100);
Ball.lineTo(0, 0);
Ball.lineTo(11, 0);
Ball.lineTo(11, 11);
Ball.lineTo(0, 11);
Ball.lineTo(0, 0);
//Ok, now we position it
Ball._x = (275);
Ball._y = (200);
//Things might look a bit out of alignment but they fix up when we start the game code!
//Finish stage 1
//++++++++++
//SATGE 2 -- MAKING THE GAME
//++++++++++
//Set the 'reset' function
function reset() {
Ball._x = 275;
Ball._y = 200;
xspeed = 0;
yspeed = 0;
extraspeed = 0;
notmoving = true;
}
reset();
//Begins the game when you click the mouse
onMouseDown = function () {
if (notmoving == true) {
notmoving = false;
xspeed = -2;
yspeed = -2;
extraspeed = 2;
}
};
//Sets function for ball
function playball() {
this._x += xspeed;
this._y += yspeed;
if (this.hitTest(Left)) {
xspeed = 2+extraspeed;
extraspeed += .333;
}
if (this.hitTest(Right)) {
xspeed = -2-extraspeed;
extraspeed += .333;
}
if (this._y>393.5) {
yspeed = -2-extraspeed;
}
if (this._y<6.5) {
yspeed = 2+extraspeed;
}
if (this._x<0) {
reset();
}
if (this._x>550) {
reset();
}
}
//Sets fuction for player (Right)
function playpong() {
this._y += (_ymouse-this._y-(this._height/2))*0.3;
}
//Sets function for AI (Left)
function challenge() {
this._y += (Ball._y+(Ball._height/2)-this._y-(this._height/2))*0.22;
}
//Finish Stage 2
//++++++++++
//STAGE 3 -- EXECUTING EVERYTHING
//++++++++++
Ball.onEnterFrame = playball;
Left.onEnterFrame = playpong;
Right.onEnterFrame = challenge;
//Finish Stage 3
//Finish Code
I know alot of beginners want to know how to make pong. I wrote
a full remake from scratch and I just need someone to turn it into
a tutorial. Thanks to vengeance from sfdt for finsing the deathbug.
//**********
//CODE BY: Headshotz
//TUTORIAL WRITTEN BY: Yourusername
//THANKS TO: Vengeance from for finding that bug
//SUBJECT: Classic game
//NAME: Pong!
//**********
//++++++++++
//STAGE 1 - DRAW EVERYTHING WITH ACTIONSCRIPT
//++++++++++
//Start by drawing and filling the background
createEmptyMovieClip("background1", 0);
background1.beginFill(0x000000, 100);
background1.lineTo(0, 0);
background1.lineTo(550, 0);
background1.lineTo(550, 400);
background1.lineTo(0, 400);
background1.lineTo(0, 0);
//Now time for the left paddle
createEmptyMovieClip("Left", 1);
Left.beginFill(0xFFFFFF, 100);
Left.lineTo(0, 0);
Left.lineTo(11, 0);
Left.lineTo(11, 34);
Left.lineTo(0, 34);
Left.lineTo(0, 0);
//Now we align it
Left._x = 40;
Left._y = (200-34);
//Now the Right paddle
createEmptyMovieClip("Right", 2);
Right.beginFill(0xFFFFFF, 100);
Right.lineTo(0, 0);
Right.lineTo(11, 0);
Right.lineTo(11, 34);
Right.lineTo(0, 34);
Right.lineTo(0, 0);
//Now we align it to the right
Right._x = 499;
Right._y = (200-34);
//Now we have our paddles drawn and aligned we can move onto the ball
createEmptyMovieClip("Ball", 3);
Ball.beginFill(0xFFFFFF, 100);
Ball.lineTo(0, 0);
Ball.lineTo(11, 0);
Ball.lineTo(11, 11);
Ball.lineTo(0, 11);
Ball.lineTo(0, 0);
//Ok, now we position it
Ball._x = (275);
Ball._y = (200);
//Things might look a bit out of alignment but they fix up when we start the game code!
//Finish stage 1
//++++++++++
//SATGE 2 -- MAKING THE GAME
//++++++++++
//Set the 'reset' function
function reset() {
Ball._x = 275;
Ball._y = 200;
xspeed = 0;
yspeed = 0;
extraspeed = 0;
notmoving = true;
}
reset();
//Begins the game when you click the mouse
onMouseDown = function () {
if (notmoving == true) {
notmoving = false;
xspeed = -2;
yspeed = -2;
extraspeed = 2;
}
};
//Sets function for ball
function playball() {
this._x += xspeed;
this._y += yspeed;
if (this.hitTest(Left)) {
xspeed = 2+extraspeed;
extraspeed += .333;
}
if (this.hitTest(Right)) {
xspeed = -2-extraspeed;
extraspeed += .333;
}
if (this._y>393.5) {
yspeed = -2-extraspeed;
}
if (this._y<6.5) {
yspeed = 2+extraspeed;
}
if (this._x<0) {
reset();
}
if (this._x>550) {
reset();
}
}
//Sets fuction for player (Right)
function playpong() {
this._y += (_ymouse-this._y-(this._height/2))*0.3;
}
//Sets function for AI (Left)
function challenge() {
this._y += (Ball._y+(Ball._height/2)-this._y-(this._height/2))*0.22;
}
//Finish Stage 2
//++++++++++
//STAGE 3 -- EXECUTING EVERYTHING
//++++++++++
Ball.onEnterFrame = playball;
Left.onEnterFrame = playpong;
Right.onEnterFrame = challenge;
//Finish Stage 3
//Finish Code