var shotImg;
var shotStack;

function shotNewGame() {
	shotImg = new Image();
	shotImg.src = "data/graphics/shot.png";
	shotStack = new Array();
}

function Shot() {
	this.obj = new FlyingObj();
	this.isFriendly; /* friendly damage enemies */
}

function fireAShot(startX, startY, dirX, dirY, isFriendly) {
	var shot = new Shot();
	shot.obj.x = startX;
	shot.obj.y = startY;
	shot.obj.dirX = dirX;
	shot.obj.dirY = dirY;
	shot.obj.img = shotImg;
	shot.isFriendly = isFriendly;
	shotStack.push(shot);
}

function shotUpdate() {
	var shot;
	for (i in shotStack) {
		shot = shotStack[i];
		shot.obj.move();
		if (!shot.obj.isIndsideObj(canvas)) {
			removeShot(i);
		}
		if (!shot.isFriendly && shot.obj.isIndsideObj(playerShip.obj)) {
			playerShip.hitted(1);
			removeShot(i);
		}
		if (shot.isFriendly) {
			for (var ei in enemyStack) {
				if (enemyStack[ei].obj.isIndsideObj(shot.obj)) {
					enemyStack[ei].hitted(1);
					removeShot(i);
					playerShip.score++;
				}
			}
		}
	}
}

function removeShot(index) {
	shotStack.splice(index, 1);
}

