"use strict";
/* keeper of the village shrine.  Old age has taken the edge off her personality.  No, trust me on this. */
var GO_Rinda = function(){
	this.sprite = new Sprite(GO_Rinda.spriteSheet,"Rinda");
	this.sprite.collision_flags = 
		DEFINE_SPRITE_COLLISION_FLAGS.GROUND | 
		DEFINE_SPRITE_COLLISION_FLAGS.AIR |
		DEFINE_SPRITE_COLLISION_FLAGS.SPRITES_ACTIVE |
		DEFINE_SPRITE_COLLISION_FLAGS.SPRITES_PASSIVE;
	this.sprite.setBoundingBox(2,0,13,15);
	this.sprite.game_object = this; // no longer a generic GO

	this.controls = new Controls(); // just to init

	this.horizontal_move_index=0;
	this.vertical_move_index = 0;
	this.anim_state = this.ANIM_STATES.bob;
	this.frame_timer=0;

	this.direction = 1; // +/-1 for facing
};
GO_Rinda.spriteImg = SDS_Load_Image("art/sheets/sprite/keeper1.png");
GO_Rinda.spriteSheet = new TileSheet(4, 4, 2, 2, GO_Rinda.spriteImg);

GO_Rinda.prototype = new GameObject(
	new Sprite(
		GO_Rinda.spriteSheet,
		"Rinda"
	),
	"Rinda"
	);

	GO_Rinda.prototype.interactions = 
		DEFINE_GAMEOBJECT_INTERACTIONS.CONTROL |
		DEFINE_GAMEOBJECT_INTERACTIONS.CHECK;

	GO_Rinda.prototype.leftward_move_water = [0,-1,-2];
	GO_Rinda.prototype.rightward_move_water = [0,1,2];
	GO_Rinda.prototype.upward_move_water = [0,-1,-2];
	GO_Rinda.prototype.downward_move_water = [0,1,2];
	GO_Rinda.prototype.ANIM_STATES = {
		"bob" : 0,
		"swim" : 1
	};
	GO_Rinda.prototype.anim_frames = [
		[0,0,1,1], //"bob" : 
		[0,1,0,2] //"swim" : 
	];

	/*GO_Rinda.prototype.checkEvent = function(sourceGO){
		var line = null;
		if (!GLOBAL_DIARY.check(1,"SHRINEQUAKE") && !GLOBAL_SCRATCHPAD.check("Dlg_Rinda_Line")) line = "Rinda_shrinequake_setup";
		GLOBAL_SCRATCHPAD.note("Dlg_Rinda_Line",1);
		return line;
	};*/
	GO_Rinda.prototype.checkEvent = function(sourceGO){
		if (sourceGO && sourceGO.sprite) this.direction = (sourceGO.sprite.x<this.sprite.x) ? -1 : 1;
		
		return Dialogue_getCurrentEvent["Rinda"]();
	};

	GO_Rinda.prototype.Update = function(){

		this._heap.oldAnimState = this.anim_state;

		this.NPCSwim();
		

		if (this._heap.oldAnimState != this.anim_state){
			this.frame_timer=0;
		}
		this.frame_timer++;
		this._heap.aniFrame = (this.frame_timer>>2) % this.anim_frames[this.anim_state].length;

		this.sprite.frame = this.anim_frames[this.anim_state][this._heap.aniFrame];

		if (this.controls.held.A){
			this.sprite.frame = 4;
		}

		this.sprite.frame = this.sprite.frame & 7;
		if (this.direction<0) this.sprite.frame+=8;
	};


