Section 1
//Engine (com.asgamer.basics1.Engine)
package com.asgamer.basics1 {
import flash.display.*;
import flash.events.*;
import com.senocular.utils.*;
import flash.geom.*;
import flash.ui.*;
public class Engine extends MovieClip {
private const WALL_COLOR:uint;
private const FINISH_COLOR:uint = 0xFF00;
private const WALKABLE_COLOR:uint = 0xDDDDDD;
private const NORTH:String = "N";
private const TILE_SIZE:uint = 250;
private const START_COLOR:uint = 0xFF0000;
private const MAZE_WIDTH:uint = 20;
private const MAZE_HEIGHT:uint = 20;
private const SOUTH:String = "S";
private const WEST:String = "W";
private const EAST:String = "E";
private var _height:uint;
private var key:KeyObject;
private var speed:Number;// = 4
private var numStars:int;// = 10
private var _maze:Array;
private var pausedMovie:pausedMc;
private var vx:Number;// = 0
private var vy:Number;// = 0
private var _width:uint;
private var friction:Number;// = 0.8
private var _container:Sprite;
private var scoreHUD:ScoreHUD;
private var tile2:Sprite;
private var _start:Point;
private var maxspeed:Number;// = 0.2
private var ourShip:Ship;
private var parallaxField:ParallaxField;
private var _finish:Point;
private var _moves:Array;
public static var enemyList:Array = new Array();
public static var wallsList:Array = new Array();
public static var tileList:Array = new Array();
public static var enemy2List:Array = new Array();
public function Engine():void{
var mainContainer:MovieClip;
var myKeyDown:Function;
var i:int;
WALL_COLOR = (Math.random() * 0xFFFFFF);
numStars = 10;
speed = 4;
vx = 0;
vy = 0;
friction = 0.8;
maxspeed = 0.2;
super();
myKeyDown = function (_arg1:KeyboardEvent):void{
if (_arg1.keyCode == Keyboard.UP){
vy = (vy + speed);
};
if (_arg1.keyCode == Keyboard.DOWN){
vy = (vy - speed);
};
if (_arg1.keyCode == Keyboard.LEFT){
vx = (vx + speed);
} else {
if (_arg1.keyCode == Keyboard.RIGHT){
vx = (vy - speed);
};
};
};
pausedMovie = new pausedMc();
addChild(pausedMovie);
addEventListener(Event.ACTIVATE, onActivate);
addEventListener(Event.DEACTIVATE, onDeactivate);
pausedMovie.x = (stage.stageWidth / 2);
pausedMovie.y = (stage.stageHeight / 2);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(MouseEvent.CLICK, _generate);
_width = ((MAZE_WIDTH * 2) + 1);
_height = ((MAZE_HEIGHT * 2) + 1);
_start = new Point(1, 1);
_finish = new Point((_height - 2), (_width - 2));
_container = new Sprite();
_generate();
ourShip = new Ship(stage);
ourShip.x = (stage.stageWidth / 2);
ourShip.y = (stage.stageHeight / 2);
stage.addChild(ourShip);
scoreHUD = new ScoreHUD(stage);
stage.addChild(scoreHUD);
mainContainer = new MovieClip();
addChild(mainContainer);
parallaxField = new ParallaxField();
parallaxField.createField(mainContainer, 0, 0, 500, 650, 5, 0, 0);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onMyKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onMyKeyUp);
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
i = 0;
while (i < numStars) {
stage.addChildAt(new Star(stage), stage.getChildIndex(ourShip));
i = (i + 1);
};
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
private function _drawSide(_arg1:uint):Sprite{
var _local2:Sprite;
_local2 = new Sprite();
_local2.graphics.beginFill(_arg1);
_local2.graphics.drawRect(0, 0, (TILE_SIZE / 4), (TILE_SIZE / 4));
_local2.graphics.endFill();
_local2.alpha = 0.4;
return (_local2);
}
private function enemyKilled(_arg1:Event){
scoreHUD.updateKills(1);
scoreHUD.updateScore(_arg1.currentTarget.points);
}
private function onEnterFrm(_arg1:Event):void{
}
private function onMyKeyUp(_arg1:KeyboardEvent):void{
switch (_arg1.keyCode){
case Keyboard.UP:
parallaxField.upPressed = false;
case Keyboard.DOWN:
parallaxField.downPressed = false;
break;
case Keyboard.LEFT:
parallaxField.leftPressed = false;
break;
case Keyboard.RIGHT:
parallaxField.rightPressed = false;
break;
};
}
private function _randInt(_arg1:int, _arg2:int):int{
return (int(((Math.random() * ((_arg2 - _arg1) + 1)) + _arg1)));
}
private function _initMaze():void{
var _local1:int;
var _local2:int;
_maze = new Array(_width);
_local1 = 0;
while (_local1 < _height) {
_maze[_local1] = new Array(_height);
_local2 = 0;
while (_local2 < _width) {
_maze[_local1][_local2] = true;
_local2++;
};
_local1++;
};
_maze[_start.x][_start.y] = false;
}
private function _drawMaze():void{
var _local1:Sprite;
var _local2:Sprite;
var _local3:int;
var _local4:int;
if (contains(_container)){
removeChild(_container);
};
_container = new Sprite();
addChild(_container);
_local3 = 0;
while (_local3 < _height) {
_local4 = 0;
while (_local4 < _width) {
_local1 = ((_maze[_local3][_local4])==true) ? _drawWallTile(WALL_COLOR) : _drawTile(WALKABLE_COLOR);
_local1.x = (_local3 * TILE_SIZE);
_local1.y = (_local4 * TILE_SIZE);
_container.addChild(_local1);
_local2 = ((_maze[_local3][_local4])==true) ? _drawSide(WALL_COLOR) : _giveWalk(FINISH_COLOR);
_local2.x = (_local3 * TILE_SIZE);
_local2.y = (_local4 * TILE_SIZE);
_container.addChild(_local2);
_local4++;
};
_local3++;
};
_local1 = _drawTile(START_COLOR);
_local1.x = (_start.x * TILE_SIZE);
_local1.y = (_start.y * TILE_SIZE);
_local1.alpha = 1;
_container.addChild(_local1);
}
private function loop(_arg1:Event):void{
var _local2:Stinger;
var _local3:Stinger2;
var _local4:Wall;
setChildIndex(_container, 0);
_container.y = (_container.y + vy);
_container.x = (_container.x + vx);
vy = (vy * friction);
vx = (vx * friction);
if (Math.floor((Math.random() * 500)) == 5){
_local2 = new Stinger(stage, ourShip);
_local2.addEventListener(Event.REMOVED_FROM_STAGE, removeEnemy, false, 0, true);
_local2.addEventListener("killed", enemyKilled, false, 0, true);
enemyList.push(_local2);
stage.addChild(_local2);
};
if (Math.floor((Math.random() * 90)) == 4){
_local3 = new Stinger2(stage, ourShip);
_local3.addEventListener(Event.REMOVED_FROM_STAGE, removeEnemy2, false, 0, true);
_local3.addEventListener("killed", enemyKilled, false, 0, true);
enemy2List.push(_local3);
stage.addChild(_local3);
};
if (Math.floor((Math.random() * 90)) == 3){
_local4 = new Wall(stage, ourShip);
_local4.addEventListener(Event.REMOVED_FROM_STAGE, removeWalls, false, 0, true);
_local4.addEventListener("broken", wallsBroken, false, 0, true);
wallsList.push(_local4);
stage.addChild(_local4);
};
}
private function _createMaze():void{
var _local1:int;
var _local2:int;
var _local3:String;
var _local4:Point;
_local4 = _start.clone();
_moves = new Array();
_moves.push((_local4.y + (_local4.x * _width)));
while (_moves.length) {
_local3 = "";
if (((((((((_local4.x + 2) < _height)) && ((_maze[(_local4.x + 2)][_local4.y] == true)))) && (!(((_local4.x + 2) == false))))) && (!(((_local4.x + 2) == (_height - 1)))))){
_local3 = (_local3 + SOUTH);
};
if (((((((((_local4.x - 2) >= 0)) && ((_maze[(_local4.x - 2)][_local4.y] == true)))) && (!(((_local4.x - 2) == false))))) && (!(((_local4.x - 2) == (_height - 1)))))){
_local3 = (_local3 + NORTH);
};
if (((((((((_local4.y - 2) >= 0)) && ((_maze[_local4.x][(_local4.y - 2)] == true)))) && (!(((_local4.y - 2) == false))))) && (!(((_local4.y - 2) == (_width - 1)))))){
_local3 = (_local3 + WEST);
};
if (((((((((_local4.y + 2) < _width)) && ((_maze[_local4.x][(_local4.y + 2)] == true)))) && (!(((_local4.y + 2) == false))))) && (!(((_local4.y + 2) == (_width - 1)))))){
_local3 = (_local3 + EAST);
};
if (_local3.length > 0){
_local2 = _randInt(0, (_local3.length - 1));
switch (_local3.charAt(_local2)){
case NORTH:
_maze[(_local4.x - 2)][_local4.y] = false;
_maze[(_local4.x - 1)][_local4.y] = false;
_local4.x = (_local4.x - 2);
break;
case SOUTH:
_maze[(_local4.x + 2)][_local4.y] = false;
_maze[(_local4.x + 1)][_local4.y] = false;
_local4.x = (_local4.x + 2);
break;
case WEST:
_maze[_local4.x][(_local4.y - 2)] = false;
_maze[_local4.x][(_local4.y - 1)] = false;
_local4.y = (_local4.y - 2);
break;
case EAST:
_maze[_local4.x][(_local4.y + 2)] = false;
_maze[_local4.x][(_local4.y + 1)] = false;
_local4.y = (_local4.y + 2);
break;
};
_moves.push((_local4.y + (_local4.x * _width)));
} else {
_local1 = _moves.pop();
_local4.x = int((_local1 / _width));
_local4.y = (_local1 % _width);
};
};
}
private function _generate(_arg1:MouseEvent=null):void{
_initMaze();
_createMaze();
_drawMaze();
}
public function _drawWallTile(_arg1:uint):Sprite{
var _local2:Sprite;
_local2 = new Sprite();
_local2.graphics.beginFill(_arg1);
_local2.graphics.drawRect(0, 0, TILE_SIZE, TILE_SIZE);
_local2.graphics.endFill();
_local2.alpha = 0.2;
return (_local2);
}
private function wallsBroken(_arg1:Event){
scoreHUD.updateScore(_arg1.currentTarget.points);
}
private function onMyKeyDown(_arg1:KeyboardEvent):void{
switch (_arg1.keyCode){
case Keyboard.UP:
parallaxField.upPressed = true;
case Keyboard.DOWN:
parallaxField.downPressed = true;
break;
case Keyboard.LEFT:
parallaxField.leftPressed = true;
break;
case Keyboard.RIGHT:
parallaxField.rightPressed = true;
break;
};
_arg1.updateAfterEvent();
}
private function removeEnemy2(_arg1:Event){
enemy2List.splice(enemy2List.indexOf(_arg1.currentTarget), 1);
}
private function removeEnemy(_arg1:Event){
enemyList.splice(enemyList.indexOf(_arg1.currentTarget), 1);
}
private function _drawTile(_arg1:uint):Sprite{
var _local2:Sprite;
_local2 = new Sprite();
_local2.graphics.beginFill(_arg1);
_local2.graphics.drawRect(0, 0, TILE_SIZE, TILE_SIZE);
_local2.graphics.endFill();
return (_local2);
}
private function onDeactivate(_arg1:Event):void{
removeEventListener(Event.ENTER_FRAME, onEnterFrm);
ourShip.removeEventListener("hit", shipHit);
addChild(pausedMovie);
}
private function shipHit(_arg1:Event){
scoreHUD.updateHits(1);
}
private function removeWalls(_arg1:Event){
wallsList.splice(wallsList.indexOf(_arg1.currentTarget), 1);
}
private function _giveWalk(_arg1:uint):Sprite{
var _local2:Sprite;
_local2 = new Sprite();
_local2.graphics.beginFill(_arg1);
_local2.graphics.drawCircle(0, 0, (TILE_SIZE / 16));
_local2.graphics.endFill();
_local2.alpha = 1;
return (_local2);
}
private function onActivate(_arg1:Event):void{
addEventListener(Event.ENTER_FRAME, onEnterFrm);
ourShip.addEventListener("hit", shipHit, false, 0, true);
removeChild(pausedMovie);
}
}
}//package com.asgamer.basics1
Section 2
//LaserBlue (com.asgamer.basics1.LaserBlue)
package com.asgamer.basics1 {
import flash.display.*;
import flash.events.*;
import com.senocular.utils.*;
import flash.utils.*;
import flash.ui.*;
public class LaserBlue extends MovieClip {
private var friction:Number;// = 1
private var canLive:Boolean;// = true
private var canGuide:Boolean;// = true
private var gravity:Number;// = -2
private var key:KeyObject;
private var maxspeed:Number;// = 13
private var bulletXSpeed:Number;// = 0
private var guideTimer:Timer;
private var stageRef:Stage;
private var speed:Number;// = 8
private var lifeTimer:Timer;
private var vx:Number;// = 0
private var vy:Number;// = 0
private var bulletYSpeed:Number;// = 15
public function LaserBlue(_arg1:Stage, _arg2:Number, _arg3:Number):void{
bulletYSpeed = 15;
bulletXSpeed = 0;
gravity = -2;
speed = 8;
vx = 0;
vy = 0;
friction = 1;
maxspeed = 13;
canGuide = true;
canLive = true;
super();
guideTimer = new Timer(500, 1);
guideTimer.addEventListener(TimerEvent.TIMER, guideTimerHandler, false, 0, true);
lifeTimer = new Timer(3000, 1);
lifeTimer.addEventListener(TimerEvent.TIMER, lifeTimerHandler, false, 0, true);
this.stageRef = _arg1;
this.x = _arg2;
this.y = _arg3;
key = new KeyObject(_arg1);
guideTimer.start();
lifeTimer.start();
if (_arg2 > (_arg1.stageWidth / 2)){
bulletXSpeed = 2;
} else {
if (_arg2 < (_arg1.stageWidth / 2)){
bulletXSpeed = -2;
} else {
if (_arg2 < 100){
bulletXSpeed = (bulletXSpeed - 1);
} else {
if (_arg2 > 400){
bulletXSpeed = (bulletXSpeed + 1);
};
};
};
};
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
private function removeSelf():void{
removeEventListener(Event.ENTER_FRAME, loop);
if (stageRef.contains(this)){
stageRef.removeChild(this);
};
}
private function guideTimerHandler(_arg1:TimerEvent):void{
canGuide = false;
}
private function lifeTimerHandler(_arg1:TimerEvent):void{
canLive = false;
removeSelf();
}
private function loop(_arg1:Event):void{
var _local2:int;
var _local3:int;
var _local4:int;
if (canGuide){
if (key.isDown(Keyboard.LEFT)){
vx = (vx + (speed / 2));
} else {
if (key.isDown(Keyboard.RIGHT)){
vx = (vx - (speed / 2));
} else {
vx = 0;
};
};
if (key.isDown(Keyboard.UP)){
vy = (vy - speed);
} else {
if (key.isDown(Keyboard.DOWN)){
vy = (vy - speed);
} else {
vy = (vy - speed);
};
};
};
x = (x + vx);
y = (y + vy);
if (vx > maxspeed){
vx = maxspeed;
} else {
if (vx < -(maxspeed)){
vx = -(maxspeed);
};
};
if (vy > maxspeed){
vy = maxspeed;
} else {
if (vy < -(maxspeed)){
vy = -(maxspeed);
};
};
if (x <= 4){
vx = (vx * -1);
} else {
if (x >= 495){
vx = (vx * -1);
};
};
_local2 = 0;
while (_local2 < Engine.enemyList.length) {
if (hitTestObject(Engine.enemyList[_local2].hit)){
trace("hitEnemy");
Engine.enemyList[_local2].takeHit();
removeSelf();
};
_local2++;
};
_local3 = 0;
while (_local3 < Engine.enemy2List.length) {
if (hitTestObject(Engine.enemy2List[_local3].hit)){
trace("hitEnemy2");
Engine.enemy2List[_local3].takeHit();
removeSelf();
};
_local3++;
};
_local4 = 0;
while (_local4 < Engine.wallsList.length) {
if (hitTestObject(Engine.wallsList[_local4].hit)){
trace("hitWalls");
Engine.wallsList[_local4].takeHit();
removeSelf();
};
_local4++;
};
}
}
}//package com.asgamer.basics1
Section 3
//ParallaxField (com.asgamer.basics1.ParallaxField)
package com.asgamer.basics1 {
import flash.display.*;
import flash.events.*;
import flash.utils.*;
public class ParallaxField extends MovieClip {
private var friction:Number;// = 0.05
private var containerX:int;
private var containerY:int;
private var containerHeight:int;
private var isStarted:Boolean;// = false
private var starBox:Sprite;
private var maxSpeed:Number;// = 0.06
private var _rightPressed:Boolean;// = false
private var _leftPressed:Boolean;// = false
private var _downPressed:Boolean;// = false
private var starsArray:Array;
private var acceleration:Number;// = -0.05
private var _upPressed:Boolean;// = false
private var containerWidth:int;
private var pathToContainer:MovieClip;
private var starArrayLength:int;
private var speedX:Number;
private var speedY:Number;
private static var STAR_NORMAL:String = "normal";
private static var STAR_SMALL:String = "small";
private static var STAR_LARGE:String = "large";
public function ParallaxField(){
acceleration = -0.05;
starsArray = [];
friction = 0.05;
maxSpeed = 0.06;
isStarted = false;
_upPressed = false;
_downPressed = false;
_leftPressed = false;
_rightPressed = false;
super();
}
private function updateSpeed():void{
if (upPressed){
speedY = (speedY - acceleration);
} else {
if (downPressed){
speedY = (speedY + acceleration);
} else {
speedY = (speedY * friction);
};
};
if (rightPressed){
speedX = (speedX + acceleration);
} else {
if (leftPressed){
speedX = (speedX - acceleration);
} else {
speedX = (speedX * friction);
};
};
}
public function get upPressed():Boolean{
return (_upPressed);
}
public function get leftPressed():Boolean{
return (_leftPressed);
}
public function set leftPressed(_arg1:Boolean):void{
_leftPressed = _arg1;
}
public function set upPressed(_arg1:Boolean):void{
_upPressed = _arg1;
}
public function get downPressed():Boolean{
return (_downPressed);
}
public function createField(_arg1:MovieClip, _arg2:int, _arg3:int, _arg4:int, _arg5:int, _arg6:int, _arg7:int, _arg8:int):void{
trace("createField");
pathToContainer = _arg1;
containerX = _arg2;
containerY = _arg3;
containerWidth = _arg4;
containerHeight = _arg5;
speedX = _arg7;
speedY = _arg8;
createStarBox();
addStars(_arg6, "small");
addStars(_arg6, "normal");
addStars(_arg6, "large");
enable();
}
public function get rightPressed():Boolean{
return (_rightPressed);
}
private function updateStars():void{
var _local1:MovieClip;
var _local2:int;
starArrayLength = starsArray.length;
_local2 = 0;
while (_local2 < starArrayLength) {
_local1 = starsArray[_local2];
_local1.x = (_local1.x + (speedX * _local1.speedModifier));
_local1.y = (_local1.y + (speedY * _local1.speedModifier));
if (_local1.x >= ((containerWidth - _local1.width) + containerX)){
_local1.x = containerX;
_local1.y = ((Math.random() * (containerHeight - _local1.height)) + containerY);
} else {
if (_local1.x <= containerX){
_local1.x = ((containerWidth + containerX) - _local1.width);
_local1.y = ((Math.random() * (containerHeight - _local1.height)) + containerY);
};
};
if (_local1.y >= ((containerHeight - _local1.height) + containerY)){
_local1.x = ((Math.random() * (containerWidth - _local1.width)) + containerX);
_local1.y = containerY;
} else {
if (_local1.y <= containerY){
_local1.x = ((Math.random() * (containerWidth - _local1.width)) + containerX);
_local1.y = ((containerHeight + containerY) - _local1.height);
};
};
_local2++;
};
}
private function createStarBox():void{
var _local1:Sprite;
trace("Creating star container...");
trace((" path: " + pathToContainer));
trace((" x: " + containerX));
trace((" y: " + containerY));
trace((" width: " + containerWidth));
trace((" height: " + containerHeight));
starBox = new Sprite();
starBox.graphics.beginFill(0);
starBox.x = containerX;
starBox.y = containerY;
starBox.width = containerWidth;
starBox.height = containerHeight;
_local1 = new Sprite();
_local1.graphics.beginFill(0xFF0000);
_local1.graphics.drawRect(containerX, containerY, containerWidth, containerHeight);
pathToContainer.addChild(_local1);
starBox.mask = _local1;
pathToContainer.addChild(starBox);
trace(" Container Created \n");
}
public function enable():void{
if (!isStarted){
trace("Starting parallax effect...");
isStarted = true;
pathToContainer.addEventListener(Event.ENTER_FRAME, gameLoop);
} else {
trace("Parallax effect already running.");
};
}
public function addStars(_arg1:int, _arg2:String):void{
var _local3:Number;
var _local4:String;
var _local5:Number;
var _local6:Class;
var _local7:int;
var _local8:MovieClip;
trace("Adding stars...");
if (_arg2 == STAR_LARGE){
_local4 = "StarLarge";
_local5 = 1;
_local3 = Math.round((_arg1 * 0.3));
} else {
if (_arg2 == STAR_NORMAL){
_local4 = "StarNormal";
_local5 = 0.66;
_local3 = Math.round((_arg1 * 0.6));
} else {
if (_arg2 == STAR_SMALL){
_local3 = Math.round((_arg1 * 1));
_local4 = "StarSmall";
_local5 = 0.33;
};
};
};
trace((" type: " + _local4));
trace((" amount: " + _local3));
_local7 = 0;
while (_local7 < _local3) {
_local6 = (getDefinitionByName(_local4) as Class);
_local8 = new (_local6);
_local8.x = ((Math.random() * (containerWidth - _local8.width)) + containerX);
_local8.y = ((Math.random() * (containerHeight - _local8.height)) + containerY);
_local8.speedModifier = _local5;
starsArray.push(_local8);
pathToContainer.addChild(_local8);
_local7++;
};
trace("Stars Added \n");
}
private function gameLoop(_arg1:Event):void{
updateSpeed();
updateStars();
}
public function set rightPressed(_arg1:Boolean):void{
_rightPressed = _arg1;
}
public function set downPressed(_arg1:Boolean):void{
_downPressed = _arg1;
}
public function disable():void{
if (isStarted){
trace("Stopping parallax effect...");
isStarted = false;
pathToContainer.removeEventListener(Event.ENTER_FRAME, gameLoop);
} else {
trace("Parallax effect is not running.");
};
}
}
}//package com.asgamer.basics1
Section 4
//Particle (com.asgamer.basics1.Particle)
package com.asgamer.basics1 {
import flash.display.*;
public class Particle {
public var fade:Number;// = 0
public var yVel:Number;// = 0
public var xVel:Number;// = 0
public var shrink:Number;// = 1
public var gravity:Number;// = 10
public var clip:DisplayObject;
public var drag:Number;// = 1
public function Particle(_arg1:Class, _arg2:DisplayObjectContainer, _arg3:Number, _arg4:Number){
xVel = 0;
yVel = 0;
drag = 1;
gravity = 10;
shrink = 1;
fade = 0;
super();
clip = new (_arg1);
_arg2.addChild(clip);
clip.x = _arg3;
clip.y = _arg4;
}
public function update():void{
clip.x = (clip.x + (xVel + Math.ceil((Math.random() * 6))));
clip.y = (clip.y + (yVel + Math.ceil((Math.random() * 6))));
xVel = (xVel * drag);
yVel = (yVel * drag);
yVel = (yVel + gravity);
clip.scaleX = (clip.scaleX * shrink);
clip.scaleY = (clip.scaleY * shrink);
clip.alpha = (clip.alpha - fade);
}
public function destroy():void{
clip.parent.removeChild(clip);
}
}
}//package com.asgamer.basics1
Section 5
//ScoreHUD (com.asgamer.basics1.ScoreHUD)
package com.asgamer.basics1 {
import flash.display.*;
import flash.text.*;
public class ScoreHUD extends MovieClip {
public var s_kills:Number;// = 0
public var hits:TextField;
public var score:TextField;
private var stageRef:Stage;
public var s_hits:Number;// = 0
public var s_score:Number;// = 0
public var kills:TextField;
public function ScoreHUD(_arg1:Stage){
s_score = 0;
s_hits = 0;
s_kills = 0;
super();
this.stageRef = _arg1;
kills.text = "0";
hits.text = "0";
score.text = "0";
x = 5;
y = ((_arg1.stageHeight - height) - 430);
}
public function updateScore(_arg1:Number):void{
s_score = (s_score + _arg1);
score.text = String(s_score);
}
public function updateHits(_arg1:Number):void{
s_hits = (s_hits + _arg1);
hits.text = String(s_hits);
}
public function updateKills(_arg1:Number):void{
s_kills = (s_kills + _arg1);
kills.text = String(s_kills);
}
}
}//package com.asgamer.basics1
Section 6
//Ship (com.asgamer.basics1.Ship)
package com.asgamer.basics1 {
import flash.display.*;
import flash.events.*;
import com.senocular.utils.*;
import flash.utils.*;
import flash.ui.*;
public class Ship extends MovieClip {
private var friction:Number;// = 0.0098
private var canFire:Boolean;// = true
private var gravity:Number;// = 0
private var key:KeyObject;
private var maxspeed:Number;// = 0.1
private var speed:Number;// = 0.02
private var target:Star;
public var hit:MovieClip;
private var fireTimer:Timer;
private var stageRef:Stage;
public var vx:Number;// = 0
public var vy:Number;// = 0
public function Ship(_arg1:Stage):void{
gravity = 0;
speed = 0.02;
vx = 0;
vy = 0;
friction = 0.0098;
maxspeed = 0.1;
canFire = true;
super();
addFrameScript(0, frame1);
addEventListener(Event.ACTIVATE, onActivate);
addEventListener(Event.DEACTIVATE, onDeactivate);
this.stageRef = _arg1;
key = new KeyObject(_arg1);
this.target = target;
fireTimer = new Timer(600, 1);
fireTimer.addEventListener(TimerEvent.TIMER, fireTimerHandler, false, 0, true);
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
private function fireBullet():void{
if (canFire){
stageRef.addChild(new LaserBlue(stageRef, (x + vx), (y - 10)));
canFire = false;
fireTimer.start();
vy = (vy + gravity);
};
}
function frame1(){
stop();
}
public function loop(_arg1:Event):void{
if (key.isDown(Keyboard.LEFT)){
vx = (vx - speed);
} else {
if (key.isDown(Keyboard.RIGHT)){
vx = (vx + speed);
} else {
vx = (vx * friction);
};
};
if (key.isDown(Keyboard.UP)){
vy = (vy - speed);
} else {
if (key.isDown(Keyboard.DOWN)){
vy = (vy + speed);
} else {
vy = (vy * friction);
};
};
if (key.isDown(Keyboard.SPACE)){
fireBullet();
};
x = (x + vx);
y = (y + vy);
if (vx > maxspeed){
vx = maxspeed;
} else {
if (vx < -(maxspeed)){
vx = -(maxspeed);
};
};
if (vy > maxspeed){
vy = maxspeed;
} else {
if (vy < -(maxspeed)){
vy = -(maxspeed);
};
};
rotation = (rotation + vx);
if (x > (stageRef.stageWidth - 26)){
x = (stageRef.stageWidth - 26);
vx = -(vx);
} else {
if (x < 26){
x = 26;
vx = -(vx);
};
};
if (y > (stageRef.stageHeight - 26)){
y = (stageRef.stageHeight - 26);
vy = -(vy);
} else {
if (y < 26){
y = 26;
vy = -(vy);
};
};
}
public function takeHit():void{
dispatchEvent(new Event("hit"));
gotoAndPlay("destroyed");
vx = (vx * -1);
vy = (vy * -1);
}
private function onDeactivate(_arg1:Event):void{
speed = 0;
vx = 0;
vy = 0;
friction = 0;
maxspeed = 0;
}
private function fireTimerHandler(_arg1:TimerEvent):void{
canFire = true;
}
private function onActivate(_arg1:Event):void{
speed = 2;
vx = 0;
vy = 0;
friction = 0.98;
maxspeed = 13;
}
}
}//package com.asgamer.basics1
Section 7
//SmallImplosion (com.asgamer.basics1.SmallImplosion)
package com.asgamer.basics1 {
import flash.display.*;
import flash.events.*;
public class SmallImplosion extends MovieClip {
public var particles:Array;
private var stageRef:Stage;
public function SmallImplosion(_arg1:Stage, _arg2:Number, _arg3:Number){
addFrameScript(0, frame1);
this.stageRef = _arg1;
this.x = _arg2;
this.y = (this.y + _arg3);
rotation = (rotation + (Math.random() * 360));
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
public function randRange(_arg1:Number, _arg2:Number){
return (((Math.random() * (_arg2 - _arg1)) + _arg1));
}
function frame1(){
particles = new Array();
addEventListener(Event.ENTER_FRAME, frameLoop);
}
public function frameLoop(_arg1:Event){
var _local2:Particle;
var _local3:int;
_local3 = 0;
while (_local3 < particles.length) {
particles[_local3].update();
_local3++;
};
_local2 = new Particle(Spark, this, 0, 0);
_local2.xVel = randRange(-1, 1);
_local2.yVel = (_local2.yVel + 4);
_local2.drag = 0.05;
_local2.gravity = -0.8;
_local2.clip.scaleX = (_local2.clip.scaleY = randRange(0.5, 0.8));
_local2.shrink = 1.02;
_local2.fade = 0.02;
_local2.clip.alpha = 0.3;
particles.push(_local2);
while (particles.length > 20) {
_local2 = particles.shift();
_local2.destroy();
};
}
private function loop(_arg1:Event){
y = (y - (Math.floor((Math.random() * 2)) - 3));
if (currentFrame == totalFrames){
removeSelf();
};
}
private function removeSelf():void{
removeEventListener(Event.ENTER_FRAME, loop);
if (stageRef.contains(this)){
stageRef.removeChild(this);
};
}
}
}//package com.asgamer.basics1
Section 8
//Spark (com.asgamer.basics1.Spark)
package com.asgamer.basics1 {
import flash.display.*;
public dynamic class Spark extends MovieClip {
public function Spark(){
addFrameScript(8, frame9);
}
function frame9(){
stop();
}
}
}//package com.asgamer.basics1
Section 9
//Star (com.asgamer.basics1.Star)
package com.asgamer.basics1 {
import flash.display.*;
import flash.events.*;
public class Star extends MovieClip {
private var speed:Number;
private var target:Ship;
public var hit:MovieClip;
private var stageRef:Stage;
public function Star(_arg1:Stage){
this.stageRef = _arg1;
setupStar(true);
gotoAndStop(Math.max(1, (Math.floor((Math.round((Math.random() * 90)) / 30)) * 30)));
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
public function setupStar(_arg1:Boolean=false):void{
y = (_arg1) ? (Math.random() * stageRef.stageHeight) : 0;
x = (Math.random() * stageRef.stageWidth);
alpha = 0;
this.target = target;
speed = (2 + (Math.random() * 2));
}
public function loop(_arg1:Event):void{
y = (y + alpha);
x = (x + alpha);
if (y > stageRef.stageHeight){
setupStar();
};
}
}
}//package com.asgamer.basics1
Section 10
//Stinger (com.asgamer.basics1.Stinger)
package com.asgamer.basics1 {
import flash.display.*;
import flash.events.*;
public class Stinger extends MovieClip {
public var points:int;// = 1
private var ay:Number;// = -0.02
private var target:Ship;
public var hit:MovieClip;
private var stageRef:Stage;
private var vy:Number;// = -0.4
public function Stinger(_arg1:Stage, _arg2:Ship):void{
vy = -0.4;
ay = -0.02;
points = 1;
super();
stop();
this.stageRef = _arg1;
this.target = _arg2;
x = 0;
y = (Math.random() * _arg1.stageWidth);
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
private function loop(_arg1:Event):void{
if (hitTestObject(target.hit)){
target.takeHit();
stageRef.addChild(new SmallImplosion(stageRef, x, y));
gotoAndPlay("destroyed");
removeSelf();
};
if (currentLabel != "destroyed"){
vy = (vy + ay);
x = (x - vy);
y = (y - 0.8);
if (y > stageRef.stageHeight){
removeSelf();
};
if (((((y - 3) < target.y)) && (((y + 3) > target.y)))){
fireWeapon();
};
};
if (currentLabel == "destroyedComplete"){
removeSelf();
};
}
public function takeHit():void{
if (currentLabel != "destroyed"){
dispatchEvent(new Event("killed"));
rotation = (rotation + (Math.random() * 360));
stageRef.addChild(new SmallImplosion(stageRef, x, y));
removeSelf();
};
}
private function fireWeapon():void{
stageRef.addChild(new StingerBullet(stageRef, target, x, y, -9));
stageRef.addChild(new StingerBullet(stageRef, target, x, y, 9));
y = (y - vy);
}
private function removeSelf():void{
removeEventListener(Event.ENTER_FRAME, loop);
if (stageRef.contains(this)){
stageRef.removeChild(this);
};
}
}
}//package com.asgamer.basics1
Section 11
//Stinger2 (com.asgamer.basics1.Stinger2)
package com.asgamer.basics1 {
import flash.display.*;
import flash.events.*;
import com.senocular.utils.*;
import flash.utils.*;
import flash.ui.*;
public class Stinger2 extends MovieClip {
private var friction:Number;// = 0.0098
public var points:int;// = 20
private var ay:Number;// = 0
private var ax:Number;// = 0.02
public var getTime:Number;
private var moveTimer:Timer;
private var key:KeyObject;
private var maxspeed:Number;// = 0.1
private var speed:Number;// = 2
private var target:Ship;
public var hit:MovieClip;
private var stageRef:Stage;
private var canMove:Boolean;// = true
private var vx:Number;// = 0.02
private var vy:Number;// = 0
private var gx:Number;// = 0
private var gy:Number;// = 0
public function Stinger2(_arg1:Stage, _arg2:Ship):void{
speed = 2;
friction = 0.0098;
maxspeed = 0.1;
vx = 0.02;
ax = 0.02;
vy = 0;
ay = 0;
gx = 0;
gy = 0;
canMove = true;
points = 20;
super();
stop();
this.stageRef = _arg1;
this.target = _arg2;
key = new KeyObject(_arg1);
x = 520;
y = (Math.random() * _arg1.stageHeight);
getTime = (Math.floor((Math.random() * 4100)) + 3000);
moveTimer = new Timer(getTime, 9);
moveTimer.addEventListener(TimerEvent.TIMER, moveTimerHandler, false, 0, true);
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
private function fireWeapon():void{
if (y < target.y){
stageRef.addChild(new Stinger2Bullet(stageRef, target, x, y, -8));
} else {
stageRef.addChild(new Stinger2Bullet(stageRef, target, x, y, 8));
};
}
public function takeHit():void{
if (currentLabel != "destroyed"){
dispatchEvent(new Event("killed"));
rotation = (rotation + (Math.random() * 360));
stageRef.addChild(new SmallImplosion(stageRef, x, y));
gotoAndPlay("destroyed");
};
}
private function moveTimerHandler(_arg1:TimerEvent):void{
canMove = true;
vx = (vx * (Math.floor((Math.random() * 4)) - 2));
y = (y + (Math.floor((Math.random() * 4)) + 1));
}
private function loop(_arg1:Event):void{
vx = (vx + ax);
x = (x - vx);
vy = (vy + ay);
y = (y - vy);
if (hitTestObject(target.hit)){
target.takeHit();
stageRef.addChild(new SmallImplosion(stageRef, x, y));
gotoAndPlay("destroyed");
removeSelf();
};
if (currentLabel != "destroyed"){
if (key.isDown(Keyboard.LEFT)){
x = (x + speed);
} else {
if (key.isDown(Keyboard.RIGHT)){
x = (x - speed);
} else {
gx = (gx * friction);
};
};
if (key.isDown(Keyboard.UP)){
y = (y + speed);
} else {
if (key.isDown(Keyboard.DOWN)){
y = (y - speed);
} else {
gy = (gy * friction);
};
};
moveTimer.start();
if (y > stageRef.stageHeight){
y = (y - 5);
};
if (((((x - 5) < target.x)) && (((x + 5) > target.x)))){
fireWeapon();
};
};
if (currentLabel == "destroyedComplete"){
removeSelf();
};
}
private function removeSelf():void{
removeEventListener(Event.ENTER_FRAME, loop);
if (stageRef.contains(this)){
stageRef.removeChild(this);
};
}
}
}//package com.asgamer.basics1
Section 12
//Stinger2Bullet (com.asgamer.basics1.Stinger2Bullet)
package com.asgamer.basics1 {
import flash.display.*;
import flash.events.*;
public class Stinger2Bullet extends MovieClip {
private var target:Ship;
private var stageRef:Stage;
private var vx:Number;
public function Stinger2Bullet(_arg1:Stage, _arg2:Ship, _arg3:Number, _arg4:Number, _arg5:Number):void{
this.stageRef = _arg1;
this.target = _arg2;
this.x = _arg3;
this.y = _arg4;
this.vx = _arg5;
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
private function loop(_arg1:Event):void{
y = (y - vx);
if ((((x > stageRef.stageWidth)) || ((x < 0)))){
removeSelf();
};
if (hitTestObject(target.hit)){
target.takeHit();
stageRef.addChild(new SmallImplosion(stageRef, x, y));
removeSelf();
};
}
private function removeSelf():void{
removeEventListener(Event.ENTER_FRAME, loop);
if (stageRef.contains(this)){
stageRef.removeChild(this);
};
}
}
}//package com.asgamer.basics1
Section 13
//StingerBullet (com.asgamer.basics1.StingerBullet)
package com.asgamer.basics1 {
import flash.display.*;
import flash.events.*;
public class StingerBullet extends MovieClip {
private var target:Ship;
private var stageRef:Stage;
private var vx:Number;
public function StingerBullet(_arg1:Stage, _arg2:Ship, _arg3:Number, _arg4:Number, _arg5:Number):void{
this.stageRef = _arg1;
this.target = _arg2;
this.x = _arg3;
this.y = _arg4;
this.vx = _arg5;
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
private function loop(_arg1:Event):void{
x = (x + vx);
if ((((x > stageRef.stageWidth)) || ((x < 0)))){
removeSelf();
};
if (hitTestObject(target.hit)){
target.takeHit();
stageRef.addChild(new SmallImplosion(stageRef, x, y));
removeSelf();
};
}
private function removeSelf():void{
removeEventListener(Event.ENTER_FRAME, loop);
if (stageRef.contains(this)){
stageRef.removeChild(this);
};
}
}
}//package com.asgamer.basics1
Section 14
//TiledMazeGen (com.asgamer.basics1.TiledMazeGen)
package com.asgamer.basics1 {
import flash.display.*;
import flash.events.*;
import flash.geom.*;
public class TiledMazeGen extends Sprite {
private const START_COLOR:uint = 0xFF0000;
private const MAZE_WIDTH:uint = 20;
private const WALL_COLOR:uint = 0;
private const FINISH_COLOR:uint = 0xFF00;
private const MAZE_HEIGHT:uint = 20;
private const SOUTH:String = "S";
private const WEST:String = "W";
private const WALKABLE_COLOR:uint = 0xDDDDDD;
private const NORTH:String = "N";
private const TILE_SIZE:uint = 10;
private const EAST:String = "E";
private var _container:Sprite;
private var _start:Point;
private var _height:uint;
private var _finish:Point;
private var _moves:Array;
private var _width:uint;
private var _maze:Array;
public function TiledMazeGen():void{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(MouseEvent.CLICK, _generate);
_width = ((MAZE_WIDTH * 2) + 1);
_height = ((MAZE_HEIGHT * 2) + 1);
_start = new Point(1, 1);
_container = new Sprite();
_generate();
}
private function _randInt(_arg1:int, _arg2:int):int{
return (int(((Math.random() * ((_arg2 - _arg1) + 1)) + _arg1)));
}
private function _initMaze():void{
var _local1:int;
var _local2:int;
_maze = new Array(_width);
_local1 = 0;
while (_local1 < _height) {
_maze[_local1] = new Array(_height);
_local2 = 0;
while (_local2 < _width) {
_maze[_local1][_local2] = true;
_local2++;
};
_local1++;
};
_maze[_start.x][_start.y] = false;
}
private function _drawTile(_arg1:uint):Sprite{
var _local2:Sprite;
_local2 = new Sprite();
_local2.graphics.beginFill(_arg1);
_local2.graphics.drawRect(0, 0, TILE_SIZE, TILE_SIZE);
_local2.graphics.endFill();
return (_local2);
}
private function _drawMaze():void{
var _local1:Sprite;
var _local2:int;
var _local3:int;
if (contains(_container)){
removeChild(_container);
};
_container = new Sprite();
addChild(_container);
_local2 = 0;
while (_local2 < _height) {
_local3 = 0;
while (_local3 < _width) {
_local1 = ((_maze[_local2][_local3])==true) ? _drawTile(WALL_COLOR) : _drawTile(WALKABLE_COLOR);
_local1.x = (_local2 * TILE_SIZE);
_local1.y = (_local3 * TILE_SIZE);
_container.addChild(_local1);
_local3++;
};
_local2++;
};
_local1 = _drawTile(START_COLOR);
_local1.x = (_start.x * TILE_SIZE);
_local1.y = (_start.y * TILE_SIZE);
_container.addChild(_local1);
}
private function _createMaze():void{
var _local1:int;
var _local2:int;
var _local3:String;
var _local4:Point;
_local4 = _start.clone();
_moves = new Array();
_moves.push((_local4.y + (_local4.x * _width)));
while (_moves.length) {
_local3 = "";
if (((((((((_local4.x + 2) < _height)) && ((_maze[(_local4.x + 2)][_local4.y] == true)))) && (!(((_local4.x + 2) == false))))) && (!(((_local4.x + 2) == (_height - 1)))))){
_local3 = (_local3 + SOUTH);
};
if (((((((((_local4.x - 2) >= 0)) && ((_maze[(_local4.x - 2)][_local4.y] == true)))) && (!(((_local4.x - 2) == false))))) && (!(((_local4.x - 2) == (_height - 1)))))){
_local3 = (_local3 + NORTH);
};
if (((((((((_local4.y - 2) >= 0)) && ((_maze[_local4.x][(_local4.y - 2)] == true)))) && (!(((_local4.y - 2) == false))))) && (!(((_local4.y - 2) == (_width - 1)))))){
_local3 = (_local3 + WEST);
};
if (((((((((_local4.y + 2) < _width)) && ((_maze[_local4.x][(_local4.y + 2)] == true)))) && (!(((_local4.y + 2) == false))))) && (!(((_local4.y + 2) == (_width - 1)))))){
_local3 = (_local3 + EAST);
};
if (_local3.length > 0){
_local2 = _randInt(0, (_local3.length - 1));
switch (_local3.charAt(_local2)){
case NORTH:
_maze[(_local4.x - 2)][_local4.y] = false;
_maze[(_local4.x - 1)][_local4.y] = false;
_local4.x = (_local4.x - 2);
break;
case SOUTH:
_maze[(_local4.x + 2)][_local4.y] = false;
_maze[(_local4.x + 1)][_local4.y] = false;
_local4.x = (_local4.x + 2);
break;
case WEST:
_maze[_local4.x][(_local4.y - 2)] = false;
_maze[_local4.x][(_local4.y - 1)] = false;
_local4.y = (_local4.y - 2);
break;
case EAST:
_maze[_local4.x][(_local4.y + 2)] = false;
_maze[_local4.x][(_local4.y + 1)] = false;
_local4.y = (_local4.y + 2);
break;
};
_moves.push((_local4.y + (_local4.x * _width)));
} else {
_local1 = _moves.pop();
_local4.x = int((_local1 / _width));
_local4.y = (_local1 % _width);
};
};
}
private function _generate(_arg1:MouseEvent=null):void{
_initMaze();
_createMaze();
_drawMaze();
}
}
}//package com.asgamer.basics1
Section 15
//Wall (com.asgamer.basics1.Wall)
package com.asgamer.basics1 {
import flash.display.*;
import flash.events.*;
public class Wall extends MovieClip {
public var points:int;// = 0
private var ay:Number;// = 0.2
private var target:Ship;
public var hit:MovieClip;
private var stageRef:Stage;
private var vy:Number;// = -0.5
public function Wall(_arg1:Stage, _arg2:Ship):void{
vy = -0.5;
ay = 0.2;
points = 0;
super();
stop();
this.stageRef = _arg1;
this.target = _arg2;
x = (Math.random() * _arg1.stageWidth);
y = -10;
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
private function loop(_arg1:Event):void{
if (hitTestObject(target.hit)){
target.takeHit();
stageRef.addChild(new SmallImplosion(stageRef, x, y));
target.y = (target.y + 20);
gotoAndPlay("destroyed");
};
if (currentLabel != "destroyed"){
vy = (vy + ay);
y = (y + vy);
if (y > stageRef.stageHeight){
removeSelf();
};
if (((((y - 15) < target.y)) && (((y + 15) > target.y)))){
fireWeapon();
};
};
if (currentLabel == "destroyedComplete"){
removeSelf();
};
}
public function takeHit():void{
if (currentLabel != "destroyed"){
dispatchEvent(new Event("broken"));
gotoAndPlay("destroyed");
};
}
private function fireWeapon():void{
}
private function removeSelf():void{
removeEventListener(Event.ENTER_FRAME, loop);
if (stageRef.contains(this)){
stageRef.removeChild(this);
};
}
}
}//package com.asgamer.basics1
Section 16
//KeyObject (com.senocular.utils.KeyObject)
package com.senocular.utils {
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import flash.ui.*;
public dynamic class KeyObject extends Proxy {
private static var keysDown:Object;
private static var stage:Stage;
public function KeyObject(_arg1:Stage){
construct(_arg1);
}
private function keyPressed(_arg1:KeyboardEvent):void{
keysDown[_arg1.keyCode] = true;
}
public function construct(_arg1:Stage):void{
KeyObject.stage = _arg1;
keysDown = new Object();
_arg1.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
_arg1.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
}
override "http://www.adobe.com/2006/actionscript/flash/proxy"?? function getProperty(_arg1){
return (((_arg1 in Keyboard)) ? Keyboard[_arg1] : -1);
}
public function isDown(_arg1:uint):Boolean{
return (Boolean((_arg1 in keysDown)));
}
private function keyReleased(_arg1:KeyboardEvent):void{
delete keysDown[_arg1.keyCode];
}
public function deconstruct():void{
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stage.removeEventListener(KeyboardEvent.KEY_UP, keyReleased);
keysDown = new Object();
KeyObject.stage = null;
}
}
}//package com.senocular.utils
Section 17
//pausedMc (pausedMc)
package {
import flash.display.*;
public dynamic class pausedMc extends MovieClip {
}
}//package
Section 18
//StarLarge (StarLarge)
package {
import flash.display.*;
public dynamic class StarLarge extends MovieClip {
}
}//package
Section 19
//StarNormal (StarNormal)
package {
import flash.display.*;
public dynamic class StarNormal extends MovieClip {
}
}//package
Section 20
//StarSmall (StarSmall)
package {
import flash.display.*;
public dynamic class StarSmall extends MovieClip {
}
}//package