package { import flash.display.Graphics; import flash.display.MovieClip; import flash.display.Sprite; import flash.events.Event; import flash.geom.Point; import flash.geom.Rectangle; public class Sector extends MovieClip { private var main:Main; private var playerShip:PlayerShip; private var sectorW:Number; private var sectorH:Number; private var map:Array = new Array(); private var AIShips:Array = new Array(); private var asteroids:Array = new Array(); private var currentMap:int = 2; public function Sector($main:Main, $keyboard:KeyboardEvents) { //variable declarations main = $main; //property stuff sectorW = main.getDBMaps.mapWidth(currentMap); sectorH = main.getDBMaps.mapHeight(currentMap); //spawn misc stuff addAsteroids(); addBorders(); //player stuff playerShip = new PlayerShip( $keyboard.getKeyPress(),//key presses main.getDBMaps.PlayerStart(currentMap).coords,//coords main.getDBMaps.PlayerStart(currentMap).rotation,//starting rotation this,//sector main.getDBShipsData.getShipData(2), 0,//allegience main.getDBWeapons.getWeaponData(1),//main weapon main.getDBWeapons.getWeaponData(3)//secondary weapon ); playerShip.MaxHP *= 2; playerShip.HP = playerShip.MaxHP; addChildAt(playerShip, 1); addAIShips(); addEventListener(Event.ENTER_FRAME, moveCamToPlayer); } private function addAIShips():void { var count:int = 0; for (var i:int; i < main.getDBMaps.noOfAIShips(currentMap); i++ ) { var tempProp:Object = main.getDBMaps.getAIShip(currentMap, i); var temp:AIShip = new AIShip( i, //id tempProp.coords, tempProp.rotation, tempProp.allegiance, this, main.getDBShipsData.getShipData(tempProp.type), main.getDBWeapons //weapon DB ); AIShips.push(temp); addChildAt(temp, 1); } } public function addSingleAIShip($coords:Point, $rot:int, $type, $allegiance:int) { var temp:AIShip = new AIShip( AIShips.length, $coords, $rot, $allegiance, this, main.getDBShipsData.getShipData($type), //ship properties main.getDBWeapons //weapon DB ); AIShips.push(temp); addChildAt(temp, 1); } private function addBorders() { var borderTop:Border = new Border(); borderTop.width = (sectorW * 32) + 8; borderTop.x = (sectorW * 32) / 2; addChildAt(borderTop, 0); var borderBottom:Border = new Border(); borderBottom.width = (sectorW * 32) + 8; borderBottom.x = (sectorW * 32) / 2; borderBottom.y = sectorH * 32; addChildAt(borderBottom, 0); var borderLeft:Border = new Border(); borderLeft.height = sectorH * 32; borderLeft.y = (sectorH * 32) / 2; addChildAt(borderLeft, 0); var borderRight:Border = new Border(); borderRight.height = sectorH * 32; borderRight.x = sectorW * 32; borderRight.y = (sectorH * 32) / 2; addChildAt(borderRight, 0); } ///Loads and adds asteroids from propertyMap to the game private function addAsteroids() { for (var i:int; i < main.getDBMaps.noOfAsteroids(currentMap); i++) { var tempProp:Object = main.getDBMaps.getAsteroid(currentMap, i); var temp:Asteroid = new Asteroid( i,//ID tempProp.coords,//coords tempProp.rotation,//rotation tempProp.type,//type this//sector ); addChild(temp); Asteroids.push(temp); } } public function get Asteroids():Array { return asteroids; } ///Removes the reference to the specific asteroid public function removeAsteroid($id:int) { asteroids[$id] = null; } public function moveCamToPlayer($e:Event):void { x = -playerShip.x; y = -playerShip.y; //0% speed = 1.0 zoom, 100% speed = 0.6 zoom var ratio:Number = 1 - ((playerShip.Speed / playerShip.SpeedMax) * .4); ratio = Math.round(ratio * 1000) / 1000; //main.RotationBoxZoom = Math.round(main.RotationBoxZoom * 1000) / 1000; main.RotationBoxZoom = .6; //30% zoom is the zoomed-out limit if (ratio <= .3) ratio = .3; if (ratio > main.RotationBoxZoom) main.RotationBoxZoom += .005; else if (ratio < main.RotationBoxZoom) main.RotationBoxZoom -= .005; } private function radToDeg($radiant):Number { return $radiant * Math.PI / 180; } //--------------------------------------------set/get-------------------------------------------- public function get SectorW():Number { return sectorW; } public function get SectorH():Number { return sectorH; } public function getShipPoints():Array { var temp:Array = new Array(); for (var i = 0; i < AIShips.length; i++) { temp.push(AIShips[i].Coords); } temp.push(playerShip.Coords); return temp; } public function getShips():Array { return AIShips.concat(playerShip); } public function removeAIShip($id:int):void { AIShips[$id] = null; } public function get Player_Ship():PlayerShip { return playerShip; } public function get AllegianceColors():Array { return main.AllegianceColors; } public function get getMain():Main { return main; } } }