/*
Basic life-restoring drops
*/

"use strict";

//var DEFINE_HEART_SIZE = {
//	SMALL: 0,
//	BIG: 1
//}
var GO_HeartDrop = function(size){
	var name = "";
	var restoration = 0;
	var box = [0,0,15,15];
	switch(size){
		case GO_HeartDrop.SIZE.SMALL:
			name = "Small Heart";
			restoration = 1;
			box = [3,5,11,12];
		break;
		case GO_HeartDrop.SIZE.BIG:
			name = "Big Heart";
			restoration = 5;
			box = [1,3,13,14];
		break;
		default:
			name = "Small Heart";
			restoration = 1;
			box = [3,5,11,12];
		break;
	}
	this.sprite = new Sprite(GO_HeartDrop.spriteSheet,name);
	this.sprite.collision_flags = 
		DEFINE_SPRITE_COLLISION_FLAGS.SPRITES_PASSIVE;
	this.sprite.setBoundingBox(box[0],box[1],box[2],box[3]);
	this.sprite.game_object = this; // no longer a generic GO

	this.name = name;

	this.restoration = restoration;
	this.size = size;
		
	this.frame_timer=0;
};
GO_HeartDrop.spriteImg = SDS_Load_Image("art/sheets/sprite/drops.png");
GO_HeartDrop.spriteSheet = new TileSheet(4, 4, 2, 3, GO_HeartDrop.spriteImg);
GO_HeartDrop.SIZE = {
	SMALL: 0,
	BIG: 1
}

GO_HeartDrop.prototype = new GameObject(
	new Sprite(
		GO_HeartDrop.spriteSheet,
		"Heart"
	),
	"Heart"
	);

	GO_HeartDrop.prototype.interactions = 
		DEFINE_GAMEOBJECT_INTERACTIONS.COLLECT;

	GO_HeartDrop.prototype.collect = function(sourceGO){
		this.sprite.map_room.removeSprite(this.sprite);
		this.manager.remove(this);
		GLOBAL_DIARY.life+=this.restoration;
		GLOBAL_DIARY.life = Math.min(GLOBAL_DIARY.life,GLOBAL_DIARY.max_life);
		switch(this.size){
			case GO_HeartDrop.SIZE.SMALL:
				sourceGO.playSound("FX_smallheart");
			break;
			case GO_HeartDrop.SIZE.BIG:
				sourceGO.playSound("FX_bigheart");
			break;
			default:
				sourceGO.playSound("FX_smallheart");
			break;
		}
		return null;
	};

	GO_HeartDrop.prototype.Update = function(){
		this.frame_timer++;
		this.frame_timer&=15;
		this.sprite.frame = this.frame_timer>>2;
		if (this.size==GO_HeartDrop.SIZE.BIG){
			this.sprite.frame+=4;
		}
	};