"use strict";

var GO_Sparkle = function(lifespan,dx,dy){
	this.sprite = new Sprite(GO_Sparkle.spriteSheet,"Poof");
	this.sprite.collision_flags = 0;
	this.sprite.setBoundingBox(0,0,8,8);
	//this.sprite.constraints=constraints;
	this.sprite.max_step = 0;
	this.sprite.game_object = this; // no longer a generic GO
	this.lifespan = lifespan ? lifespan : 8;
	this.frame_timer = 0;

	this.dx = dx ? dx : 0;
	this.dy = dy ? dy : 0;
	this.dx_accum = 0;
	this.dy_accum = 0;
};
GO_Sparkle.spriteImg = SDS_Load_Image("art/sheets/sprite/sparkle.png");
GO_Sparkle.spriteSheet = new TileSheet(3, 3, 3, 0, GO_Sparkle.spriteImg);

GO_Sparkle.prototype = new GameObject(
	new Sprite(
		GO_Sparkle.spriteSheet,
		"Sparkle"
	),
	"Sparkle"
	);

	GO_Sparkle.prototype.interactions = 0;

	GO_Sparkle.prototype.Update = function(){
		this.frame_timer++;
		this.sprite.frame = this.frame_timer&7;

		this.dx_accum+=this.dx;
		this.dy_accum+=this.dy;

		this._heap.dx = this.dx_accum>>3;
		this._heap.dy = this.dy_accum>>3;

		this.dx_accum &= 7;
		this.dy_accum &= 7;

		this.sprite.move(this._heap.dx,this._heap.dy,  this._heap.spriteMoveRes);

		if (this.frame_timer == this.lifespan){
			this.sprite.map_room.removeSprite(this.sprite);
			this.manager.remove(this);
		}
	}