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 ammoText:TextField; private var cheatBar:TextField; private var statsFormat:TextFormat; private var hpIcon:Icon_shield; private var ammoIcon:Icon_bolt; 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) { updateHP(); updateAmmo(); updateStatsbox(); } private function createMinimap() { 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() { //hpText hpText = new TextField(); hpText.selectable = false; hpText.autoSize = TextFieldAutoSize.RIGHT; hpText.x = main.StageWidth - 12; hpText.y = main.StageHeight - 78; hpText.defaultTextFormat = statsFormat; addChild(hpText); //ammoText ammoText = new TextField(); ammoText.selectable = false; ammoText.autoSize = TextFieldAutoSize.RIGHT; ammoText.x = main.StageWidth - 12; ammoText.y = main.StageHeight - 50; ammoText.defaultTextFormat = statsFormat; ammoText.text = "0"; addChild(ammoText); //hpIcon hpIcon = new Icon_shield(); hpIcon.y = hpText.y + 16; addChildAt(hpIcon, 1); //ammoIcon ammoIcon = new Icon_bolt(); ammoIcon.y = ammoText.y + 16; addChildAt(ammoIcon, 1); //statsbox statsBox = new Statsbox(); statsBox.x = main.StageWidth + statsBox.width; statsBox.y = main.StageHeight - 12; addChildAt(statsBox, 0); } private function createCheatBar() { 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) { if ($e.keyCode == 13)//enter key pressed { stage.focus = null; cheats(cheatBar.text); } } private function cheats($cheat:String) { 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"); } } private function updateHP() { //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 updateAmmo() { ////////////////red ammo on low yoyo ammoIcon.x = ammoText.x - 4; } private function updateStatsbox() { 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) { minimap.removeAsteroidBlipp($id); } //--------------------------------------------set/get-------------------------------------------- } }