
/**
 *	Initialize bubbles
 */
function bubble_instance(x, y) {

	for (var idx in Bubble) {
		this[idx] = Bubble[idx];
	}
	
	this.__construct(x, y);
	
	return this;

}


var Bubble = {

	MAX_STEPS : 3000,
	s_image : null,
	
	x : 0,
	y : 0,
	x_offset : 0,
	angle : 0.0,
	steps_traveled : 0,
	
	init : function() {
		Bubble.s_image = document.createElement("img");
		Bubble.s_image.src = TANK_BASE + "img/bubble.gif";
	},
	
	/** 
	 *	Initialize bubble
	 */
	__construct : function(x, y) {
		this.x = x;
		this.y = y;
		this.angle = Math.random() * Math.PI * 2;
	},
	
	
	/** 
	 * 	move the bubble
	 */
	move_step : function(steps) {
	
		if (this.steps_traveled > Bubble.MAX_STEPS ||
			DRAW_HEIGHT - u[Math.round((this.x + this.x_offset) / STEP)] > this.y + DRAW_HEIGHT ) {
			return false;
		}
		
		this.x_offset = Math.sin(this.angle) * 10;
		this.y -= steps * 0.05;
		this.angle += steps * 0.003;
		
		this.steps_traveled += steps;
		
		return true;
	},
	
	
	draw : function(context) {
		context.drawImage(Bubble.s_image, this.x + this.x_offset, this.y + DRAW_HEIGHT);
	}

};

