Created
May 20, 2011 18:35
-
-
Save MattMcFarland/983504 to your computer and use it in GitHub Desktop.
upgrade menu
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.Upgrade | |
{ | |
import adobe.utils.CustomActions; | |
import campaign.btnTab; | |
import net.flashpunk.graphics.Image; | |
import net.flashpunk.graphics.Spritemap; | |
import net.flashpunk.graphics.Text; | |
import net.flashpunk.tweens.misc.VarTween; | |
import net.flashpunk.World; | |
import net.flashpunk.Entity; | |
import net.flashpunk.utils.Input; | |
import net.flashpunk.FP; | |
import net.flashpunk.tweens.misc.ColorTween; | |
import campaign.Galaxy.galaxymap; | |
import base.glowText; | |
import base.systemBtn; | |
import base.dynamicBtn; | |
/** | |
* ... | |
* @author Matt McFarland | |
*/ | |
public class upgradeMenu extends World | |
{ | |
//Graphics & Indicators: | |
protected var bg:Image; | |
protected var xp_bar:Image; | |
public static var CurrentWeapon:wepIndicator; | |
public static var damage:Text; | |
public static var multi:Text; | |
public static var special:Text; | |
public static var costIndicator:glowText; | |
public static var description:infoPanel; | |
public static var damageUpgrade:wepUpg; | |
public static var multiUpgrade:wepUpg; | |
public static var specialUpgrade:wepUpg; | |
public static var boomSet:upgIndicator; | |
public static var magnetSet:upgIndicator; | |
public static var shieldSet:upgIndicator; | |
//Additional Buttons: | |
public static var mapButton:btnTab; | |
public static var resetButton:upgButton; | |
protected var resetText:Text; | |
public static var boomEnemySwitch:upgSwitch; | |
public static var boomBulletSwitch:upgSwitch; | |
public static var magnetPullSwitch:upgSwitch; | |
public static var magnetRepelSwitch:upgSwitch; | |
public static var shieldShootSwitch:upgSwitch; | |
public static var shieldMoveSwitch:upgSwitch; | |
public static var shieldAbsorb:Array = []; | |
public static var shieldAmount:Array = []; | |
public static var magnetStrength:Array = []; | |
public static var magnetRadius:Array = []; | |
public static var boomAmmo:Array = []; | |
public static var boomCoolDown:Array = []; | |
//Logic: | |
public static var skillPoints:int; | |
public static var usedPoints:int; | |
public static var lvl:int; | |
//Tweeners: | |
public var playerSkin:Entity; | |
public var sprPlayer:Spritemap = new Spritemap(GFX.iGAME_PLAYER, 32, 32); | |
public var skinIndex:int = 0; | |
public function upgradeMenu(level:int) | |
{ | |
lvl = level; | |
galaxymap.previousLevel = GV.player_level; | |
} | |
/** | |
* Runs when the game starts. | |
*/ | |
override public function begin():void | |
{ | |
usedPoints = 0; | |
skillPoints = 0; | |
var bbg:Image = new Image(GFX.iUI_MAPMENU); | |
addGraphic(bbg, 9); | |
bbg.blend = "normal"; | |
bg = new Image(GFX.iUI_UPGRADEMENU); | |
bg.blend = "normal"; | |
addGraphic(bg, 7); | |
CreateXPbar(); | |
CreateXPtext(); | |
createMapButton(); | |
createResetButton(); | |
//createCheatButton(); | |
CreateWeaponSelector(); | |
CreateWeaponUpgrades(); | |
CreateMagnetUpgrades(); | |
CreateShieldUpgrades(); | |
CreateBoomUpgrades(); | |
description = new infoPanel(); | |
add (description); | |
CreateCostIndicator(); | |
upgradeMenu.costIndicator.txt = "Upgrade Points: " +String(upgradeMenu.skillPoints - upgradeMenu.usedPoints); | |
if (GV.player_level < 7) CreateOverlays(); | |
if (GV.player_level == 81) CreateOverlays(); | |
//addGraphic(new Image(GFX.SPONSOR_LOGO), -1, 525, 367); | |
addSkinSelector(); | |
} | |
private function addSkinSelector():void | |
{ | |
addGraphic(new Image(GFX.SKIN_SELECTOR), 1, 479, 357); | |
var l:dynamicBtn = new dynamicBtn(99, 506, 374, new Image(GFX.BLUE_LEFT), prevSkin); | |
var r:dynamicBtn = new dynamicBtn(99, 581, 374, new Image(GFX.BLUE_RIGHT), nextSkin); | |
add (l); | |
add(r); | |
l.layer = 0; | |
r.layer = 0; | |
showPlayerSkin(); | |
} | |
public function showPlayerSkin():void | |
{ | |
sprPlayer = new Spritemap(GFX.iGAME_PLAYER, 32, 32); | |
if (GV.playerSkin == "Pod") { | |
sprPlayer = new Spritemap(GFX.PLAYER_POD, 32, 32); | |
skinIndex = 1; | |
} | |
if (GV.playerSkin == "Shuttle") { | |
sprPlayer = new Spritemap(GFX.PLAYER_SHUTTLE, 32, 32); | |
skinIndex = 2; | |
} | |
if (GV.playerSkin == "Splitter") { | |
sprPlayer = new Spritemap(GFX.PLAYER_SPLITTER, 32, 32); | |
skinIndex = 3; | |
} | |
if (GV.playerSkin == "Streaker") { | |
sprPlayer = new Spritemap(GFX.PLAYER_STREAKER, 32, 32); | |
skinIndex = 4; | |
} | |
sprPlayer.add("play", [7,6,5,4,3,2,1,0,8,9,10,11,12,13,14,15,16], 5); | |
sprPlayer.play("play"); | |
if (!playerSkin) { | |
playerSkin = new Entity(536, 401, sprPlayer); | |
playerSkin.layer = 0; | |
add(playerSkin); | |
} else { | |
playerSkin.graphic = sprPlayer; | |
} | |
} | |
public function prevSkin():void | |
{ | |
skinIndex --; | |
if (skinIndex < 0) skinIndex = 4; | |
updateSkin(); | |
} | |
public function nextSkin():void | |
{ | |
skinIndex ++; | |
if (skinIndex > 4) skinIndex = 0; | |
updateSkin(); | |
} | |
public function updateSkin():void | |
{ | |
if (skinIndex == 0) GV.playerSkin = ""; | |
if (skinIndex == 1) GV.playerSkin = "Pod"; | |
if (skinIndex == 2) GV.playerSkin = "Shuttle"; | |
if (skinIndex == 3) GV.playerSkin = "Splitter"; | |
if (skinIndex == 4) GV.playerSkin = "Streaker"; | |
showPlayerSkin(); | |
} | |
private function CreateOverlays():void | |
{ | |
add (new Overlay("Current Weapon", 12, 136, 146, 104)); | |
add (new Overlay("Upgrade Weapon",159, 136, 466, 102)); | |
add (new Overlay("Magnet",11, 252, 193, 103,24,24)); | |
add (new Overlay("Shield",223, 253, 192, 102,24,24)); | |
add (new Overlay("Nuke", 434, 253, 192, 102,24,24)); | |
if (GV.weaponType!="blaster") add (new Overlay("Equip!", 10, 137, 42, 32, 15)); | |
if (GV.weaponType!="lightningGun") add (new Overlay("Equip!", 10, 173, 42, 32, 15)); | |
if (GV.weaponType!="rocketLauncher") add (new Overlay("Equip!", 10, 207, 42, 32, 15)); | |
add (new Overlay("Swap!", 25, 259, 50, 45, 15)); | |
add (new Overlay("Swap!", 143, 259, 50, 45, 15)); | |
add (new Overlay("Swap!", 235, 259, 50, 45, 15)); | |
add (new Overlay("Swap!", 355, 259, 50, 45, 15)); | |
add (new Overlay("Swap!", 446, 259, 50, 45, 15)); | |
add (new Overlay("Swap!", 565, 259, 50, 45, 15)); | |
add (new Overlay("Change Ship", 503, 367, 100, 100, 15, -24)); | |
var toMap:Text = new Text("<- To"+String.fromCharCode(10) +"Map"); | |
toMap.wordWrap; | |
toMap.align = "right"; | |
toMap.size = 18; | |
add (new Entity(565, 4, toMap)); | |
} | |
override public function update():void | |
{ | |
if (GV.SystemWindowActive) { | |
var systemBtns:Array = []; | |
getType("systemBtn", systemBtns); | |
for each (var o:systemBtn in systemBtns) | |
{ | |
o.update(); | |
} | |
return; | |
} | |
super.update(); | |
} | |
/** | |
* Create an XP Bar. | |
*/ | |
protected function CreateXPbar():void | |
{ | |
xp_bar = new Image(GFX.iUI_XP_BAR); | |
//placeholder nextlevel int | |
var nextLevel:int = GV.LevelTable[GV.player_level + 1]; | |
var percentage:Number = GV.XP / nextLevel; | |
xp_bar.scaleX = 0; | |
addGraphic(xp_bar, 1, 14, 14); | |
var xpTween:VarTween = new VarTween(); | |
xpTween.tween(xp_bar, "scaleX", percentage, .5); | |
addTween(xpTween, true); | |
Text.size = 18; | |
var level:Text = new Text("level: " + String(GV.player_level)) | |
level.color = 0x000000; | |
//level.alpha = .4; | |
addGraphic(level, 0, 17, 15); | |
} | |
/** | |
* Create the current and next level XP texts | |
*/ | |
protected function CreateXPtext():void | |
{ | |
//placeholder nextlevel int | |
var nextLevel:int = GV.LevelTable[GV.player_level + 1]; | |
Text.size = 18; | |
var currXP:Text = new Text("Current: " + GV.XP + " XP"); | |
var nextXP:Text = new Text("Next Level: " + nextLevel + " XP"); | |
nextXP.width = 574; | |
currXP.color = 0x52a2f7, nextXP.color = 0x52a2f7; | |
currXP.align = "left"; | |
nextXP.align = "right"; | |
var showCurrXP:Entity = new Entity(10, 38, currXP); | |
var showNextXP:Entity = new Entity(10, 38, nextXP); | |
showCurrXP.layer = 1; | |
showNextXP.layer = 1; | |
add (showCurrXP); | |
add (showNextXP); | |
} | |
/** | |
* Create Reset Button that resets the skill points | |
*/ | |
protected function createResetButton():void | |
{ | |
Text.size = 24; | |
resetText = new Text("Reset"); | |
resetText.color = 0x52a2f7; | |
resetButton = new upgButton(1, 13, 90, resetText,resetSkills); | |
resetButton.infoTitle = "Reset Skill Points"; | |
resetButton.infoText = "A clean slate! Reset your skill points to try various weapon & defense strategies"; | |
add (resetButton); | |
} | |
protected function createCheatButton():void | |
{ | |
Text.size = 24; | |
resetText = new Text("Cheat"); | |
resetText.color = 0x52a2f7; | |
resetButton = new upgButton(1, 120, 65, resetText,cheatSkills); | |
resetButton.infoTitle = "Attn Sponsor"; | |
resetButton.infoText = "Not available for the released version. Cheat makes you level 81 so you can test drive everything! "; | |
add (resetButton); | |
} | |
protected function resetSkills():void | |
{ | |
GV.multiLevel = 1; | |
GV.damageLevel = 1; | |
GV.specialLevel = 1; | |
GV.shieldAbsorb = 1; | |
GV.shieldAmount = 1; | |
GV.boomAmmo = 1; | |
GV.boomCoolDown = 1; | |
GV.magnetStrength = 1; | |
GV.magnetRadius = 1; | |
FP.world = new upgradeMenu(lvl); | |
} | |
protected function cheatSkills():void | |
{ | |
GV.player_level = 81; | |
GV.XP = 10000000000; | |
GV.multiLevel = 1; | |
GV.damageLevel = 1; | |
GV.specialLevel = 1; | |
GV.shieldAbsorb = 1; | |
GV.shieldAmount = 1; | |
GV.boomAmmo = 1; | |
GV.boomCoolDown = 1; | |
GV.magnetStrength = 1; | |
GV.magnetRadius = 1; | |
galaxymap.cheating = true; | |
FP.world = new upgradeMenu(lvl); | |
} | |
/** | |
* Create the upper right "return to map" button | |
*/ | |
protected function createMapButton():void | |
{ | |
mapButton = new btnTab("map"); | |
add (mapButton); | |
} | |
/** | |
* Create the Weapon Selector buttons and set the weapon | |
*/ | |
protected function CreateWeaponSelector():void | |
{ | |
//Create Weapon Buttons | |
Text.size = 18; | |
damage = new Text("Damage",509, 145); | |
multi = new Text("Number", 529, 175); | |
special = new Text("Special", 509, 205); | |
damage.color = 0x7cb7f7; | |
multi.color = 0x52a2f7; | |
special.color = 0x7cb7f7; | |
addGraphic(damage); | |
addGraphic(multi); | |
addGraphic(special); | |
add (new wepBtn(2, 17, 139, "blaster")); | |
add (new wepBtn(3, 17, 174, "lightningGun")); | |
add (new wepBtn(4, 17, 209, "rocketLauncher")); | |
CurrentWeapon = new wepIndicator(57, 139,GV.weaponType); | |
Weapon = GV.weaponType; | |
add (CurrentWeapon); | |
} | |
/** | |
* Create the Weapon Upgrade Arrays | |
*/ | |
protected function CreateWeaponUpgrades():void | |
{ | |
damageUpgrade = new wepUpg(176, 149, "damage"); | |
multiUpgrade = new wepUpg(196, 179, "multi"); | |
specialUpgrade = new wepUpg(176, 210, "special"); | |
add(damageUpgrade); | |
add(multiUpgrade); | |
add(specialUpgrade); | |
} | |
/** | |
* Create the Cost Indicator | |
*/ | |
protected function CreateCostIndicator():void | |
{ | |
skillPoints = GV.player_level * 75; | |
Text.size = 24; | |
var ci:Text = new Text("Upgrade Points: "+String(skillPoints-usedPoints),10,92); | |
ci.width = 620; | |
ci.color = 0x52a2f7; | |
ci.align = "right"; | |
costIndicator = new glowText(ci); | |
add(costIndicator); | |
} | |
/** | |
* Create the Magnet indicater/upgrades | |
*/ | |
protected function CreateMagnetUpgrades():void | |
{ | |
magnetSet = new upgIndicator(73, 261, "magnet"); | |
magnetPullSwitch = new upgSwitch(22, 257, "attract"); | |
magnetRepelSwitch = new upgSwitch(141, 257, "repel"); | |
add(magnetPullSwitch); | |
add(magnetRepelSwitch); | |
add(magnetSet); | |
addGraphic(new Image(GFX.iUI_OVERICONS), 4, 12, 253); | |
magnetStrength = CreateBubbleArray("magnetStrength", 24, 305); | |
magnetRadius = CreateBubbleArray("magnetRadius", 174, 305); | |
} | |
/** | |
* Create the Shield Indicator and Upgrades | |
*/ | |
protected function CreateShieldUpgrades():void | |
{ | |
shieldSet = new upgIndicator(289, 260, "shield"); | |
shieldShootSwitch = new upgSwitch(354, 257, "shoot"); | |
shieldMoveSwitch = new upgSwitch(234, 257, "move"); | |
add(shieldMoveSwitch); | |
add(shieldShootSwitch); | |
add(shieldSet); | |
addGraphic(new Image(GFX.iUI_OVERICONS), 4, 223, 253); | |
shieldAbsorb = CreateBubbleArray("shieldAbsorb", 235, 305); | |
shieldAmount = CreateBubbleArray("shieldAmount", 385, 305); | |
} | |
/** | |
* Create the Bomb Indicator and Upgrades | |
*/ | |
protected function CreateBoomUpgrades():void | |
{ | |
boomSet = new upgIndicator(500, 260, "boom"); | |
boomBulletSwitch = new upgSwitch(567, 257, "bullets"); | |
boomEnemySwitch = new upgSwitch(446, 257, "enemies"); | |
add(boomBulletSwitch); | |
add(boomEnemySwitch); | |
add(boomSet); | |
addGraphic(new Image(GFX.iUI_OVERICONS), 4, 434, 253); | |
boomAmmo = CreateBubbleArray("boomAmmo", 446, 305); | |
boomCoolDown = CreateBubbleArray("boomCoolDown",596, 305); | |
} | |
/** | |
* Creates a utility upgrade array of bubbles | |
* @param type upgrade type | |
* @param x Coordinate | |
* @param y Coordinate | |
* @return returns new array of bubbles | |
*/ | |
protected function CreateBubbleArray(type:String, x:Number, y:Number):Array | |
{ | |
var firstX:Number = x; | |
var makeX:Number = x; | |
var makeY:Number = y; | |
var bubbles:Array = new Array(); | |
var levelOwned:int; | |
var show:Boolean = true; | |
var space:int; | |
var i:int = 1; | |
if (type == "shieldAbsorb") { | |
space = 20; | |
levelOwned = GV.shieldAbsorb; | |
} | |
if (type == "shieldAmount") { | |
space = -20; | |
levelOwned = GV.shieldAmount; | |
} | |
if (type == "boomAmmo") { | |
space = 20; | |
levelOwned = GV.boomAmmo; | |
} | |
if (type == "boomCoolDown") { | |
space = -20; | |
levelOwned = GV.boomCoolDown; | |
} | |
if (type == "magnetStrength") { | |
space = 20; | |
levelOwned = GV.magnetStrength; | |
} | |
if (type == "magnetRadius") { | |
space = -20; | |
levelOwned = GV.magnetRadius; | |
} | |
while (i < 11) | |
{ | |
if (levelOwned < i) show = false; | |
var cost:int = i * 15 -15; | |
if (i == 1 || | |
i == 2 || | |
i == 4 || | |
i == 7) makeX = firstX; | |
if (i == 3 || | |
i == 5 || | |
i == 8) makeX = firstX + space; | |
if (i == 6 || | |
i == 9) makeX = firstX + space*2; | |
if (i == 10) makeX = firstX + space*3; | |
if (i == 1) bubbles[i] = new upgBubble(makeX, makeY, show, cost, type, i); | |
if (i > 1 && i < 4) bubbles[i] = new upgBubble(makeX, makeY + 10, show, cost, type, i); | |
if (i > 3 && i < 7) bubbles[i] = new upgBubble(makeX, makeY + 20, show, cost, type, i); | |
if (i > 6 && i < 11) bubbles[i] = new upgBubble(makeX, makeY + 30, show, cost, type, i); | |
add(bubbles[i]); | |
i++ | |
} | |
return bubbles; | |
} | |
/** | |
* Set Weapon to "rocketLauncher" - "lightningGun" - "blaster" | |
*/ | |
public static function set Weapon(arg:String):void | |
{ | |
//Draconian Error Handling, force string to be correct! | |
if (arg != "rocketLauncher" && | |
arg != "lightningGun" && | |
arg != "blaster") { | |
throw new Error("Illegal weapon!"); | |
} | |
switch (arg) | |
{ | |
case "rocketLauncher": | |
CurrentWeapon.switchTo(new Image(GFX.iWEP_ROCKET)); | |
multi.text = "Reload"; | |
special.text = "Radius"; | |
GV.weaponType = arg; | |
break; | |
case "lightningGun": | |
CurrentWeapon.switchTo(new Image(GFX.iWEP_LIGHTNING)); | |
multi.text = "Chains"; | |
special.text = "Stun %"; | |
GV.weaponType = arg; | |
break; | |
case "blaster": | |
CurrentWeapon.switchTo(new Image(GFX.iWEP_BULLETS)); | |
multi.text = "Spread"; | |
special.text = "Piercing %"; | |
GV.weaponType = arg; | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment