"use strict";

// dx and dy are in 1/8 units
var GO_MalfoseSpike = function(){
	this.sprite = new Sprite(GO_MalfoseSpike.spriteSheet,"MalfoseSpike");
	this.sprite.collision_flags = 
		DEFINE_SPRITE_COLLISION_FLAGS.SPRITES_PASSIVE;
	this.sprite.setBoundingBox(
		this.hitboxen[0].x,
		this.hitboxen[0].y,
		this.hitboxen[0].x+8,
		this.hitboxen[0].y+8);
	//sprite.constraints=constraints;
	this.sprite.max_step = 0;
	this.sprite.game_object = this; // no longer a generic GO

	this.angle = 0; // 0-255
	this.hp = 8;//32; // ok, I'll be nice to low% given spikes respawn now
};
GO_MalfoseSpike.spriteImg = SDS_Load_Image("art/sheets/sprite/malfose_spike.png");
GO_MalfoseSpike.spriteSheet = new TileSheet(4, 4, 2, 2, GO_MalfoseSpike.spriteImg);

GO_MalfoseSpike.prototype = new GameObject(
	new Sprite(
		GO_MalfoseSpike.spriteSheet,
		"MalfoseSpike"
	),
	"MalfoseSpike"
	);

	GO_MalfoseSpike.prototype.hitboxen = [
		{x:4,y:0},
		{x:6,y:0},
		{x:6,y:2},
		{x:8,y:2},

		{x:8,y:4},
		{x:8,y:6},
		{x:6,y:6},
		{x:6,y:8},

		{x:4,y:8},
		{x:2,y:8},
		{x:2,y:6},
		{x:0,y:6},

		{x:0,y:4},
		{x:0,y:2},
		{x:2,y:2},
		{x:2,y:0},
	];

	GO_MalfoseSpike.prototype.interactions = 
		DEFINE_GAMEOBJECT_INTERACTIONS.DAMAGE |
		DEFINE_GAMEOBJECT_INTERACTIONS.INFLICT;

	GO_MalfoseSpike.prototype.damage = function(source,points){
		this.hp -= points;

		return this.hp<=0;
	};
	GO_MalfoseSpike.prototype.inflict = function(){
		//this.sprite.map_room.removeSprite(this.sprite);
		//this.manager.remove(this);

		return {hp: 2, chi:0};
	};

	GO_MalfoseSpike.prototype.Update = function(){
		// playing with fire... I think Malfose can still keep tabs on the object
		// even after it's removed from the manager.
		if (this.hp<=0){
			this._heap.poof = new GO_Poof("FX_splat");
			this._heap.poof.spawnOnSprite(this.sprite,this.manager);
			this._heap.poof = null;

			this.clearFromRoom(this.sprite.map_room);
			this.manager.remove(this);
			return;
		}

		this.sprite.frame = ((this.angle+8)&0xff)>>4; // add half a tick to lookup so each frame is centered on its respective angle
		this.sprite.setBoundingBox(
			this.hitboxen[this.sprite.frame].x,
			this.hitboxen[this.sprite.frame].y,
			this.hitboxen[this.sprite.frame].x+8,
			this.hitboxen[this.sprite.frame].y+8);
	};

