package  {
	import flash.display.MovieClip
	import flash.events.MouseEvent;
	import flash.display.Sprite;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	
	public class MyGame extends MovieClip
	{
		public static const ENEMY_DISTANCE = 180;
		private var _player:Sprite;
		private var _enemies:Vector.<Enemy> = new Vector.<Enemy>;
		private var _enemyTimer:Timer;

		public function MyGame() 
		{
			_player = new Sprite();
			_player.x = stage.stageWidth/2;
			_player.y = stage.stageHeight/2;
			addChild(_player);
			drawPlayer();
			
			_enemyTimer = new Timer(1000);
			
			_enemyTimer.start();
			
			_enemyTimer.addEventListener(TimerEvent.TIMER, addEnemy);
			
			stage.addEventListener(MouseEvent.MOUSE_MOVE, rotatePlayer);
		}
		
		public function rotatePlayer(e:MouseEvent)
		{
			var angle:Number = Math.atan2(mouseY - _player.y, mouseX - _player.x);
			angle = angle * 180 / Math.PI;
			_player.rotation = angle;
		}
		
		public function drawPlayer()
		{
			_player.graphics.lineStyle(2,0x000000);		
			_player.graphics.moveTo(10,0);				
			_player.graphics.lineTo(-10,5);				
			_player.graphics.lineTo(-10,-5);
			_player.graphics.lineTo(10,0);	
		}

		
		public function addEnemy(e:TimerEvent)
		{
			
			var randAngle:Number = Math.random() * 2*Math.PI;
			
			var enemy:Enemy = new Enemy();
			
			enemy.x = ENEMY_DISTANCE * Math.cos(randAngle) + stage.stageWidth/2;
			enemy.y = ENEMY_DISTANCE * Math.sin(randAngle) + stage.stageHeight/2;
			
			_enemies.push(enemy);
			
			addChild(enemy);
			
		}

	}
	
}


