//--- Flash MX Pong Game 1Kb by random10122 Version 1.0
//--- Paste this code on frame 1 and set scene size to 600x300 and frame rate to 60
//--- Inspired by strille's Flash MX Snake Game 1Kb
h = 300; // Stage height
w = 600; // Stage width
// Create a border
lineStyle(1);
lineTo(w, y = m = 0); // set score variables
lineTo(w, h);
lineTo(0, h);
lineTo(0, 0);
// Create the net
lineStyle (1,null,50)
moveTo(w/2,0)
lineTo(w/2, h);
// Hide the mouse from view
mouse.hide();
// Create some score fields
createTextField("x",7,140,10,20,20); // enemys score
createTextField("z",8,440,10,20,20); // player score
// Main game function
s = function () {
with (createEmptyMovieClip("e", 2)) { // create an enemy
lineStyle(1); // create the paddle
lineTo(10, 0);
lineTo(10, 60);
lineTo(0, 60);
lineTo(0, 0);
_x = 10; // position the paddle
_y = h/2;
}
e.onEnterFrame = function() { // enemy actions
if (b._y-34 > this._y) { // move the paddle
this._y += 4;
} else if (b._y-30 < this._y) {
this._y -= 4;
}
if (b._x < this._x+10) {
if (b._y > this._y && b._y < this._y+60) { // if paddle hits ball
b.i *= -1; // reverse the ball speed
b.j = (b._y-(this._y+30))/2;
} else {
x.text = ++m; // increase score
s(); // reset the game
}
}
}
with (createEmptyMovieClip("b", 6)) { // create the ball
// draw the circle
lineStyle(1);
curveTo(5,0, 5,-5);
curveTo(5,-10,0,-10);
curveTo(-5,-10,-5,-5);
curveTo(-5,0,0,0);
// position the ball in the center
_x = w/2;
_y = h/2;
// give it a random direction and speed
if (random(3) > 1) {
b.i = 8+random(3);
} else {
b.i = -8-random(3);
}
b.j = random(4);
}
b.onEnterFrame = function() {
this._x += this.i; // move the ball according to speed
this._y += this.j;
if (this._y > h-5 or this._y < 5) { // check for boundaries and reverse direction
this.j *= -1;
}
};
// duplicate player from enemy so we dont have to draw another paddle
with(e.duplicateMovieClip("p", 1)){
_x = w-20; // position on stage
_y = _root._ymouse;
}
p.onEnterFrame = function() {
this._y = _ymouse; // move paddle with mouse
if (b._x > this._x) {
if (b._y > this._y && b._y < this._y+60) { // if paddle hits ball
b.i *= -1; // reverse direction
b.j = (b._y-(this._y+30))/2;
} else {
z.text = ++y; // increase score
s(); // reset
}
}
};
};
// Now lets start the game
s();