init(); //this runs only on load - once
function init():Void
{
vr = 5;
thrust = 0.2;
vx = 0;
vy = 0;
left = 0;
right = Stage.width;
top = 0;
bottom = Stage.height;
bounce = -0.7;//when it bounces, this absorbs three tenths of the speed
ship = attachMovie("ship", "ship", 0);
ship._xscale = ship._yscale = 55;
ship._x = Stage.width / 2;
ship._y = Stage.height / 2;
ship.greenflame._visible = false;
ship.redflame._visible = false;
ship.yellowflame._visible = false;
score = 0;
helper._visible = false;//hides the help movie clip on load
launchhelp.onRelease = function ()
{
helper._visible = true;//shows the help mc on click
}
helper.helpclose.onRelease = function()
{
helper._visible = false;
}
}
function onEnterFrame():Void// this onEnterFrame function fires 20 times a second. There is only one frame in this movie.
{
if(Key.isDown(Key.RIGHT)){
ship._rotation -= vr;//ship._rot = ship._rot minus vr(5)
ship.greenflame._visible = true;//shows the green flame on press of right arrow on keyboard
}
else
{
ship.greenflame._visible = false;
}
if (Key.isDown(Key.LEFT))
{
ship._rotation += vr;
ship.redflame._visible = true;
}
else
{
ship.redflame._visible = false;
}
if(Key.isDown(Key.UP)){ //this fires the rocket motor
var radians:Number = ship._rotation * Math.PI / 180;
var ax:Number = Math.cos(radians) * thrust;//this it trigonometry, there are 3.14 (pi) radians in 180 degrees
var ay:Number = Math.sin(radians) * thrust;
vx += ax;//vx is the velocity in the x direction
vy += ay; //vy is velocity in the y direction
ship.yellowflame._visible = true;
score = score + 1;// adds one to the score every 1/20th second
}
else
{
ship.yellowflame._visible = false;
}
ship._x += vx;
ship._y += vy;
//begin bounce off walls code
if(ship._x + ship._width / 6 > right) //meaning it's bumped into the right edge of the stage, I divide by six to make it not sink in before the bounce
{
ship._x = right - ship._width / 6;//this snugs it right to the edge of stage
vx *= bounce;//reverses direction of rocket by multiplying it by bounce variable = -0.7, which also absorbs one third velocity
score = score - 20;//penalize for hitting walls
/*
turns the positive speed & velocity (vx) from positive
to negative (reverses direction of rocket[makes it bounce])
*/
}
else if (ship._x - ship._width / 6 < left)
{
ship._x = left + ship._width / 6;
vx *= bounce;
score = score - 20;//penalize for hitting walls
}
if(ship._y + ship._height / 6 > bottom)
{
ship._y = bottom - ship._height / 6;
vy *= bounce;
score = score - 20;

}
else if (ship._y - ship._height / 6 < top)
{
ship._y = top + ship._height / 6;
vy *= bounce;
score = score - 20;
}
}