package { import caurina.transitions.properties.TextShortcuts; import flash.display.MovieClip; import flash.events.Event; import flash.events.KeyboardEvent; import flash.geom.Point; import flash.text.*; import caurina.transitions.*; public class GUI extends MovieClip { private var main:Main; private var sector:Sector; private var minimap:Minimap; private var hpText:TextField; private var energyText:TextField; private var secAmmoText:TextField; private var cheatBar:TextField; private var statsFormat:TextFormat; private var hpIcon:Icon_shield; private var energyIcon:Icon_bolt; private var secAmmoIcon:Icon_missle; private var statsBox:Statsbox; public function GUI($main:Main) { statsFormat = new TextFormat(); statsFormat.color = 0xFFFFFF; statsFormat.font = "_sans"; statsFormat.size = 24; statsFormat.bold = true; main = $main; sector = main.GetSector; createMinimap(); createStatsBar(); createCheatBar(); addEventListener(Event.ENTER_FRAME, loop); } private function loop($e:Event):void { updateHP(); updateEnergy(); updateSecAmmo(); updateStatsbox(); } private function createMinimap():void { minimap = new Minimap(sector); var minimapRatio:Number = sector.SectorH / sector.SectorW; minimap.scaleY = minimapRatio; minimap.x = main.StageWidth - minimap.width - 12; minimap.y = 12; addChild(minimap); } private function createStatsBar():void { //statsbox statsBox = new Statsbox(); statsBox.x = main.StageWidth - 120; statsBox.y = main.StageHeight - statsBox.height - 12; addChildAt(statsBox, 0); //hpText hpText = new TextField(); hpText.selectable = false; hpText.autoSize = TextFieldAutoSize.RIGHT; hpText.x = 95; hpText.y = 4; hpText.defaultTextFormat = statsFormat; statsBox.addChild(hpText); //energyText energyText = new TextField(); energyText.selectable = false; energyText.autoSize = TextFieldAutoSize.RIGHT; energyText.x = 95; energyText.y = 30; energyText.defaultTextFormat = statsFormat; energyText.text = "0"; statsBox.addChild(energyText); //secAmmoText secAmmoText = new TextField(); secAmmoText.selectable = false; secAmmoText.autoSize = TextFieldAutoSize.RIGHT; secAmmoText.x = 95; secAmmoText.y = 56; secAmmoText.defaultTextFormat = statsFormat; secAmmoText.text = "0"; statsBox.addChild(secAmmoText); //hpIcon hpIcon = new Icon_shield(); hpIcon.y = hpText.y + 16; statsBox.addChildAt(hpIcon, 1); //energyIcon energyIcon = new Icon_bolt(); energyIcon.y = energyText.y + 16; statsBox.addChildAt(energyIcon, 1); //secAmmoIcon secAmmoIcon = new Icon_missle(); secAmmoIcon.y = secAmmoText.y + 16; statsBox.addChildAt(secAmmoIcon, 1); } private function createCheatBar():void { cheatBar = new TextField(); cheatBar.x = 12; cheatBar.y = main.StageHeight - 50; cheatBar.width = 300; cheatBar.height = 22; cheatBar.type = TextFieldType.INPUT; cheatBar.background = true; cheatBar.backgroundColor = 0xFFFFFF; cheatBar.visible = true; addChildAt(cheatBar, 1); cheatBar.addEventListener(KeyboardEvent.KEY_DOWN, cheatBarInput); } private function cheatBarInput($e:KeyboardEvent):void { if ($e.keyCode == 13)//enter key pressed { stage.focus = null; cheats(cheatBar.text); } } private function cheats($cheat:String):void { if ($cheat == "god")//god mode { trace("cheat: giving player lots of hp"); main.Player_Ship.MaxHP = 99999; main.Player_Ship.HP = 99999; } else if ($cheat == "spawn")//spawn ships { //generate random coors around the player var randCoors:Point = new Point( sector.Player_Ship.Coords.x + Math.round((Math.random() * 10) - 5), sector.Player_Ship.Coords.y + Math.round((Math.random() * 10) - 5) ); //randomize faction var tempAllegiance:int = Math.floor(Math.random() * 6); sector.addSingleAIShip( randCoors, sector.Player_Ship.rotation, 2, tempAllegiance ); trace("cheat: spawning an enemy of faction " + tempAllegiance); } else if($cheat == "rapid")//rapid missles { var stuff:Object = sector.Player_Ship.MainWep; stuff.rof = 1000; sector.Player_Ship.MainWep = stuff; var secStuff:Object = sector.Player_Ship.SecWep; secStuff.rof = 100; sector.Player_Ship.SecWep = secStuff; trace("cheat: rapid fire on"); } else if ($cheat == "ammo") { main.Player_Ship.SecAmmo = 999; } } private function updateHP():void { //red color if less than 30% hp if ((main.Player_Ship.HP / main.Player_Ship.MaxHP) <= .3) hpText.textColor = 0xFF0000; else hpText.textColor = 0xFFFFFF; if (parseInt(hpText.text) < 0) hpText.text = "0"; hpText.text = main.Player_Ship.HP.toString(); hpIcon.x = hpText.x - 4; } private function updateEnergy():void { //red color if less than 10% if ((main.Player_Ship.Energy / main.Player_Ship.EnergyMax) <= .1) energyText.textColor = 0xFF0000; else energyText.textColor = 0xFFFFFF; var energyValue:int = Math.floor(main.Player_Ship.Energy); if(energyValue < 0) energyText.text = "0"; else energyText.text = energyValue.toString(); energyIcon.x = energyText.x - 4; } private function updateSecAmmo():void { secAmmoText.text = main.Player_Ship.SecAmmo.toString(); secAmmoIcon.x = secAmmoText.x; } private function updateStatsbox():void { /* var temp:int; if (hpText.width > ammoText.width) temp = hpText.x; else temp = ammoText.x; statsBox.x = temp + 200; Tweener.addTween(statsBox, {x:(temp + 200), time:.5} ); */ } public function removeAsteroidBlipp($id:int):void { minimap.removeAsteroidBlipp($id); } //--------------------------------------------set/get-------------------------------------------- } }