"use strict";
/* Fred and Ned.  Identical in appearance and work ethic. */
var GO_FredNed = function(){
	this.sprite = new Sprite(GO_FredNed.spriteSheet,"FredNed");
	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_FredNed.spriteImg = SDS_Load_Image("art/sheets/sprite/worker.png");
GO_FredNed.spriteSheet = new TileSheet(4, 4, 2, 2, GO_FredNed.spriteImg);

GO_FredNed.prototype = new GameObject(
	new Sprite(
		GO_FredNed.spriteSheet,
		"FredNed"
	),
	"FredNed"
	);

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

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

	GO_FredNed.prototype.checkEvent = function(sourceGO){
		if (sourceGO && sourceGO.sprite) this.direction = (sourceGO.sprite.x<this.sprite.x) ? -1 : 1;
		
		return Dialogue_getCurrentEvent[this.name]();
	}

	GO_FredNed.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];

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

