Section 1
//AAGun (AAGun)
package {
import flash.events.*;
import flash.display.*;
public class AAGun extends MovieClip {
var speed:Number;// = 5
public function AAGun(){
speed = 5;
super();
this.x = 275;
this.y = 200;
addEventListener(Event.ENTER_FRAME, moveGun);
}
public function moveGun(_arg1:Event){
var _local2:*;
var _local3:*;
_local2 = this.x;
_local3 = this.y;
if (MovieClip(parent).A_Button){
_local2 = (_local2 - speed);
};
if (MovieClip(parent).D_Button){
_local2 = (_local2 + speed);
};
if (MovieClip(parent).W_Button){
_local3 = (_local3 - speed);
};
if (MovieClip(parent).S_Button){
_local3 = (_local3 + speed);
};
if (_local2 < 10){
_local2 = 10;
};
if (_local2 > 540){
_local2 = 540;
};
if (_local3 < 20){
_local3 = 20;
};
if (_local3 > 380){
_local3 = 380;
};
this.x = _local2;
this.y = _local3;
}
}
}//package
Section 2
//Asteroid (Asteroid)
package {
import flash.events.*;
import flash.display.*;
public class Asteroid extends MovieClip {
private var canStartAsteroid;// = true
private var vx:Number;
private var vy:Number;// = -400
public function Asteroid(){
vy = -400;
canStartAsteroid = true;
super();
init();
}
private function init():void{
this.y = (this.y + vy);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function resetAsteroid():void{
this.y = ((Math.random() * -100) - 100);
this.x = (Math.random() * 550);
vy = ((Math.random() * 2) + 4);
}
public function startAsteroid():void{
if (canStartAsteroid == true){
this.x = (Math.random() * 550);
this.y = ((Math.random() * -100) - 100);
vy = ((Math.random() * 2) + 4);
canStartAsteroid = false;
};
}
private function onEnterFrame(_arg1:Event):void{
if (canStartAsteroid == false){
this.y = (this.y + vy);
};
if ((this.y - 50) > stage.stageHeight){
this.y = ((Math.random() * -400) - 100);
this.x = (Math.random() * 550);
vy = ((Math.random() * 2) + 4);
canStartAsteroid = true;
};
}
}
}//package
Section 3
//Bullet (Bullet)
package {
import flash.events.*;
import flash.display.*;
public class Bullet extends MovieClip {
private var myBulletRotation:Number;// = 0
private var deltaY;
private var deltaX;
private var bulletMoving:Boolean;// = false
public function Bullet(){
bulletMoving = false;
myBulletRotation = 0;
super();
init();
}
public function startBullet(_arg1, _arg2, _arg3, _arg4, _arg5:Number):void{
if (bulletMoving == false){
this.x = _arg1;
this.y = _arg2;
deltaX = _arg3;
deltaY = _arg4;
myBulletRotation = _arg5;
this.rotation = myBulletRotation;
bulletMoving = true;
};
}
public function init():void{
this.x = 150;
this.y = 600;
addEventListener(Event.ENTER_FRAME, moveBullet);
}
public function resetBullet():void{
this.x = 150;
this.y = 600;
bulletMoving = false;
}
public function moveBullet(_arg1:Event){
if (bulletMoving == true){
this.y = (this.y + deltaY);
this.x = (this.x + deltaX);
if ((((((((this.y < 0)) || ((this.y > 400)))) || ((this.x < 0)))) || ((this.x > 550)))){
this.x = 150;
this.y = 600;
bulletMoving = false;
};
};
}
}
}//package
Section 4
//gunshot (gunshot)
package {
import flash.media.*;
public dynamic class gunshot extends Sound {
}
}//package
Section 5
//popcork (popcork)
package {
import flash.media.*;
public dynamic class popcork extends Sound {
}
}//package
Section 6
//star (star)
package {
import flash.display.*;
public dynamic class star extends MovieClip {
}
}//package
Section 7
//StartTrigGame (StartTrigGame)
package {
import flash.events.*;
import flash.media.*;
import flash.display.*;
import flash.utils.*;
public class StartTrigGame extends MovieClip {
private var myHitSound:Sound;
public var A_Button;
var canFire:Boolean;// = true
private var numAsteroids:Number;// = 10
var shotxspeed:Number;// = 0
private var numBullets:Number;// = 20
private var asteroidArray:Array;
private var bulletArray:Array;
var whichBullet:Number;// = 0
var bulletSpeed:Number;// = 8
public var W_Button;
public var D_Button:Boolean;
public var S_Button;
private var myCannon:AAGun;
var shotyspeed:Number;// = 0
var myTimer:Timer;
var whichAsteroid:Number;// = 0
public function StartTrigGame(){
bulletSpeed = 8;
shotxspeed = 0;
shotyspeed = 0;
numBullets = 20;
whichBullet = 0;
canFire = true;
numAsteroids = 10;
whichAsteroid = 0;
super();
init();
}
function timerFunction(_arg1:TimerEvent):void{
asteroidArray[whichAsteroid].startAsteroid();
whichAsteroid++;
if (whichAsteroid >= (asteroidArray.length - 1)){
whichAsteroid = 0;
};
}
public function keyUpFunction(_arg1:KeyboardEvent){
if (_arg1.keyCode == 87){
W_Button = false;
} else {
if (_arg1.keyCode == 83){
S_Button = false;
} else {
if (_arg1.keyCode == 65){
A_Button = false;
} else {
if (_arg1.keyCode == 68){
D_Button = false;
};
};
};
};
}
private function init():void{
var _local1:uint;
var _local2:uint;
var _local3:*;
var _local4:*;
myHitSound = new popcork();
myCannon = new AAGun();
bulletArray = new Array();
asteroidArray = new Array();
_local1 = 0;
while (_local1 < numAsteroids) {
_local3 = new Asteroid();
addChild(_local3);
asteroidArray.push(_local3);
_local1++;
};
addChild(myCannon);
_local2 = 0;
while (_local2 < numBullets) {
_local4 = new Bullet();
addChild(_local4);
bulletArray.push(_local4);
_local2++;
};
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownFunction);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpFunction);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMousePress);
stage.addEventListener(MouseEvent.MOUSE_UP, onMyMouseUp);
myTimer = new Timer(1000);
myTimer.addEventListener(TimerEvent.TIMER, timerFunction);
myTimer.start();
}
public function keyDownFunction(_arg1:KeyboardEvent){
if (_arg1.keyCode == 87){
W_Button = true;
} else {
if (_arg1.keyCode == 83){
S_Button = true;
} else {
if (_arg1.keyCode == 65){
A_Button = true;
} else {
if (_arg1.keyCode == 68){
D_Button = true;
};
};
};
};
}
public function onMyMouseUp(_arg1:MouseEvent):void{
canFire = true;
}
public function onEnterFrame(_arg1:Event):void{
var _local2:Number;
var _local3:Number;
var _local4:int;
var _local5:int;
_local2 = Math.atan2((mouseY - myCannon.y), (mouseX - myCannon.x));
_local3 = Math.round(((_local2 * 180) / Math.PI));
myCannon.rotation = _local3;
_local4 = (bulletArray.length - 1);
while (_local4 >= 0) {
_local5 = (asteroidArray.length - 1);
while (_local5 >= 0) {
if (bulletArray[_local4].hitTestObject(asteroidArray[_local5])){
myHitSound.play(0, 1);
asteroidArray[_local5].resetAsteroid();
bulletArray[_local4].resetBullet();
};
_local5--;
};
_local4--;
};
}
public function onMousePress(_arg1:MouseEvent):void{
var _local2:Number;
var _local3:Number;
var _local4:Number;
var _local5:Number;
var _local6:Number;
var _local7:Number;
var _local8:Number;
_local2 = (myCannon.y - mouseY);
_local3 = (myCannon.x - mouseX);
_local4 = Math.sqrt(((_local3 * _local3) + (_local2 * _local2)));
_local5 = ((myCannon.y - mouseY) / _local4);
shotyspeed = (bulletSpeed * _local5);
shotyspeed = (shotyspeed * -1);
_local6 = ((mouseX - myCannon.x) / _local4);
shotxspeed = (bulletSpeed * _local6);
_local7 = Math.atan2((mouseY - myCannon.y), (mouseX - myCannon.x));
_local8 = Math.round(((_local7 * 180) / Math.PI));
if (canFire == true){
bulletArray[whichBullet].startBullet(myCannon.x, myCannon.y, shotxspeed, shotyspeed, _local8);
whichBullet++;
if (whichBullet >= (bulletArray.length - 1)){
whichBullet = 0;
};
canFire = false;
};
}
}
}//package