Section 1
//KongregateEvent (com.kongregate.as3.client.events.KongregateEvent)
package com.kongregate.as3.client.events {
import flash.events.*;
public class KongregateEvent extends Event {
public static const COMPLETE:String = "component_api_available";
public function KongregateEvent(_arg1:String){
super(_arg1);
}
}
}//package com.kongregate.as3.client.events
Section 2
//AbstractShadowService (com.kongregate.as3.client.services.AbstractShadowService)
package com.kongregate.as3.client.services {
import flash.events.*;
public class AbstractShadowService extends EventDispatcher {
protected function alert(_arg1:String, _arg2:String, _arg3="", _arg4:String=""):void{
trace(((((((("Kongregate API: " + _arg1) + ".") + _arg2) + "(") + _arg3) + ") ") + _arg4));
}
}
}//package com.kongregate.as3.client.services
Section 3
//HighScoreServiceShadow (com.kongregate.as3.client.services.HighScoreServiceShadow)
package com.kongregate.as3.client.services {
public class HighScoreServiceShadow extends AbstractShadowService implements IHighScoreServices {
private var mode:String;
public function HighScoreServiceShadow(){
mode = "";
}
public function submit(_arg1:Number, _arg2:String=null):void{
alert("IHighScoreServices", "submit", arguments);
}
public function connect():Boolean{
alert("IKongregateServices", "connect");
return (true);
}
public function requestList(_arg1:Function):void{
alert("IHighScoreServices", "requestList", "", (("[Mode: " + mode) + "]"));
_arg1({success:false});
}
public function setMode(_arg1:String):void{
alert("IHighScoreServices", "setMode", arguments);
this.mode = _arg1;
}
}
}//package com.kongregate.as3.client.services
Section 4
//IHighScoreServices (com.kongregate.as3.client.services.IHighScoreServices)
package com.kongregate.as3.client.services {
public interface IHighScoreServices {
function setMode(_arg1:String):void;
function submit(_arg1:Number, _arg2:String=null):void;
function requestList(_arg1:Function):void;
}
}//package com.kongregate.as3.client.services
Section 5
//IKongregateServices (com.kongregate.as3.client.services.IKongregateServices)
package com.kongregate.as3.client.services {
import flash.events.*;
public interface IKongregateServices extends IEventDispatcher {
function getPlayerInfo(_arg1:Function):void;
function connect(_arg1:Number=-1):Boolean;
}
}//package com.kongregate.as3.client.services
Section 6
//IStatServices (com.kongregate.as3.client.services.IStatServices)
package com.kongregate.as3.client.services {
public interface IStatServices {
function submitArray(_arg1:Array):void;
function submit(_arg1:String, _arg2:Number):void;
}
}//package com.kongregate.as3.client.services
Section 7
//IUserServices (com.kongregate.as3.client.services.IUserServices)
package com.kongregate.as3.client.services {
public interface IUserServices {
function getName():String;
function getPlayerInfo(_arg1:Function):void;
}
}//package com.kongregate.as3.client.services
Section 8
//KongregateServiceShadow (com.kongregate.as3.client.services.KongregateServiceShadow)
package com.kongregate.as3.client.services {
public class KongregateServiceShadow extends AbstractShadowService implements IKongregateServices {
public function getName():String{
alert("IKongregateServices", "getName");
return ("Guest");
}
public function connect(_arg1:Number=-1):Boolean{
alert("IKongregateServices", "connect", arguments);
return (true);
}
public function getPlayerInfo(_arg1:Function):void{
alert("IKongregateServices", "getPlayerInfo");
_arg1(new Object());
}
}
}//package com.kongregate.as3.client.services
Section 9
//StatServiceShadow (com.kongregate.as3.client.services.StatServiceShadow)
package com.kongregate.as3.client.services {
public class StatServiceShadow extends AbstractShadowService implements IStatServices {
public function submitArray(_arg1:Array):void{
alert("IStatServices", "submitArray", arguments);
}
public function submit(_arg1:String, _arg2:Number):void{
alert("IStatServices", "submitStat", arguments);
}
}
}//package com.kongregate.as3.client.services
Section 10
//UserServiceShadow (com.kongregate.as3.client.services.UserServiceShadow)
package com.kongregate.as3.client.services {
public class UserServiceShadow extends AbstractShadowService implements IUserServices {
public function getName():String{
alert("UserService", "getName");
return ("Guest");
}
public function getPlayerInfo(_arg1:Function):void{
alert("UserService", "getPlayerInfo");
_arg1({isGuest:true, name:"Guest", points:0, level:0, isMode:false, isAdmin:false, isDeveloper:false, avatarPath:"", chatAvatarPath:""});
}
}
}//package com.kongregate.as3.client.services
Section 11
//IAPIBootstrap (com.kongregate.as3.client.IAPIBootstrap)
package com.kongregate.as3.client {
import flash.events.*;
import flash.display.*;
public interface IAPIBootstrap {
function init(_arg1:Event=null, _arg2:Stage=null):void;
function hideLog():void;
function showLog(_arg1:int=0):void;
}
}//package com.kongregate.as3.client
Section 12
//KongregateAPI (com.kongregate.as3.client.KongregateAPI)
package com.kongregate.as3.client {
import flash.events.*;
import flash.display.*;
import com.kongregate.as3.client.events.*;
import com.kongregate.as3.client.services.*;
import flash.system.*;
import flash.net.*;
import flash.errors.*;
import flash.utils.*;
public class KongregateAPI extends Sprite {
private const VERSION:Number = 1;
private var loader:Loader;
private var loadedDomain:ApplicationDomain;
private static const CLASS_USER:String = "com.kongregate.as3.client.services.UserServices";
private static const CLASS_STATS:String = "com.kongregate.as3.client.services.StatServices";
private static const CLASS_SERVICES:String = "com.kongregate.as3.client.services.KongregateServices";
private static const CLASS_SCORES:String = "com.kongregate.as3.client.services.HighScoreServices";
private static const DEBUG_API_URL:String = "//Linuxpc/kongregate/public/flash/API_AS3.swf";
private static var _connected:Boolean;
private static var kUser:IUserServices;
private static var _loaded:Boolean;
private static var kServices:IKongregateServices;
private static var kScores:IHighScoreServices;
private static var mInstance:KongregateAPI;
private static var kStats:IStatServices;
private static var kAPI:IAPIBootstrap;
public function KongregateAPI(){
if (mInstance != null){
throw (new Error("Warning: KongregateAPI has been added to stage more than once or accessed improperly. Use getInstance() or a stage reference to access."));
};
mInstance = this;
this.addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
}
public function get loaded():Boolean{
return (_loaded);
}
public function get connected():Boolean{
return (_connected);
}
private function alertConnected(_arg1:TimerEvent=null):void{
var _local2:KongregateEvent;
var _local3:Boolean;
_local2 = new KongregateEvent(KongregateEvent.COMPLETE);
_local3 = this.dispatchEvent(_local2);
}
private function init(_arg1:Event):void{
var _local2:Object;
var _local3:String;
var _local4:URLRequest;
var _local5:LoaderContext;
this.removeEventListener(Event.ADDED_TO_STAGE, init);
_loaded = false;
_connected = false;
_local2 = LoaderInfo(root.loaderInfo).parameters;
_local3 = _local2.api_path;
if (_local3 == null){
trace("Alert: Kongregate API could not be loaded, due to local testing. API will load when the game is uploaded.");
createShadowServices();
return;
};
Security.allowDomain("*.kongregate.com");
Security.allowDomain("kongregatetrunk.com");
_local4 = new URLRequest(_local3);
_local5 = new LoaderContext(false);
_local5.applicationDomain = ApplicationDomain.currentDomain;
_local5.securityDomain = SecurityDomain.currentDomain;
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
loader.load(_local4, _local5);
}
public function get api():IAPIBootstrap{
return (kAPI);
}
private function loadComplete(_arg1:Event):void{
getServices();
}
public function get scores():IHighScoreServices{
return (kScores);
}
private function ioErrorHandler(_arg1:IOErrorEvent):void{
throw (new IOError(("API file not found. " + _arg1)));
}
public function get services():IKongregateServices{
return (kServices);
}
public function get stats():IStatServices{
return (kStats);
}
private function createShadowServices():void{
var _local1:Timer;
trace(">>> Kongregate Shadow Services instantiated for local development..");
kServices = new KongregateServiceShadow();
kScores = new HighScoreServiceShadow();
kStats = new StatServiceShadow();
kUser = new UserServiceShadow();
_local1 = new Timer(200, 1);
_local1.addEventListener(TimerEvent.TIMER_COMPLETE, alertConnected);
_local1.start();
_connected = true;
}
public function get user():IUserServices{
return (kUser);
}
private function getServices():void{
var _local1:ApplicationDomain;
var _local2:*;
var _local3:*;
var _local4:*;
var _local5:*;
_local1 = ApplicationDomain.currentDomain;
kAPI = IAPIBootstrap(loader.getChildAt(0));
this.addChild(loader);
_local2 = _local1.getDefinition(CLASS_SERVICES);
trace(_local2);
kServices = _local2.getInstance();
_local3 = _local1.getDefinition(CLASS_SCORES);
kScores = _local3.getInstance();
_local4 = _local1.getDefinition(CLASS_STATS);
kStats = _local4.getInstance();
_local5 = _local1.getDefinition(CLASS_USER);
kUser = _local5.getInstance();
kServices.connect(VERSION);
_loaded = true;
_connected = true;
alertConnected();
}
public static function getInstance():KongregateAPI{
if (!mInstance){
throw (new IllegalOperationError("You must add the Kongregate API component to the stage before attempting to access it."));
};
return (mInstance);
}
}
}//package com.kongregate.as3.client
Section 13
//MainTimeline (Swarm_fla.MainTimeline)
package Swarm_fla {
import flash.display.*;
public dynamic class MainTimeline extends MovieClip {
public const C_LEVELS:int = 1;
public var dead:DeadScreen;
public var m:MochiBot;
public var logic:GameLogic;
public var but:ButtonPane;
public var stats:Stats;
public function MainTimeline(){
super();
addFrameScript(0, frame1, 1, frame2, 2, frame3, 3, frame4, 4, frame5, 5, frame6);
}
function frame3(){
logic.startMusic();
logic.clearAll();
logic.menuMode = false;
logic.control.visible = true;
logic.initAll();
}
function frame6(){
dead = new DeadScreen(logic, this);
this.addChild(dead);
}
function frame5(){
gotoAndPlay(Constants.F_PLAY);
}
function frame1(){
m = MochiBot.track(this, "01800122");
this.addChild(new PreLoader(this));
stop();
}
function frame4(){
logic.step();
if (logic.won){
logic.sound.stopSounds();
logic.updateStats();
logic.control.visible = false;
gotoAndStop(Constants.F_WON);
};
}
function frame2(){
trace(2);
stats = new Stats();
this.addChild(stats.kong);
logic = new GameLogic(stats, 0);
logic.control.visible = false;
this.addChild(logic.board);
this.addChild(logic.control);
but = new ButtonPane(this);
this.addChild(but);
Key.initialize(stage);
gotoAndPlay(Constants.F_PLAY);
}
}
}//package Swarm_fla
Section 14
//AgainBut (AgainBut)
package {
import flash.display.*;
public dynamic class AgainBut extends SimpleButton {
public function AgainBut(){
super();
}
}
}//package
Section 15
//bang_1 (bang_1)
package {
import flash.media.*;
public dynamic class bang_1 extends Sound {
public function bang_1(){
super();
}
}
}//package
Section 16
//Bonus (Bonus)
package {
public class Bonus extends GObject {
public var type:int;
public static const T_SLOW = 3;
public static const T_ADD = 0;
public static const T_SPEED = 1;
public static const C_TYPES = 3;
public static const T_POINTS = 2;
public function Bonus(board:GameBoard, type:int){
super();
speed = 40;
this.board = board;
this.type = type;
this.acc = new Vec2f();
alive = true;
if (type == T_ADD){
this.addChild(new BonusSwarm());
} else {
if (type == T_SPEED){
this.addChild(new BonusSpeed());
} else {
if (type == T_POINTS){
this.addChild(new BonusPoints());
} else {
if (type == T_SLOW){
this.addChild(new BonusSlow());
};
};
};
};
}
override public function update(delta:Number){
var j:int;
super.update(delta);
if ((((((((this.x < 0)) || ((this.y < 0)))) || ((this.x > board.wid)))) || ((this.y > board.hgt)))){
this.alive = false;
};
j = 0;
while (j < board.swarmers.length) {
if (this.hitTestObject(board.swarmers[j])){
this.alive = false;
board.logic.useBonus(this);
break;
};
j++;
};
}
}
}//package
Section 17
//BonusPoints (BonusPoints)
package {
import flash.display.*;
public dynamic class BonusPoints extends MovieClip {
public function BonusPoints(){
super();
}
}
}//package
Section 18
//BonusSlow (BonusSlow)
package {
import flash.display.*;
public dynamic class BonusSlow extends MovieClip {
public function BonusSlow(){
super();
}
}
}//package
Section 19
//BonusSpeed (BonusSpeed)
package {
import flash.display.*;
public dynamic class BonusSpeed extends MovieClip {
public function BonusSpeed(){
super();
}
}
}//package
Section 20
//BonusSwarm (BonusSwarm)
package {
import flash.display.*;
public dynamic class BonusSwarm extends MovieClip {
public function BonusSwarm(){
super();
}
}
}//package
Section 21
//Bullet (Bullet)
package {
public class Bullet extends GObject {
public function Bullet(board:GameBoard){
super();
life = 1;
speed = 100;
this.board = board;
this.addChild(new BulletImg());
this.acc = new Vec2f();
}
public function addHitEffect(){
board.addEffect(Effect.T_BULLET_HIT, this.loc);
}
override public function update(delta:Number){
var j:int;
super.update(delta);
if (life < 0){
this.alive = false;
};
this.rotation = vel.getAngle();
if ((((((((this.x < 0)) || ((this.y < 0)))) || ((this.x > board.wid)))) || ((this.y > board.hgt)))){
this.alive = false;
};
j = 0;
while (j < board.enemies.length) {
if (this.hits(board.enemies[j])){
board.enemies[j].health--;
if (board.enemies[j].health <= 0){
board.enemies[j].addDeathEffect();
if (board.enemies[j].alive){
board.logic.addKill();
};
};
this.addHitEffect();
this.alive = false;
break;
};
j++;
};
}
}
}//package
Section 22
//BulletHit (BulletHit)
package {
import flash.display.*;
public dynamic class BulletHit extends MovieClip {
public function BulletHit(){
super();
addFrameScript(5, frame6);
}
function frame6(){
this.visible = false;
}
}
}//package
Section 23
//BulletImg (BulletImg)
package {
import flash.display.*;
public dynamic class BulletImg extends MovieClip {
public function BulletImg(){
super();
}
}
}//package
Section 24
//ButtonPane (ButtonPane)
package {
import flash.events.*;
import flash.display.*;
public class ButtonPane extends Sprite {
public var cred:CredPane;
public var inst:InstructPane;
public var buttons:Array;
public var lvls:int;
public var main:MovieClip;
public var menuP:MenuPane;
public function ButtonPane(main:MovieClip, lvls:int=0){
super();
buttons = new Array();
menuP = new MenuPane();
cred = new CredPane();
inst = new InstructPane();
this.addChild(menuP);
this.addChild(cred);
this.addChild(inst);
menuP.start.addEventListener(MouseEvent.MOUSE_UP, start);
menuP.instruct.addEventListener(MouseEvent.MOUSE_UP, instruct);
cred.menu.addEventListener(MouseEvent.MOUSE_UP, menu);
inst.menu.addEventListener(MouseEvent.MOUSE_UP, menu);
menuP.credBut.addEventListener(MouseEvent.MOUSE_UP, showCredits);
this.inst.visible = false;
this.cred.visible = false;
this.lvls = lvls;
this.main = main;
init();
}
public function init(){
}
public function instruct(e:MouseEvent){
menuP.visible = false;
inst.visible = true;
}
public function menu(e:MouseEvent){
menuP.visible = true;
inst.visible = false;
cred.visible = false;
}
public function start(e:MouseEvent){
main.gotoAndPlay(Constants.F_START);
this.visible = false;
}
public function update(stats:Stats){
}
public function showCredits(e:MouseEvent){
menuP.visible = false;
cred.visible = true;
}
}
}//package
Section 25
//Constants (Constants)
package {
public class Constants {
public static const F_MAIN:int = 2;
public static const F_START:int = 3;
public static const F_WON:int = 6;
public static const F_PLAY:int = 4;
public function Constants(){
super();
}
}
}//package
Section 26
//ControlPanel (ControlPanel)
package {
import flash.events.*;
import flash.display.*;
import flash.text.*;
public class ControlPanel extends MovieClip {
public var logic:GameLogic;
public var score:TextField;
public var muteBut:SoundBut;
public var pText:TextField;
public var time:TextField;
public var swarmers:TextField;
public function ControlPanel(logic:GameLogic){
super();
this.logic = logic;
this.x = 300;
this.y = 100;
this.muteBut.addEventListener(MouseEvent.MOUSE_UP, muteSound);
pText.visible = false;
}
public function muteSound(e:MouseEvent){
logic.sound.muteAll();
if (logic.sound.mute){
this.muteBut.gotoAndStop(2);
} else {
this.muteBut.gotoAndStop(1);
};
}
public function update(){
this.time.text = ("Time: " + logic.iTime.toString());
this.score.text = ("Score: " + logic.score.toString());
this.swarmers.text = ("Swarmers: " + logic.board.swarmers.length.toString());
}
}
}//package
Section 27
//CredBut (CredBut)
package {
import flash.display.*;
public dynamic class CredBut extends SimpleButton {
public function CredBut(){
super();
}
}
}//package
Section 28
//CredPane (CredPane)
package {
import flash.display.*;
public dynamic class CredPane extends MovieClip {
public var menu:MenuBut;
public function CredPane(){
super();
}
}
}//package
Section 29
//DeadScreen (DeadScreen)
package {
import flash.events.*;
import flash.display.*;
import flash.text.*;
public class DeadScreen extends MovieClip {
public var score:TextField;
public var again:AgainBut;
public var main:MovieClip;
public var time:TextField;
public var kills:TextField;
public function DeadScreen(logic:GameLogic, main:MovieClip){
super();
this.time.text = logic.iTime.toString();
this.score.text = logic.score.toString();
this.kills.text = logic.kills.toString();
this.main = main;
again.addEventListener(MouseEvent.MOUSE_UP, playAgain);
}
public function playAgain(e:MouseEvent){
main.gotoAndPlay(Constants.F_START);
this.visible = false;
}
}
}//package
Section 30
//Effect (Effect)
package {
import flash.display.*;
public class Effect extends GObject {
public var type:int;
public var mc:MovieClip;
public static const T_BULLET_HIT:int = 1;
public static const T_ENEMY_DEAD:int = 0;
public function Effect(type:int){
super();
this.type = type;
switch (type){
case T_ENEMY_DEAD:
mc = new EnemyImgDead();
break;
case T_BULLET_HIT:
mc = new BulletHit();
break;
};
this.addChild(mc);
}
override public function update(delta:Number){
if (!mc.visible){
this.alive = false;
};
}
}
}//package
Section 31
//Enemy (Enemy)
package {
public class Enemy extends GObject {
public var canKill:Boolean;
public var health:int;
public var skimTime:Number;
public var type:int;
public static const C_TYPES = 4;
public static const T_CHASER = 4;
public static const T_INVINCI = 3;
public static const T_SPLITTER = 1;
public static const T_SKIMMER = 2;
public static const T_SPLIT = 25;
public static const T_SPAWNER = 5;
public static const T_PLAIN = 0;
public function Enemy(board:GameBoard, type:int){
super();
speed = 50;
health = 5;
skimTime = 3;
canKill = true;
this.type = type;
this.board = board;
this.acc = new Vec2f();
alive = true;
if (this.type == T_PLAIN){
this.addChild(new EnemyImg());
} else {
if (this.type == T_SPLITTER){
this.addChild(new EnemySplitter());
this.life = 3;
} else {
if (this.type == T_SPLIT){
this.health = 2;
this.addChild(new EnemySplit());
} else {
if (this.type == T_SKIMMER){
this.addChild(new EnemySkimmer());
speed = 75;
} else {
if (this.type == T_INVINCI){
this.addChild(new EnemyInv());
this.health = 800;
} else {
if (this.type == T_CHASER){
this.addChild(new EnemyChaser());
this.health = 3;
this.speed = 30;
} else {
if (this.type == T_SPAWNER){
this.addChild(new EnemySpawner());
skimTime = 4;
canKill = false;
};
};
};
};
};
};
};
this.setBitmapData();
}
public function skim(){
var i:int;
i = Math.round((Math.random() * 3));
this.skimTime = 3;
if (i == 0){
this.setVel(new Vec2f(0, 1));
} else {
if (i == 1){
this.setVel(new Vec2f(0, -1));
} else {
if (i == 2){
this.setVel(new Vec2f(1, 0));
} else {
if (i == 3){
this.setVel(new Vec2f(-1, 0));
};
};
};
};
this.acc = vel.mult(-0.3);
}
public function spawn(){
}
public function findClosest():Swarmer{
var s:Swarmer;
var n:int;
var i:int;
s = null;
n = 4000;
i = 0;
while (i < board.swarmers.length) {
if (this.dist(board.swarmers[i]) < n){
n = this.dist(board.swarmers[i]);
s = board.swarmers[i];
};
i++;
};
return (s);
}
public function addSplits(){
var i:int;
var e:Enemy;
i = 0;
while (i < 4) {
e = new Enemy(board, T_SPLIT);
if (i == 0){
e.setVel(new Vec2f(1, 1));
} else {
if (i == 1){
e.setVel(new Vec2f(1, -1));
} else {
if (i == 2){
e.setVel(new Vec2f(-1, -1));
} else {
if (i == 3){
e.setVel(new Vec2f(-1, 1));
};
};
};
};
e.setLoc(this.loc.copy());
board.enemies.push(e);
board.addChild(e);
i++;
};
}
override public function update(delta:Number){
var j:int;
var s:Swarmer;
super.update(delta);
if ((((type == T_SKIMMER)) || (T_SPAWNER))){
skimTime = (skimTime - delta);
if ((((skimTime <= 0)) && ((type == T_SKIMMER)))){
skim();
} else {
if ((((skimTime <= 0)) && ((type == T_SPAWNER)))){
spawn();
};
};
};
if (this.type == T_CHASER){
s = findClosest();
if (s != null){
this.setVel(s.loc.minus(this.loc).normalise());
};
};
this.rotation = vel.getAngle();
if (((this.alive) && ((life <= 0)))){
alive = false;
addSplits();
};
if (health <= 0){
this.alive = false;
};
if ((((((((this.x < 0)) || ((this.y < 0)))) || ((this.x > board.wid)))) || ((this.y > board.hgt)))){
this.alive = false;
};
j = 0;
while (j < board.swarmers.length) {
if (this.hits(board.swarmers[j])){
board.logic.sound.playSoundClass(new sound4());
board.swarmers[j].alive = false;
};
j++;
};
}
public function addDeathEffect(){
board.addEffect(Effect.T_ENEMY_DEAD, this.loc);
}
}
}//package
Section 32
//EnemyChaser (EnemyChaser)
package {
import flash.display.*;
public dynamic class EnemyChaser extends MovieClip {
public function EnemyChaser(){
super();
}
}
}//package
Section 33
//EnemyImg (EnemyImg)
package {
import flash.display.*;
public dynamic class EnemyImg extends MovieClip {
public function EnemyImg(){
super();
}
}
}//package
Section 34
//EnemyImgDead (EnemyImgDead)
package {
import flash.display.*;
public dynamic class EnemyImgDead extends MovieClip {
public function EnemyImgDead(){
super();
addFrameScript(9, frame10);
}
function frame10(){
this.visible = false;
}
}
}//package
Section 35
//EnemyInv (EnemyInv)
package {
import flash.display.*;
public dynamic class EnemyInv extends MovieClip {
public function EnemyInv(){
super();
}
}
}//package
Section 36
//EnemySkimmer (EnemySkimmer)
package {
import flash.display.*;
public dynamic class EnemySkimmer extends MovieClip {
public function EnemySkimmer(){
super();
}
}
}//package
Section 37
//EnemySpawner (EnemySpawner)
package {
import flash.display.*;
public dynamic class EnemySpawner extends MovieClip {
public function EnemySpawner(){
super();
}
}
}//package
Section 38
//EnemySplit (EnemySplit)
package {
import flash.display.*;
public dynamic class EnemySplit extends MovieClip {
public function EnemySplit(){
super();
}
}
}//package
Section 39
//EnemySplitter (EnemySplitter)
package {
import flash.display.*;
public dynamic class EnemySplitter extends MovieClip {
public function EnemySplitter(){
super();
}
}
}//package
Section 40
//GameBoard (GameBoard)
package {
import flash.display.*;
public class GameBoard extends Sprite {
public var effects:Array;
public var bonuses:Array;
public var enemies:Array;
public var logic:GameLogic;
public var hgt:int;
public var bullets:Array;
public var wid;
public var player:Player;
public var swarmers:Array;
public function GameBoard(logic:GameLogic){
super();
player = new Player(this);
this.logic = logic;
this.addChild(player);
wid = 550;
hgt = 400;
initAll();
}
public function removeObject(index:int, a:Array){
removeChild(a[index]);
delete a[index];
a.splice(index, 1);
}
public function addBullet(s:Swarmer){
var b:Bullet;
b = new Bullet(this);
b.setLoc(s.loc.copy());
b.setVel(s.vel.copy().normalise());
b.vel.plusE(s.vel);
bullets.push(b);
this.addChild(b);
}
public function clearArray(a:Array){
var i:int;
i = 0;
while (i < a.length) {
this.removeChild(a[i]);
delete a[i];
i++;
};
}
public function clearAll(){
clearArray(enemies);
clearArray(bonuses);
clearArray(swarmers);
clearArray(bullets);
clearArray(effects);
}
public function addSwarmer(){
var s:Swarmer;
s = new Swarmer(this, player);
swarmers.push(s);
this.addChild(s);
logic.sound.playSoundClass(new sound21());
}
public function initAll(){
swarmers = new Array();
enemies = new Array();
bonuses = new Array();
bullets = new Array();
effects = new Array();
}
public function addEffect(id:int, loc:Vec2f){
var e:Effect;
e = new Effect(id);
e.setLoc(loc);
this.addChild(e);
effects.push(e);
}
}
}//package
Section 41
//GameLogic (GameLogic)
package {
import flash.events.*;
import flash.display.*;
import flash.utils.*;
public class GameLogic extends Sprite {
public const C_EDIVISOR = 19;
public const C_BONUSRATE = 15;
public const C_STARTSWARM = 10;
public const C_KILLSCORE = 10;
public var canWin:Boolean;
public var mute:Boolean;
public var sound:SoundPlayer;
public var paused:Boolean;
public var enemyGrowRate:Number;
public var deltMultGrow:Number;
public var control:ControlPanel;
public var toBonus:Number;
public var lastTime:Number;
public var level:int;
public var won:Boolean;
public var enemyRate:Number;
public var stats:Stats;
public var score:int;
public var bonusRate:Number;
public var toMenu:Boolean;
public var deltMult:Number;
public var menuMode:Boolean;
public var delt:Number;
public var time:Number;
public var kills:int;
public var iTime:int;
public var bonusGrowRate:Number;
public var toEnemy:Number;
public var board:GameBoard;
public function GameLogic(stats:Stats, level:int){
super();
this.stats = stats;
this.sound = new SoundPlayer();
this.level = level;
this.menuMode = true;
control = new ControlPanel(this);
board = new GameBoard(this);
board.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
board.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
initAll();
}
public function clearAll(){
board.clearAll();
}
public function mouseUp(e:MouseEvent){
board.player.order = Player.C_DRAW;
}
public function checkKeys(){
if (Key.isDown(80)){
paused = !(paused);
control.pText.visible = paused;
Key.removeKeyDown(80);
};
if (Key.isDown(77)){
control.muteSound(null);
Key.removeKeyDown(77);
};
}
public function startMusic(){
sound.loopSoundClass(new playground());
}
public function loopArray(a:Array){
var i:int;
i = 0;
while (i < a.length) {
a[i].update(delt);
if (!a[i].alive){
board.removeObject(i, a);
};
i++;
};
}
public function addObject(obj:GObject, b:Boolean){
var movX:Boolean;
var oppDir:Boolean;
var loc:*;
var vel:Vec2f;
movX = (Math.random() > 0.5);
oppDir = (Math.random() > 0.5);
if (movX){
loc = new Vec2f((oppDir) ? board.wid : 0, (Math.random() * board.hgt));
vel = new Vec2f((oppDir) ? -1 : 1, 0);
} else {
loc = new Vec2f((Math.random() * board.wid), (oppDir) ? board.hgt : 0);
vel = new Vec2f(0, (oppDir) ? -1 : 1);
};
vel.multE(deltMult);
obj.loc = loc;
obj.setVel(vel);
if (b){
board.bonuses.push(obj);
} else {
board.enemies.push(obj);
};
board.addChild(obj);
}
public function updateStats(){
stats.setStat(score, iTime, kills);
}
public function initAll(){
var i:int;
board.initAll();
this.time = 0;
this.iTime = 0;
this.score = 0;
this.kills = 0;
enemyRate = 1.5;
toEnemy = enemyRate;
bonusRate = C_BONUSRATE;
toBonus = bonusRate;
deltMult = 1;
deltMultGrow = 0.01;
board.player.x = 200;
board.player.y = 200;
paused = false;
won = false;
i = 0;
while (i < C_STARTSWARM) {
board.addSwarmer();
i++;
};
}
public function useBonus(b:Bonus){
var k:int;
if (b.type == Bonus.T_ADD){
k = 0;
while (k < 5) {
board.addSwarmer();
sound.playSoundClass(new sound21());
k++;
};
} else {
if (b.type == Bonus.T_SPEED){
board.player.speedBonus = (board.player.speedBonus + 0.1);
board.player.accBonus = (board.player.accBonus * 1.25);
sound.playSoundClass(new sound10());
} else {
if (b.type == Bonus.T_POINTS){
score = (score + (time * 5));
} else {
if (b.type == Bonus.T_SLOW){
deltMult = (deltMult - (deltMultGrow * 40));
};
};
};
};
}
public function setDelta(){
delt = ((getTimer() - lastTime) / 1000);
if ((((delt > 1)) || (isNaN(delt)))){
delt = 0;
};
lastTime = getTimer();
}
public function addKill(){
kills++;
this.score = (this.score + C_KILLSCORE);
sound.playSoundClass(new bang_1());
}
public function getEnemyType():int{
return (Math.round((Math.random() * Math.min(Enemy.C_TYPES, (iTime / C_EDIVISOR)))));
}
public function update(){
time = (time + delt);
if (!menuMode){
if ((time - iTime) >= 1){
iTime = time;
score = (score + board.swarmers.length);
deltMult = (deltMult + deltMultGrow);
};
toEnemy = (toEnemy - (delt * (deltMult * deltMult)));
if (toEnemy <= 0){
toEnemy = (enemyRate + ((Math.random() - 0.5) * enemyRate));
addObject(new Enemy(board, getEnemyType()), false);
};
toBonus = (toBonus - (delt * deltMult));
if (toBonus <= 0){
toBonus = (bonusRate + ((Math.random() - 0.5) * bonusRate));
addObject(new Bonus(board, Math.round((Math.random() * Bonus.C_TYPES))), true);
};
};
loopArray(board.swarmers);
loopArray(board.bullets);
loopArray(board.enemies);
loopArray(board.bonuses);
loopArray(board.effects);
if (board.swarmers.length == 0){
won = true;
};
}
public function step(){
setDelta();
if (delt == 0){
return;
};
checkKeys();
if (paused){
return;
};
control.update();
board.player.update(delt);
update();
}
public function mouseDown(e:MouseEvent){
board.player.order = Player.C_PUSH;
}
}
}//package
Section 42
//GObject (GObject)
package {
import flash.display.*;
public class GObject extends MovieClip {
public var life:Number;
public var speed:Number;
public var loc:Vec2f;
public var acc:Vec2f;
public var vel:Vec2f;
public var bmData:BitmapData;
public var alive:Boolean;
public var board:GameBoard;
public function GObject(){
super();
this.alive = true;
this.acc = new Vec2f(0, 0);
this.vel = new Vec2f(0, 0);
life = 1000;
}
public function setBitmapData(){
bmData = new BitmapData(this.width, this.height);
}
public function dist(o:GObject){
return (this.loc.dist(o.loc));
}
public function hits(obj:GObject):Boolean{
if (!this.hitTestObject(obj)){
return (false);
};
return (true);
}
public function update(delta:Number){
this.vel.plusE(acc.mult(delta));
this.loc.plusE(vel.mult(delta));
this.x = loc.x;
this.y = loc.y;
life = (life - delta);
}
public function setLoc(l:Vec2f){
this.loc = l;
this.x = loc.x;
this.y = loc.y;
}
public function setVel(v:Vec2f){
this.vel = v.multE((speed + (Math.random() * speed)));
}
}
}//package
Section 43
//InstructBut (InstructBut)
package {
import flash.display.*;
public dynamic class InstructBut extends SimpleButton {
public function InstructBut(){
super();
}
}
}//package
Section 44
//InstructPane (InstructPane)
package {
import flash.display.*;
public dynamic class InstructPane extends MovieClip {
public var menu:MenuBut;
public function InstructPane(){
super();
}
}
}//package
Section 45
//Key (Key)
package {
import flash.events.*;
import flash.display.*;
public class Key {
private static var initialized:Boolean = false;
private static var keysDown:Object = new Object();
public function Key(){
super();
}
public static function initialize(stage:Stage){
if (!initialized){
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
stage.addEventListener(Event.DEACTIVATE, clearKeys);
initialized = true;
};
}
public static function clearKeys(event:Event):void{
keysDown = new Object();
}
public static function isDown(keyCode:uint):Boolean{
if (!initialized){
throw (new Error("Key class has yet been initialized."));
};
return (Boolean((keyCode in keysDown)));
}
private static function keyPressed(event:KeyboardEvent):void{
keysDown[event.keyCode] = true;
trace(event.keyCode);
}
private static function keyReleased(event:KeyboardEvent):void{
if ((event.keyCode in keysDown)){
delete keysDown[event.keyCode];
};
}
public static function removeKeyDown(key:uint):void{
if ((key in keysDown)){
delete keysDown[key];
};
}
}
}//package
Section 46
//LinkButton (LinkButton)
package {
import flash.display.*;
public dynamic class LinkButton extends SimpleButton {
public function LinkButton(){
super();
}
}
}//package
Section 47
//LoadBut (LoadBut)
package {
import flash.display.*;
public dynamic class LoadBut extends SimpleButton {
public function LoadBut(){
super();
}
}
}//package
Section 48
//LoadCircle (LoadCircle)
package {
import flash.display.*;
public dynamic class LoadCircle extends MovieClip {
public function LoadCircle(){
super();
}
}
}//package
Section 49
//MenuBut (MenuBut)
package {
import flash.display.*;
public dynamic class MenuBut extends SimpleButton {
public function MenuBut(){
super();
}
}
}//package
Section 50
//MenuPane (MenuPane)
package {
import flash.display.*;
public dynamic class MenuPane extends MovieClip {
public var start:StartBut;
public var credBut:CredBut;
public var instruct:InstructBut;
public function MenuPane(){
super();
}
}
}//package
Section 51
//MochiBot (MochiBot)
package {
import flash.display.*;
import flash.system.*;
import flash.net.*;
public dynamic class MochiBot extends Sprite {
public function MochiBot(){
super();
}
public static function track(parent:Sprite, tag:String):MochiBot{
var self:MochiBot;
var server:String;
var lv:URLVariables;
var url:String;
var req:URLRequest;
var loader:Loader;
if (Security.sandboxType == "localWithFile"){
return (null);
};
self = new (MochiBot);
parent.addChild(self);
Security.allowDomain("*");
Security.allowInsecureDomain("*");
server = "http://core.mochibot.com/my/core.swf";
lv = new URLVariables();
lv["sb"] = Security.sandboxType;
lv["v"] = Capabilities.version;
lv["swfid"] = tag;
lv["mv"] = "8";
lv["fv"] = "9";
url = self.root.loaderInfo.loaderURL;
if (url.indexOf("http") == 0){
lv["url"] = url;
} else {
lv["url"] = "local";
};
req = new URLRequest(server);
req.contentType = "application/x-www-form-urlencoded";
req.method = URLRequestMethod.POST;
req.data = lv;
loader = new Loader();
self.addChild(loader);
loader.load(req);
return (self);
}
}
}//package
Section 52
//Player (Player)
package {
import flash.display.*;
public class Player extends MovieClip {
public var accBonus:Number;
public var speedBonus:Number;
public var order:int;
public var loc:Vec2f;
public var maxSwarm:int;
public var timeLeft:Number;
public var cirRad:int;
public var rate:Number;
public var board:GameBoard;
public static const C_DRAW:int = 1;
public static const C_PUSH:int = 2;
public static const C_CIRCLE:int = 3;
public function Player(board:GameBoard){
super();
rate = 10;
speedBonus = 1;
accBonus = 1;
timeLeft = rate;
maxSwarm = 200;
cirRad = 50;
this.board = board;
order = C_DRAW;
loc = new Vec2f();
}
public function update(delta:Number){
timeLeft = (timeLeft - delta);
if ((((timeLeft <= 0)) && (!(board.logic.menuMode)))){
board.addSwarmer();
timeLeft = rate;
};
this.x = stage.mouseX;
this.y = stage.mouseY;
loc.x = this.x;
loc.y = this.y;
}
}
}//package
Section 53
//playground (playground)
package {
import flash.media.*;
public dynamic class playground extends Sound {
public function playground(){
super();
}
}
}//package
Section 54
//PreLoader (PreLoader)
package {
import flash.events.*;
import flash.display.*;
import flash.text.*;
import flash.net.*;
public class PreLoader extends MovieClip {
public var link:LinkButton;
public var pAdd:Number;
public var loadText:TextField;
public var numCircles:int;
public var main:MovieClip;
public var loadBut:LoadBut;
public var totalCircles:int;
public function PreLoader(main:MovieClip){
super();
this.main = main;
this.x = 275;
this.y = 200;
totalCircles = 16;
numCircles = 1;
pAdd = (1 / totalCircles);
main.loaderInfo.addEventListener(ProgressEvent.PROGRESS, checkProgress);
main.loaderInfo.addEventListener(Event.COMPLETE, fileLoaded);
this.loadBut.visible = false;
loadBut.addEventListener(MouseEvent.MOUSE_UP, startGame);
link.addEventListener(MouseEvent.MOUSE_UP, visitSite);
}
public function visitSite(e:MouseEvent){
navigateToURL(new URLRequest("http://www.moojoogames.com"));
}
function checkProgress(p:ProgressEvent):void{
var percent:int;
var lc:LoadCircle;
var dir:Vec2f;
percent = (p.currentTarget.bytesLoaded / p.currentTarget.bytesTotal);
while ((((percent >= (numCircles * pAdd))) && ((percent <= 1)))) {
numCircles++;
lc = new LoadCircle();
dir = Vec2f.FromAngle((((numCircles * pAdd) * 2) * Math.PI), 120);
lc.x = dir.x;
lc.y = dir.y;
this.addChild(lc);
};
}
public function startGame(e:MouseEvent){
main.removeChild(this);
main.gotoAndPlay(Constants.F_MAIN);
}
function fileLoaded(e:Event):void{
this.loadBut.visible = true;
this.loadText.visible = false;
}
}
}//package
Section 55
//sound10 (sound10)
package {
import flash.media.*;
public dynamic class sound10 extends Sound {
public function sound10(){
super();
}
}
}//package
Section 56
//sound21 (sound21)
package {
import flash.media.*;
public dynamic class sound21 extends Sound {
public function sound21(){
super();
}
}
}//package
Section 57
//sound4 (sound4)
package {
import flash.media.*;
public dynamic class sound4 extends Sound {
public function sound4(){
super();
}
}
}//package
Section 58
//SoundBut (SoundBut)
package {
import flash.display.*;
public dynamic class SoundBut extends MovieClip {
public function SoundBut(){
super();
addFrameScript(0, frame1);
}
function frame1(){
this.mouseChildren = false;
this.buttonMode = true;
stop();
}
}
}//package
Section 59
//SoundPlayer (SoundPlayer)
package {
import flash.media.*;
import flash.net.*;
public class SoundPlayer {
public var loops:Array;
public var mute:Boolean;
public function SoundPlayer(){
super();
loops = new Array();
mute = false;
}
public function stopSounds(){
var i:int;
i = 0;
while (i < loops.length) {
loops[i].stop();
i++;
};
}
public function muteAll(){
var st:SoundTransform;
var i:int;
mute = !(mute);
st = new SoundTransform();
st.volume = (mute) ? 0 : 1;
i = 0;
while (i < loops.length) {
loops[i].soundTransform = st;
i++;
};
}
public function loopSound(s:String){
var sc:SoundChannel;
sc = new Sound(new URLRequest(s)).play(0, 10000);
loops.push(sc);
}
public function loopSoundClass(s:Sound){
var sc:SoundChannel;
sc = s.play(0, 10000);
loops.push(sc);
}
public function playSoundClass(s:Sound){
if (!mute){
s.play();
};
}
}
}//package
Section 60
//StartBut (StartBut)
package {
import flash.display.*;
public dynamic class StartBut extends SimpleButton {
public function StartBut(){
super();
}
}
}//package
Section 61
//Stats (Stats)
package {
import com.kongregate.as3.client.events.*;
import com.kongregate.as3.client.*;
public class Stats {
public var time:int;
public var score:int;
public var kong:KongregateAPI;
public var apiLoaded:Boolean;
public function Stats(){
super();
score = 0;
time = 0;
apiLoaded = false;
kong = new KongregateAPI();
kong.addEventListener(KongregateEvent.COMPLETE, apiDone);
}
public function setStat(score:int, time:int, kills:int){
score = Math.max(score, this.score);
time = Math.max(time, this.time);
kong.scores.submit(score, "SCORE");
kong.scores.submit(time, "TIME");
kong.stats.submit("SCORE", score);
kong.stats.submit("TIME", time);
kong.stats.submit("KILLS", kills);
}
public function apiDone(e:KongregateEvent):void{
apiLoaded = true;
}
}
}//package
Section 62
//Swarmer (Swarmer)
package {
public class Swarmer extends GObject {
public var offsetY:Number;
public var offsetX;
public var fireRate:Number;
public var maxAcc:Number;
public var maxVel:Number;
public var tillFire:Number;
public var player:Player;
public function Swarmer(board:GameBoard, player:Player){
super();
this.fireRate = (0.5 + (Math.random() * 0.2));
this.tillFire = fireRate;
maxAcc = (200 + (Math.random() * 100));
maxVel = (100 + (Math.random() * 70));
offsetX = ((Math.random() - 0.5) / 4);
offsetY = ((Math.random() - 0.5) / 4);
this.loc = new Vec2f(player.x, player.y);
this.x = player.x;
this.y = player.y;
this.vel = Vec2f.rand().multE(maxVel);
this.acc = new Vec2f();
this.player = player;
this.board = board;
this.alive = true;
this.addChild(new SwarmerImg());
}
public function ordCircle(){
var r:Number;
var x1:Number;
var dir:Vec2f;
r = this.loc.minus(player.loc).getR();
if (r < player.cirRad){
ordPush();
return;
};
x1 = Math.acos((player.cirRad / r));
dir = Vec2f.FromAngle(x1, 1);
if (this.loc.plus(dir).dist(player.loc) > loc.dist(player.loc)){
dir.multE(-1);
};
if (((((isNaN(x1)) || (isNaN(dir.x)))) || (isNaN(dir.y)))){
x1 = 0;
};
this.acc = dir.multE(maxAcc);
}
public function ordPush(){
var dir:Vec2f;
dir = loc.minus(player.loc).normalise();
dir.x = (dir.x + offsetX);
dir.y = (dir.y + offsetY);
this.acc = dir.multE((maxAcc * player.accBonus));
}
public function ordDraw(){
var dir:Vec2f;
dir = player.loc.minus(this.loc).normalise();
dir.x = (dir.x + offsetX);
dir.y = (dir.y + offsetY);
this.acc = dir.multE((maxAcc * player.accBonus));
}
override public function update(delta:Number){
if (!player.board.logic.menuMode){
this.tillFire = (this.tillFire - delta);
if (tillFire <= 0){
tillFire = fireRate;
board.addBullet(this);
};
};
this.vel.plusE(acc.mult(delta)).limitTo((maxVel * player.speedBonus));
this.loc.plusE(vel.mult(delta));
this.rotation = vel.getAngle();
this.x = loc.x;
this.y = loc.y;
checkBounds();
switch (player.order){
case Player.C_DRAW:
ordDraw();
break;
case Player.C_PUSH:
ordPush();
break;
};
}
public function checkBounds(){
if ((((loc.x < 0)) && ((vel.x < 0)))){
vel.x = (vel.x * -1);
};
if ((((loc.y < 0)) && ((vel.y < 0)))){
vel.y = (vel.y * -1);
};
if ((((loc.x > board.wid)) && ((vel.x > 0)))){
vel.x = (vel.x * -1);
};
if ((((loc.y > board.hgt)) && ((vel.y > 0)))){
vel.y = (vel.y * -1);
};
}
}
}//package
Section 63
//SwarmerImg (SwarmerImg)
package {
import flash.display.*;
public dynamic class SwarmerImg extends MovieClip {
public function SwarmerImg(){
super();
}
}
}//package
Section 64
//Vec2f (Vec2f)
package {
public class Vec2f {
public var x:Number;
public var y:Number;
public function Vec2f(x:Number=0, y:Number=0){
super();
this.x = x;
this.y = y;
}
public function getR():Number{
return (Math.sqrt(((x * x) + (y * y))));
}
public function dist(v:Vec2f):Number{
return (v.minus(this).getR());
}
public function plusE(v:Vec2f):Vec2f{
x = (x + v.x);
y = (y + v.y);
return (this);
}
public function toString():String{
return ((((("(" + x.toString()) + ",") + y.toString()) + ")"));
}
public function normalise():Vec2f{
var r:Number;
r = Math.sqrt(((x * x) + (y * y)));
return (new Vec2f((x / r), (y / r)));
}
public function copy():Vec2f{
return (new Vec2f(this.x, this.y));
}
public function limitTo(n:Number):Vec2f{
var r:Number;
r = Math.sqrt(((x * x) + (y * y)));
if (r > n){
x = (x * (n / r));
y = (y * (n / r));
};
return (this);
}
public function minus(v:Vec2f):Vec2f{
return (new Vec2f((x - v.x), (y - v.y)));
}
public function plus(v:Vec2f):Vec2f{
return (new Vec2f((v.x + x), (v.y + y)));
}
public function multE(n:Number):Vec2f{
x = (x * n);
y = (y * n);
return (this);
}
public function getAngle():Number{
var n:Number;
if (x == 0){
return (((y > 0)) ? 90 : 270);
//unresolved jump
};
n = ((Math.atan((y / x)) * 180) / Math.PI);
if (x < 0){
n = (n + 180);
};
return (n);
}
public function mult(n:Number):Vec2f{
return (new Vec2f((this.x * n), (this.y * n)));
}
public static function FromAngle(t:Number, r:Number):Vec2f{
return (new Vec2f((Math.sin(t) * r), (Math.cos(t) * r)));
}
public static function rand():Vec2f{
return (new Vec2f((Math.random() - 0.5), (Math.random() - 0.5)));
}
}
}//package