function Bullet(pid, pReference, pSpeed, pDivReference){
	this.base = ScreenObject;
	this.base(-32,-32,"bullet",pid,25,33,pDivReference,"bullet.gif");

	this.speed=pSpeed;
	this.status=0;

	this.objRef = pReference;

	this.start = function (){
		this.status=1;
		// Hmm... why fire backwards?
		switch(this.objRef.facing){	
			case kLeft: this.speed=-15;break;
			case kRight: this.speed=15;break;
		}
		this.speed = pSpeed;
		
		this.x = this.objRef.x+this.objRef.width/2-3;
		this.y = this.objRef.y+this.objRef.height/2-5;
	}

	this.stop = function(){
		this.x=(0-this.height*2);
		this.y=(0-this.width*2);
		this.status=0;
	}
	
	this.move = function(){
		if(this.x<TheGame.screenWidth&&this.x>0)
			this.x+=this.speed;
			else this.stop();
	}
	
	this.remove = function(){
		this.stop();
		this.draw();
	}
}
//Bullet.protoype = new ScreenObject; //inherits from screenobject

function BulletController(pNumBullets, pDivReference){
	this.group = new Array();
	this.numBullets = pNumBullets;
	
	this.fireRate = 2;
	this.threshold = this.fireRate-1;
	this.div = pDivReference;
	
	this.init = function(){
		 for(bcCount1=0;bcCount1<this.numBullets;bcCount1++){
		 	this.group[bcCount1] = new Bullet(bcCount1, TheGame.P, 20, this.div);
			this.group[bcCount1].init();
		}
	}
	this.init();

	this.update = function(){
		for(bcUpCount=0;bcUpCount<this.numBullets;bcUpCount++){
			if(this.group[bcUpCount].status==1){
				this.group[bcUpCount].move();
				this.group[bcUpCount].draw();
			}
		}
	}
	
	this.start = function(){
		if(++this.threshold==this.fireRate){
			for(bcCount1=0;bcCount1<this.numBullets;bcCount1++){
				if(this.group[bcCount1].status==0){
					this.group[bcCount1].start();
					break;
				}
			}
			this.threshold=0;
		}
	}
	this.checkCol = function(pBaddieController){
		for(bcColCount=0;bcColCount<this.numBullets;bcColCount++){
			if(this.group[bcColCount].status==1){
				for(bcCount2=0;bcCount2<pBaddieController.group.length;bcCount2++){
					if(pBaddieController.group[bcCount2].status!=0){
						if(Collision(pBaddieController.group[bcCount2], this.group[bcColCount])){
							TheGame.Explosion1.x = this.group[bcColCount].x;
							TheGame.Explosion1.y = this.group[bcColCount].y;
							TheGame.Explosion1.status=1;
							TheGame.P.score+=pBaddieController.group[bcCount2].pointValue;
							pBaddieController.group[bcCount2].remove();
							this.group[bcColCount].remove();
						}
					}
				}
			}
		}
	}
}
