"use strict";

var EN_Anchovy = function(){
	this.sprite = new Sprite(EN_Anchovy.spriteSheet,"Anchovy");
	this.sprite.game_object = this; // no longer a generic GO

	this._basicInit(EN_Anchovy.params);

	//-----

	this.sprite.collision_flags |= (DEFINE_SPRITE_COLLISION_FLAGS.GROUND | DEFINE_SPRITE_COLLISION_FLAGS.AIR);

	this.dx = 0;
	this.dy = 0;
	this.dz = 0;
	this.z = 0;

	this.moveRes = new SpriteMoveResult();
};
EN_Anchovy.spriteImg = SDS_Load_Image("art/sheets/sprite/anchovy.png");
EN_Anchovy.spriteSheet = new TileSheet(3, 3, 1, 1, EN_Anchovy.spriteImg);
EN_Anchovy.params = {
	name: "Anchovy",
	box: [0,3,7,5], // left, top, right, bottom
	max_step: 2,
	hp: 1,
	infection: 0,
};

EN_Anchovy.prototype = new GO_Enemy();

	EN_Anchovy.prototype.ai = function(){
		this.sprite.move(this.dx,this.dy,this.moveRes);
		this.z+=this.dz;

		if (this.moveRes.flags & DEFINE_SPRITE_MOVE_RESULT_EJECTED_H){
			this.dx=0;
		}
		if (this.moveRes.flags & DEFINE_SPRITE_MOVE_RESULT_EJECTED_V){
			//this.dy=0;
			this.dy = (this.dy>0) ? -3 : 3;
		}

		this.toggleInteractionsStd();

		this._heap.frame = 0;
		if (this.infection>0) this._heap.frame+=2;
		if (this.dx<0) this._heap.frame+=1;
		this.sprite.frame=this._heap.frame;
	};
	EN_Anchovy.prototype.damage = function(source,points){
		if (points>0){
			this.hp-=points;
			return (this.hp<=0);
		}
		else{
			//var cough = new GO_Smoke();
			this._heap.cough = new GO_Smoke();
			this._heap.cough.sprite.x = this.sprite.x;
			this._heap.cough.sprite.y = this.sprite.y;
			this._heap.cough.launch_dir.x=0;
			this._heap.cough.launch_dir.y=0;
			this._heap.cough.host_obj = this;

			this.sprite.map_room.addSprite(this._heap.cough.sprite);
			this.manager.add(this._heap.cough);

			this._heap.cough = null;

			this.infection--;
			return false;
		}
	};
	EN_Anchovy.prototype._inflictVal = {hp:0, chi:1};
	EN_Anchovy.prototype.inflict = function(){
		return this._inflictVal;
	};
	EN_Anchovy.prototype.drop = function(){
		this._heap.dropRand = Math.random();
		if (this._heap.dropRand<0.01){
			return new GO_HeartDrop(GO_HeartDrop.SIZE.SMALL);
		}
		return null;
	};


