package { import flash.display.MovieClip; import flash.geom.Point; import Globals; public class Asteroid extends MovieClip { private var id:int; private var health:int; private var dying:Boolean = false;//prevents multiple destroy() calls private var sector:Sector; public function Asteroid($id:int, $coords:Point, $rotation:int, $type:int, $sector:Sector) { id = $id; x = $coords.x * 32; y = $coords.y * 32; rotation = $rotation; gotoAndStop($type); sector = $sector; health = 300; } public function hit($damage:Number):void { health -= $damage; if (health <= 0 && !dying) destroy(); } private function spawnSmoke($ammount:int):void { for (var i:int = 0; i < $ammount; i++) { var temp:Engine_smoke; temp = new Engine_smoke( Globals.random(-2, 2), Globals.random(-2, 2) ); temp.x = x; temp.y = y; temp.scaleX = 3; temp.scaleY = 3; sector.addChild(temp); } } public function destroy():void { if (!dying) { dying = true; //Remove minimap blipp sector.getMain.getGUI.removeAsteroidBlipp(ID); //Explosion var boom:AsteroidExplosion = new AsteroidExplosion(); boom.x = x; boom.y = y; boom.rotation = Globals.random(0, 360); parent.addChildAt(boom, 2); spawnSmoke(20); //Remove this and its references sector.removeAsteroid(id); parent.removeChild(this); } } //--------------------------------------------set/get-------------------------------------------- public function get ID():int { return id; } } }