
class MainManager {

	private var cursor:Reticule;
	private var spaceShip:Ship;
	private var bullets:Array = new Array();
	private var enemies:Array = new Array();
	private var keyMgr:KeyManager;
	
	private var difficulty = 1;
	
	private var score = 0;
	
	public var hit = 0;
	
	public var width = 480;
	public var height = 640;
	
	private var enemyTimer = 30;
	
	public var removedEnemies = 0; //part of a jury-rigged way to prevent the bullets from "hitTest"ing every enemy that's been generated
	public var removedBullets = 0;
	
	function init() {
		_global.g = new Globals();
		_global.g.init();
		_global.g.mainMgr = this;
		
		this.cursor = new Reticule();
		this.cursor.init();
		
		this.spaceShip = new Ship();
		this.spaceShip.init();
		
		this.keyMgr = new KeyManager();
		this.keyMgr.init();
		
		_global.g.rootClip.mainStage.attachMovie("scoreBox", "scoreBox", 20000);
		_global.g.rootClip.mainStage.scoreBox._x = 85;
		_global.g.rootClip.mainStage.scoreBox._y = 25;
		//_global.g.rootClip.mainStage.scoreBox.score.html = true;
		_global.g.rootClip.mainStage.scoreBox.score.text = 0;
		
		_global.g.rootClip.mainStage.mainMgr = this;
		_global.g.rootClip.mainStage.onEnterFrame = function() {
			this.mainMgr.processTicks();
		}
	}
	
	
	
	function makeEnemy() {
		var newEnemy = new Enemy();
		newEnemy.init()
		_global.g.mainMgr.enemies.push(newEnemy);
	}
	
	function updateScore (pointsAdded){
		this.score += pointsAdded;
		_global.g.rootClip.mainStage.scoreBox.score.text = this.score;
	}
	
	function processTicks() {
		this.cursor.processTicks();
		this.spaceShip.processTicks();
		//this.keyMgr.processTicks();
		for(var i=0; i<this.bullets.length; i++) { this.bullets[i].processTicks(); }
		for(var i=0; i<this.enemies.length; i++) { this.enemies[i].processTicks(); }
		
		if(this.enemyTimer < 60) {
			this.enemyTimer += this.difficulty;
		}else{
			this.makeEnemy();
			this.enemyTimer = 0;
		}
		
		
		this.difficulty += 0.001; //Slowly ups the difficulty each frame
		
	}

}