Contents /
Previous /
Next
Example
The
Ball
Class
class Ball extends MovieClip
{
var xscale:Number = 100;
var yscale:Number = 100;
var x:Number = 100;
var y:Number = 100;
.....
function Ball( swfFileBase, baseDepthLevel )
{
_root.createEmptyMovieClip( swfFileBase, baseDepthLevel );
this.prototype = _root[ swfFileBase ];
// Load movieClips with a loader.
var mcl:MovieClipLoader = new MovieClipLoader();
mcl.loadClip( swfFileBase+".swf", _root[ swfFileBase ] );
}
function move()
{
// Random momentum move.
...
}
function die()
{
this.prototype._visible = false;
}
}
class FadeBerry extends Ball
{
function FadeBerry( swfFileBase, baseDepthLevel )
{
super( swfFileBase, baseDepthLevel );
x = 100;
y = 300;
xscale = 250;
yscale = 250;
}
function die()
{
this.prototype._alpha -= 0.25;
}
}
class DisBerry extends Ball
{
function DisBerry( swfFileBase, baseDepthLevel )
{
super( swfFileBase, baseDepthLevel );
x = 400;
y = 400;
xscale = 250;
yscale = 250;
}
function die()
{
xscale -= 1;
yscale -= 1;
if( xscale < 0 ) xscale = 0;
if( yscale < 0 ) yscale = 0;
}
}
class Engine
{
var world:World = null;
var ball:Ball = null;
var disBerry:DisBerry = null;
var fadeBerry:FadeBerry = null;
var time:Number = 0;
function Engine()
{
world = new World( "World_blank", 100 )
ball = new Ball( "ball", 1000 );
disBerry = new DisBerry( "disBerry", 1010 );
fadeBerry = new FadeBerry( "fadeBerry", 1020 );
// Start loop.
time = 0;
// Time in milisec.
setInterval( this, "updateLoop", 20 );
}
function updateLoop()
{
time ++;
if( time <= 200 ) {
world.drawTimeBar( time / 2 );
} else {
ball.die();
disBerry.die();
fadeBerry.die();
}
// Move objects.
ball.move();
disBerry.move();
fadeBerry.move();
// Show.
updateAfterEvent();
}
}
class World extends MovieClip
{
function World( swf_file, baseDepthLevel )
{
_root.createEmptyMovieClip( swf_file, baseDepthLevel );
this.prototype = _root[ swf_file ];
var mcl = new MovieClipLoader();
mcl.loadClip( swf_file+".swf", _root[ swf_file ] );
// Display time and score.
_root.createEmptyMovieClip( "inGameDisplay", baseDepthLevel+ 200 );
}
function drawTimeBar( percentLeft:Number )
{
//trace("percentLeft:"+percentLeft);
// World size is 130x40.
_root["inGameDisplay"].clear();
//
// Time line.
_root["inGameDisplay"].lineStyle( 20, 0xcc0000, 15 );
_root["inGameDisplay"].moveTo( 680, 500);
_root["inGameDisplay"].lineTo( 680, 150 );
//
_root["inGameDisplay"].lineStyle( 20, 0xcc0000, 80 );
_root["inGameDisplay"].moveTo( 680, 500 );
_root["inGameDisplay"].lineTo( 680, 500 - 3.5 * percentLeft );
}
}