Created
May 14, 2011 22:55
-
-
Save MattMcFarland/972727 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package campaign.Action | |
{ | |
import adobe.utils.CustomActions; | |
import campaign.Action.Objects.Roid; | |
import campaign.Galaxy.galaxymap; | |
import com.bit101.components.NumericStepper; | |
import editor.edUI; | |
import flash.utils.ByteArray; | |
import net.flashpunk.Entity; | |
import flash.events.Event; | |
import flash.net.URLLoader; | |
import flash.net.URLRequest | |
import net.flashpunk.FP; | |
import net.flashpunk.graphics.Graphiclist; | |
import net.flashpunk.graphics.Image; | |
import net.flashpunk.graphics.Spritemap; | |
import net.flashpunk.graphics.Text | |
import com.mcfarland.msgbox; | |
import campaign.Action.Objects.baddie; | |
import com.nuffrespec.utils.XMLUtils; | |
import net.flashpunk.tweens.misc.Alarm; | |
import net.flashpunk.tweens.misc.VarTween; | |
import net.flashpunk.utils.Input; | |
import net.flashpunk.utils.Key; | |
import net.flashpunk.utils.Ease; | |
import net.flashpunk.Sfx; | |
import utils.screenTransitions.screenFader; | |
import com.shockwave.Achievements2; | |
/** | |
* ... | |
* @author Matt McFarland | |
*/ | |
public class LevelHandler extends Entity | |
{ | |
public var Timing:Number = 0; | |
public static var LevelData:XML; | |
public var LevelDesign:XML; | |
public var LevelEnemies:XMLList; | |
public var LevelMessages:XMLList; | |
public var messageAmount:int | |
public var messageIndex:int = 0; | |
public var nextMessageTime:Number; | |
public static var EnemyAmount:int; | |
public var NextEnemyTime:Number; | |
public static var loadlevel:int; | |
public var killpercentage:int; | |
public var uniqueID:int; | |
public static var powerupcount:int; | |
public var messageDestroyDelay:Array = []; | |
public var tweenSetting:String; | |
public var messageText:Array = []; | |
public var movetextTween:Array = []; | |
public var alphatextTween:Array = []; | |
public var removeTextTween:Array = []; | |
public var removealphaTextTween:Array = []; | |
public var enemyIndex:int = 0; | |
public var stopUpdater:Boolean = false; | |
public var editmode:Boolean = false; | |
public var objectives:Array = []; | |
public var oHeader:Text; | |
public var resourceLevel:Boolean = false; | |
public var clearLevel:Boolean = false; | |
public var resourcesCollected:Boolean = false; | |
public var roidLevel:Boolean = false; | |
public var roidLength:Number = 0; | |
public var roidMinRate:Number = 0; | |
public var roidMaxRate:Number = 0; | |
public var roidSpeedMod:Number = 0; | |
public var nextRoidTime:Number = 0; | |
public var nextBGRoidTime:Number = 0; | |
public var roidTint:uint = 0xFFFFFF; | |
public var makeIndex:int = 0; | |
public var infiniteMode:Boolean = false; | |
public var iLevelIndex:int; | |
public var inBetweenLevels:Boolean = false; | |
public var achievement:Achievements2; //Achievements Class | |
public var ach_initObj:Object = new Object(); //Achievement Object | |
public var dataObject:Object = new Object(); //Data Obj for storing Score | |
public var responseObject:Object = new Object(); //Response Obj | |
public var achievementsReady:Boolean; //Lets the game know it can send the score | |
/** | |
* Loads and plays level data. | |
* @param _loadlevel Level to load (-1(custom) or 0(no level) are custom switches)) | |
* @param customXML Custom XML to load | |
*/ | |
public function LevelHandler(_loadlevel:int,customXML:XML=null) | |
{ | |
name = "levelHandler"; | |
layer = -5; | |
loadlevel = _loadlevel; | |
if (FP.stage.quality != "LOW") Timing = -5; | |
else Timing = -4; | |
gameworld.enemies = new Array(); | |
gameworld.isComplete = false; | |
// -1 argument tells level handler we are playing a custom level. | |
if (loadlevel == -1) playCustom(customXML); | |
// 0 argument tells level handler we are playing from editor | |
if (loadlevel == 0) { designXML(); editmode = true; } | |
} | |
override public function added():void | |
{ | |
// Load campaign levels. | |
if (loadlevel == 1) processXML(LVL._01); | |
if (loadlevel == 2) processXML(LVL._02); | |
if (loadlevel == 3) processXML(LVL._03); | |
if (loadlevel == 4) processXML(LVL._04); | |
if (loadlevel == 5) processXML(LVL._05); | |
if (loadlevel == 6) processXML(LVL._06); | |
if (loadlevel == 7) processXML(LVL._07); | |
if (loadlevel == 8) processXML(LVL._08); | |
if (loadlevel == 9) processXML(LVL._09); | |
if (loadlevel == 10) processXML(LVL._10); | |
if (loadlevel == 11) processXML(LVL._11); | |
if (loadlevel == 12) processXML(LVL._12); | |
if (loadlevel == 13) processXML(LVL._13); | |
if (loadlevel == 14) processXML(LVL._14); | |
if (loadlevel == 15) processXML(LVL._15); | |
if (loadlevel == 16) processXML(LVL._16); | |
if (loadlevel == 17) processXML(LVL._17); | |
if (loadlevel == 18) processXML(LVL._18); | |
if (loadlevel == 19) processXML(LVL._19); | |
if (loadlevel == 20) processXML(LVL._20); | |
if (loadlevel == 21) processXML(LVL._21); | |
if (loadlevel == 22) processXML(LVL._22); | |
if (loadlevel == 23) processXML(LVL._23); | |
if (loadlevel == 24) processXML(LVL._24); | |
if (loadlevel == 25) processXML(LVL._25); | |
if (loadlevel == 26) processXML(LVL._26); | |
if (loadlevel == 27) processXML(LVL._27); | |
if (loadlevel == 28) processXML(LVL._28); | |
if (loadlevel == 29) processXML(LVL._29); | |
if (loadlevel == 30) processXML(LVL._30); | |
if (loadlevel == 31) { | |
processXML(LVL.INF); | |
iLevelIndex = 1; | |
infiniteMode = true; | |
} | |
if (loadlevel == 32) processXML(LVL.N1S1); | |
if (loadlevel == 33) processXML(LVL.N1S2); | |
if (loadlevel == 34) processXML(LVL.N2S1); | |
if (loadlevel == 35) processXML(LVL.N2S2); | |
if (loadlevel == 36) processXML(LVL.N3S1); | |
if (loadlevel == 37) processXML(LVL.N3S2); | |
if (loadlevel == 38) processXML(LVL.N3S3); | |
if (loadlevel == 39) processXML(LVL.N4S1); | |
if (loadlevel == 40) processXML(LVL.N4S2); | |
if (loadlevel == 41) processXML(LVL.N4S3); | |
if (loadlevel == 42) processXML(LVL.N5S1); | |
if (loadlevel == 43) processXML(LVL.N5S2); | |
if (loadlevel == 44) processXML(LVL.N5S3); | |
create_achObj(); | |
} | |
//Setup all the necessary information to send the Score and Game Id | |
private function create_achObj():void { | |
//DEVELOPER - Fill out the following elements of the achievement object (Given to you) | |
ach_initObj["SourceElementType"] = "Game"; | |
ach_initObj["SourceElementReference"] = "starcede"; | |
//******************************** TESTING LOCALLY ***********************************// | |
// /** //For TESTING LOCALLY uncomment this entire section... This will allow you to bypass calls to the router.. | |
//For DEPLOYMENT make sure this section is commented out. | |
ach_initObj["DEBUGMODE"] = "true"; | |
ach_initObj["em_url"] = "http://dev.eventmanager.shockwave.com/eventmanager/event/ejta"; | |
ach_initObj["hs_url"] = "http://dev.highscores.shockwave.com/highscores/servlet/AddScore"; | |
ach_initObj["sdk_url"] = "http://dev.shockwave.com/content/achievements/sdk_as3.swf"; | |
ach_initObj["status_url"] = "http://dev.shockwave.com/util/hs.jsp"; | |
ach_initObj["skip_router"] = "true"; | |
// **/ | |
//***********************************************************************************// | |
//Creates the Achievements Object, passes in the game and the Achievement Object we just created | |
achievement = new Achievements2(FP.stage, ach_initObj); | |
//Listens for when the achievement class is ready | |
achievement.addEventListener("achievementsready", onAchReady); | |
} | |
//Event to notify when the Achievements Class is ready | |
private function onAchReady(e:Event):void { | |
trace("[TEST.as] Achievements Class Ready"); | |
//Clean up | |
e.stopImmediatePropagation(); | |
achievement.removeEventListener("achievementsready", onAchReady); | |
//The Achievements Class is now ready and can be used. | |
achievementsReady = true; | |
} | |
/** | |
* Create NEW BLANK XML Data (LevelData) | |
*/ | |
public function designXML():void | |
{ | |
LevelDesign = new XML( <level title="Custom"></level>); | |
LevelData = new XML(LevelDesign); | |
} | |
/** | |
* Load custom XML Data | |
*/ | |
public function playCustom(xml:XML):void | |
{ | |
LevelData = xml; | |
LevelEnemies = LevelData.enemy; | |
EnemyAmount = int(LevelEnemies.length()); | |
NextEnemyTime = LevelEnemies.@time[0]; | |
FP.rate = 1; | |
} | |
/** | |
* PROCESS XML Data from loaded level | |
* @param xml Only used for embedded levels (main 1-30) | |
*/ | |
public function processXML(xml:Class):void | |
{ | |
gameworld.enemies = []; | |
inBetweenLevels = false; | |
var RawData:ByteArray = new xml; | |
var DataString:String = RawData.readUTFBytes(RawData.length); | |
LevelData = new XML(DataString); | |
LevelEnemies = LevelData.enemy; | |
EnemyAmount = int(LevelEnemies.length()); | |
NextEnemyTime = LevelEnemies.@time[0]; | |
LevelMessages = LevelData.message; | |
messageAmount = int(LevelMessages.length()); | |
nextMessageTime = LevelMessages.@time[0]; | |
var BackGrounds:XMLList = LevelData.backgrounds.add; | |
var totalBG:int = int(BackGrounds.length()); | |
var counter:int = 0; | |
while (counter < totalBG) | |
{ | |
var tmpElement:XML = BackGrounds[counter] | |
world.add(new bg(tmpElement.@type, int(tmpElement.@layer), uint(tmpElement.@color), Number(tmpElement.@speed))); | |
counter++; | |
} | |
if (!infiniteMode) { | |
var objectiveList:XMLList = LevelData.Objective; | |
var totalObjectives:int = int(objectiveList.length()); | |
var i:int = 0; | |
while (i < totalObjectives) | |
{ | |
var newObj:objective = new objective(); | |
var newObjective:XML = objectiveList[i]; | |
if (newObjective.@type == "collect") { | |
newObj.add(i, "collect", int(newObjective.@amount), newObjective.@what); | |
resourceLevel = true; | |
} | |
if (newObjective.@type == "clear") { | |
newObj.add(i, "clear", Number(newObjective.@amount)); | |
clearLevel = true; | |
} | |
objectives.push(newObj); | |
i++; | |
} | |
if (objectives.length > 0) { | |
addObjectives(); | |
} | |
} | |
var roidz:XMLList = LevelData.asteroids; | |
var roid:XML = roidz[0]; | |
if (!roid) return; | |
roidLength = roid.@length; | |
roidMinRate = roid.@minRate; | |
roidMaxRate = roid.@maxRate; | |
roidSpeedMod = roid.@sMod; | |
nextRoidTime = roid.@start; | |
roidLevel = true; | |
} | |
private function addObjectives():void | |
{ | |
oHeader = new Text("Objectives"); | |
var screen:Number = FP.halfWidth; | |
var mid:Number = FP.halfHeight-objectives.length*20; | |
world.add (new Entity(screen - oHeader.width/2, mid - objectives.length - 20, oHeader)); | |
var i:int = 0; | |
for each (var o:objective in objectives) | |
{ | |
o.y = mid + i * 20; | |
world.add(o); | |
i++ | |
} | |
} | |
/** | |
* PARSE LEVEL DATA - Read XML Data and create enemy que | |
* @param xml XML to read | |
*/ | |
public function ParseLevelData(xml:XML):void | |
{ | |
XMLUtils.sortXMLByAttribute(xml, 'time', Array.NUMERIC); | |
LevelData = new XML(xml); | |
LevelEnemies = LevelData.enemy; | |
EnemyAmount = int(LevelEnemies.length()); | |
NextEnemyTime = LevelEnemies.@time[0]; | |
enemyIndex = 0; | |
} | |
/** | |
* UPDATE - Main Update Format | |
*/ | |
override public function update():void | |
{ | |
if ((world.typeCount("dead")) > 300) { | |
var removeEnemies:Array = []; | |
world.getType("dead", removeEnemies); | |
for each (var del:Entity in removeEnemies) | |
{ | |
world.remove(del); | |
} | |
removeEnemies = []; | |
} | |
if (oHeader && oHeader.alpha > 0) { | |
oHeader.alpha -= FP.elapsed/2.8; | |
} | |
if (stopUpdater) return; | |
//viewConsole(); | |
//Add Timing. | |
Timing += FP.elapsed; | |
//Check if its a resource type level | |
if (!resourceLevel) { | |
if (enemyIndex < EnemyAmount) CheckForEnemies(); | |
} else { | |
var getNext:Boolean = false; | |
for each (var o:objective in objectives) { | |
if (!o.isComplete) getNext = true; | |
} | |
if (getNext) { | |
if (enemyIndex >= EnemyAmount) { | |
NextEnemyTime = LevelEnemies.@time[0]; | |
enemyIndex = 0; | |
Timing = 0; | |
} | |
CheckForEnemies(); | |
} else { | |
resourcesCollected = true; | |
} | |
} | |
if (messageAmount > 0) CheckForMessages(); | |
// Check if we are in editor, playing a custom level or neither. | |
if (loadlevel == 0) { editor_update();} | |
else {game_update();} | |
if (infiniteMode && !inBetweenLevels) { | |
if (enemyIndex < EnemyAmount) return; | |
if (gameworld.PlayerDead) return; | |
if (world.typeCount("baddie") > 0) return; | |
if (world.typeCount("collectable") > 0) return; | |
if (world.typeCount("doodad") > 0) return; | |
if (world.typeCount("ebullet") > 0) return; | |
trace (world.typeCount("baddie")); | |
iLevelIndex ++; | |
if (iLevelIndex == 31) { | |
iLevelIndex = 2; | |
} | |
var fx:Sfx = new Sfx(SFX.WARP_OUT); | |
if (!GV.muteSound) fx.play(); | |
var loadTween:Alarm = new Alarm(1.8,getNextLevel); | |
addTween(loadTween, true); | |
inBetweenLevels = true; | |
} | |
} | |
private function getNextLevel():void | |
{ | |
var removeEnemies:Array = []; | |
world.getType("dead", removeEnemies); | |
for each (var del:Entity in removeEnemies) | |
{ | |
world.remove(del); | |
} | |
removeEnemies = []; | |
screenFader.In(.5, 0xFFFFFF); | |
var bgs:Array = []; | |
world.getClass(bg, bgs) | |
for each (var b:bg in bgs) | |
{ | |
b.fade(2); | |
} | |
if (iLevelIndex == 1) processXML(LVL._01); | |
if (iLevelIndex == 2) processXML(LVL._02); | |
if (iLevelIndex == 3) processXML(LVL._03); | |
if (iLevelIndex == 4) processXML(LVL._04); | |
if (iLevelIndex == 5) processXML(LVL._05); | |
if (iLevelIndex == 6) processXML(LVL._06); | |
if (iLevelIndex == 7) processXML(LVL._07); | |
if (iLevelIndex == 8) processXML(LVL._08); | |
if (iLevelIndex == 9) processXML(LVL._09); | |
if (iLevelIndex == 10) processXML(LVL._10); | |
if (iLevelIndex == 11) processXML(LVL._11); | |
if (iLevelIndex == 12) processXML(LVL._12); | |
if (iLevelIndex == 13) processXML(LVL._13); | |
if (iLevelIndex == 14) processXML(LVL._14); | |
if (iLevelIndex == 15) processXML(LVL._15); | |
if (iLevelIndex == 16) processXML(LVL._16); | |
if (iLevelIndex == 17) processXML(LVL._17); | |
if (iLevelIndex == 18) processXML(LVL._18); | |
if (iLevelIndex == 19) processXML(LVL._19); | |
if (iLevelIndex == 20) processXML(LVL._20); | |
if (iLevelIndex == 21) processXML(LVL._21); | |
if (iLevelIndex == 22) processXML(LVL._22); | |
if (iLevelIndex == 23) processXML(LVL._23); | |
if (iLevelIndex == 24) processXML(LVL._24); | |
if (iLevelIndex == 25) processXML(LVL._25); | |
if (iLevelIndex == 26) processXML(LVL._26); | |
if (iLevelIndex == 27) processXML(LVL._27); | |
if (iLevelIndex == 28) processXML(LVL._28); | |
if (iLevelIndex == 29) processXML(LVL._29); | |
if (iLevelIndex == 30) processXML(LVL._30); | |
NextEnemyTime = LevelEnemies.@time[0]; | |
enemyIndex = 0; | |
Timing = -4; | |
} | |
/** | |
* EDITOR_UPDATE - Runs when handling levels in the game editor | |
*/ | |
private function editor_update():void | |
{ | |
if (Input.check(Key.ESCAPE)) | |
{ | |
FP.world = new edUI(LevelData); | |
} | |
} | |
/** | |
* GAME UPDATE - For use with main game | |
*/ | |
private function game_update():void | |
{ | |
if (roidLevel && Timing < roidLength) { | |
if (Timing > nextRoidTime) fetchRoid(); | |
} | |
if (roidLevel && Timing < roidLength) { | |
if (Timing > nextBGRoidTime) fetchBGRoid(); | |
} | |
//Check if level completed. | |
if (levelCompleted) | |
{ | |
gameworld.Player.canControl = false; | |
gameworld.Player.armedWeapon.enabled = false; | |
var fx:Sfx = new Sfx(SFX.WARP_OUT); | |
if (!GV.muteSound) fx.play(); | |
stopUpdater = true; | |
var bgs:Array = []; | |
world.getClass(bg, bgs) | |
for each (var b:bg in bgs) | |
{ | |
b.warp(b.cruiseSpeed, b.warpSpeed * 1.6, .6, .8, 2, b.cruiseSpeed, b.warpSpeed, .6, .6, 1, 0, 2.8); | |
} | |
var leave:Alarm = new Alarm(1.8, warpPlayerOut); | |
var win:Alarm = new Alarm(2, levelWin); | |
addTween(leave, true); | |
if (!clearLevel) { | |
addTween(win, true); | |
} else { | |
var isFAIL:Boolean = false; | |
for each (var o:objective in objectives) { | |
if (!o.isComplete) isFAIL = true; | |
} | |
if (isFAIL) { | |
var lose:Alarm = new Alarm(2, levelFail); | |
addTween(lose, true); | |
} else { | |
addTween(win, true); | |
} | |
} | |
} | |
//Check if player has died. | |
if (gameworld.PlayerDead == true) | |
{ | |
stopUpdater = true; | |
var end:Alarm; | |
if (!infiniteMode) end = new Alarm(2, levelFail); | |
if (infiniteMode) end = new Alarm(2, infiniEnd); | |
addTween(end, true); | |
} | |
} | |
public function warpPlayerOut():void | |
{ | |
gameworld.Player.warpOut(); | |
} | |
/** | |
* Check to see if next enemy is ready to be fetched | |
*/ | |
private function CheckForEnemies():void | |
{ | |
var difference:Number = NextEnemyTime - Timing; | |
if (NextEnemyTime - Timing < .30 && enemyIndex < EnemyAmount) FetchEnemy(); | |
} | |
/** | |
* Check to see if next message is ready to be fetched | |
*/ | |
private function CheckForMessages():void | |
{ | |
var difference:Number = nextMessageTime - Timing; | |
if (nextMessageTime - Timing < .30 && messageIndex < messageAmount) FetchMessage(); | |
var i:int = 0; | |
while (i < messageDestroyDelay.length) | |
{ | |
messageDestroyDelay[i] -= FP.elapsed; | |
if (messageDestroyDelay[i] <= 0 && messageDestroyDelay[i] > -100) { | |
DestroyMessage(i); | |
messageDestroyDelay[i] = -150; | |
} | |
if (messageDestroyDelay[i] < -151) | |
{ | |
messageDestroyDelay.shift(); | |
messageText.shift(); | |
} | |
i++; | |
} | |
} | |
private function viewConsole():void | |
{ | |
var enemysleft:String = String(EnemyAmount - enemyIndex); | |
var liveenemies:String = String(world.typeCount("baddie")); | |
var lvlcomp:String = "false"; | |
if (levelCompleted) lvlcomp = "true"; | |
FP.console.log("Enemies: " + liveenemies + "(alive)" + enemysleft + "(qued) levelcompleted = " + lvlcomp); | |
} | |
private function fetchBGRoid():void | |
{ | |
var randSize:int = Math.random() * 4; | |
if (randSize >= 3) randSize = 3; | |
if (randSize == 0) randSize = 1; | |
var newR:Roid = world.add(new Roid(true,randSize, -123, -123, roidSpeedMod*.75)) as Roid; | |
var randomTimer:Number = roidMinRate + Math.random() * (roidMaxRate*1.25); | |
nextBGRoidTime = Timing + randomTimer; | |
} | |
private function fetchRoid():void | |
{ | |
makeIndex ++; | |
var randSize:int = Math.random() * 4; | |
if (randSize >= 3) randSize = 3; | |
if (randSize == 0) randSize = 1; | |
var newR:Roid = world.add(new Roid(false,randSize, -123, -123, roidSpeedMod)) as Roid; | |
newR.index = makeIndex; | |
gameworld.enemies.push(newR); | |
var randomTimer:Number = roidMinRate + Math.random() * roidMaxRate; | |
nextRoidTime = Timing + randomTimer; | |
} | |
/** | |
* FETCH ENEMY Called when next enemy in que is ready to be invoked. | |
*/ | |
private function FetchEnemy():void | |
{ | |
var b:baddie; | |
var tmpElement:XML = LevelEnemies[enemyIndex]; | |
var tmpX:int = 0; | |
var tmpY:int = 0; | |
var gridArray:Array = null; | |
//Add X or Y Coordinates if they are defined. | |
if (tmpElement.path.@X != null) tmpX = tmpElement.path.@X | |
if (tmpElement.path.@Y != null) tmpY = tmpElement.path.@Y | |
//Add Grid Array if it is defined. | |
if (tmpElement.path.@grid != null) { | |
var readGrid:String = tmpElement.path.@grid; | |
gridArray = readGrid.split(","); | |
} | |
//Add the baddie with XML and conditional variables. | |
b = world.create(baddie) as baddie; | |
var makeType:int = int(tmpElement.@type) | |
if (makeType > 11) makeType = 1; | |
makeIndex ++; | |
b.create(int(tmpElement.path.@pattern), makeType, tmpX, tmpY, int(tmpElement.path.@speed), gridArray, editmode, int(tmpElement.@ID), makeIndex); | |
gameworld.enemies.push(b); | |
//trace (gameworld.enemies.length); | |
if (enemyIndex < EnemyAmount) | |
{ | |
var tmpNextEnemy:XML = LevelEnemies[enemyIndex + 1]; | |
if (tmpNextEnemy != null) NextEnemyTime = Number(tmpNextEnemy.@time) | |
} | |
enemyIndex++; | |
if (NextEnemyTime - Timing < .30 && enemyIndex <EnemyAmount) FetchEnemy(); | |
} | |
/** | |
* Fetch Message | |
*/ | |
private function FetchMessage():void | |
{ | |
Text.size = 20; | |
var currentMessage:XML = LevelMessages[messageIndex]; | |
messageText[messageIndex] = new Text(currentMessage.@text); | |
messageText[messageIndex].alpha = 0; | |
FP.world.addGraphic(messageText[messageIndex], 2); | |
messageDestroyDelay[messageIndex] = int(currentMessage.@delay); | |
tweenSetting = ""; | |
tweenSetting += currentMessage.@from | |
if (messageDestroyDelay[messageIndex] < 1) messageDestroyDelay[messageIndex] = 3; | |
setTween(tweenSetting,"entry",messageIndex); | |
addTween(movetextTween[messageIndex], true); | |
addTween(alphatextTween[messageIndex], true); | |
if (messageIndex < messageAmount) | |
{ | |
var tmpNextMessage:XML = LevelMessages[messageIndex + 1]; | |
if (tmpNextMessage != null) nextMessageTime = Number(tmpNextMessage.@time) | |
} | |
messageIndex ++; | |
} | |
/** | |
* | |
* @param tweenType "top" - "left" - "right" - "bottom" | |
* @param passage "entry" - "exit" | |
*/ | |
private function setTween(tweenType:String,passage:String,index:int):void | |
{ | |
if (passage == "entry") | |
{ | |
alphatextTween[index] = new VarTween(); | |
movetextTween[index] = new VarTween(); | |
alphatextTween[index].tween(messageText[index], "alpha", 1, 1.0, Ease.bounceOut); | |
} | |
if (passage == "exit") | |
{ | |
removealphaTextTween[index] = new VarTween(); | |
removeTextTween[index] = new VarTween(); | |
removealphaTextTween[index].tween(messageText[index], "alpha", 0, 0.5, Ease.bounceIn); | |
} | |
if (tweenType == "right") | |
{ | |
if (passage == "entry") { | |
messageText[index].y = FP.screen.height / 2+20; | |
messageText[index].x = FP.screen.width + messageText[index].width; | |
movetextTween[index].tween(messageText[index], "x", FP.screen.width / 2 - messageText[index].width / 2, 0.5, Ease.quadOut); | |
} | |
if (passage == "exit") { | |
removeTextTween[index].tween(messageText[index], "x", 0 - messageText[index].width, 0.5, Ease.quadIn); | |
} | |
return; | |
} | |
if (tweenType == "left") | |
{ | |
if (passage == "entry") { | |
messageText[index].y = FP.screen.height / 2-20; | |
messageText[index].x = 0 - messageText[index].width; | |
movetextTween[index].tween(messageText[index], "x", FP.screen.width/2 - messageText[index].width/2, 0.5, Ease.quadOut); | |
} | |
if (passage == "exit") { | |
removeTextTween[index].tween(messageText[index], "x", FP.screen.width + messageText[index].width, 0.5, Ease.quadIn); | |
} | |
return; | |
} | |
if (tweenType == "top") | |
{ | |
if (passage == "entry") { | |
messageText[index].y = 0-messageText[index].height; | |
messageText[index].x = FP.screen.width/2 - messageText[index].width/2 | |
movetextTween[index].tween(messageText[index], "y", FP.screen.height / 2-20, 0.5, Ease.quadOut); | |
} | |
if (passage == "exit") { | |
removeTextTween[index].tween(messageText[index], "y", 0 - messageText[index].height, 0.5, Ease.quadIn); | |
} | |
return; | |
} | |
//tweenType is either "bottom" or not set. | |
if (passage == "entry") { | |
messageText[index].y = FP.screen.height+messageText[index].height; | |
messageText[index].x = FP.screen.width/2 - messageText[index].width/2 | |
movetextTween[index].tween(messageText[index], "y", FP.screen.height / 2, 0.5, Ease.quadOut); | |
} | |
if (passage == "exit") { | |
removeTextTween[index].tween(messageText[index], "y", 0 - messageText[index].height+20, 0.5, Ease.quadIn); | |
} | |
return; | |
} | |
private function DestroyMessage(index:int):void | |
{ | |
setTween(tweenSetting,"exit",index); | |
addTween(removealphaTextTween[index], true); | |
addTween(removeTextTween[index], true); | |
} | |
private function get levelCompleted():Boolean | |
{ | |
if (infiniteMode) return false; | |
if (roidLevel && Timing < roidLength) return false; | |
if (resourceLevel && !resourcesCollected) return false; | |
if (enemyIndex < EnemyAmount && !resourceLevel && !roidLevel) return false; | |
if (gameworld.PlayerDead) return false; | |
if (world.typeCount("baddie") > 0) return false; | |
if (world.typeCount("collectable") > 0) return false; | |
if (world.typeCount("doodad") > 0) return false; | |
if (world.typeCount("ebullet") > 0) return false; | |
return true; | |
} | |
/* | |
* LEVEL COMPLETE | |
* Displays the level finish dialog box | |
*/ | |
private function levelWin():void | |
{ | |
var randWin:String; | |
var randwin:int = Math.random() * 4; | |
if (randwin == 0) randWin = "Success"; | |
if (randwin == 1) randWin = "Awesome"; | |
if (randwin == 2) randWin = "Way cool"; | |
if (randwin >= 3) randWin = "Good job"; | |
gameworld.isComplete = true; | |
world.add(new interMenu(randWin)); | |
//killpercentage = gameworld.Enemykilled / (EnemyAmount-powerupcount) * 100; | |
//var percmsg:String = "Cash Collected:/t$" + String(gameworld.Cash ) + "/nEnemies Killed:/t" + String(killpercentage) + "%"; | |
//percmsg += "/n/nPress ENTER or click OK/nto continue..."; | |
//world.add(new msgbox("LEVEL COMPLETE!","Congrats Captain!/nScore: "+(String(gameworld.scoreIndicator.RealScore))+"/n"+percmsg , "center", 120, 100, false, EndGameplay)); | |
} | |
/* | |
* LEVEL FAILURE | |
* Display the level failure dialog. | |
*/ | |
private function levelFail():void | |
{ | |
var randLose:String; | |
var randlose:int = Math.random() * 4; | |
if (randlose == 0) randLose = "so close"; | |
if (randlose == 1) randLose = "bummer"; | |
if (randlose == 2) randLose = "nice try"; | |
if (randlose >= 3) randLose = "Failure"; | |
gameworld.isComplete = false; | |
world.add(new interMenu(randLose)); | |
//killpercentage = gameworld.Enemykilled / (EnemyAmount-powerupcount) * 100; | |
//var Failmsg:String = "Cash Collected:/t$" + String(gameworld.Cash) + "/nEnemies Killed:/t" + String(killpercentage) + "%"; | |
//Failmsg += "/n/nPress ENTER or click OK/nto continue..."; | |
//world.add(new msgbox("LEVEL FAILURE!", Failmsg, "center", 120, 80, false, EndGameplay)); | |
} | |
private function infiniEnd():void | |
{ | |
gameworld.isComplete = true; | |
world.add(new interMenu("the end", true)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment