﻿//! 自弾
var Shot = Class.create();
Shot.prototype = {
	initialize : function() {
		this.x    = 0;	// 座標
		this.y    = 0;	// 座標
		this.vx   = 0;	// 速度
		this.vy   = 0;	// 速度
		this.life = 0;	// 自弾の生死
		Element.hide($("shot"));
	},

	start : function(h) {
		if (this.life != 0) return;
		Element.show($("shot"));
		this.x = h.x;
		this.y = h.y;
		this.vx = -0.00012 * sin16(h.rangle);
		this.vy =  0.00012 * cos16(h.rangle);
		this.life = 1;
	},

	kill : function() {
		this.life = 0;
		Element.show($("shot"));
	},

	update : function() {
		if (this.life == 0) {
			Element.hide($("shot"));
			return;
		}
		this.x += this.vx;
		this.y += this.vy;
		for (var i = 0; i < enemTask.work.length; i++) {
			var e = enemTask.work[i];
	        var dx = e.x - this.x;
	        var dy = e.y - this.y;
			if (Math.abs(dx) <= 0.00012 && 
			    Math.abs(dy) <= 0.00012) {
				explode(e.x, e.y, 100);
				this.kill();
				e.start();
				continue;
			}
	    }
	},

	render : function() {
		var x = toScreenX(this.x);
		var y = toScreenY(this.y);
		$("shot").style.left = (x-8) + "px";
		$("shot").style.top  = (y-8) + "px";
		if (isClip(x, y)) this.life = 0;
	}
};
