ParticleHandler = class(Object, function(o, x, y, file, sprite, ...)
	local arg = {...}
	if arg[1] == nil then
		options = {}
	else
		options = arg[1]
	end
	o.lifetime = options.lifetime or 0.25
	o.cooldown = options.cooldown or 1

	Object.init(o, x, y, 1, 1)
	o.pl = ParticleLoader(sprite, file)
	o.pl.particles:setPosition(o.pos.x, o.pos.y)
	o.pl.particles:start()
	o.alive = true
	o.age = 0
	o.immortal = options.immortal or false
	if options.preroll then o.pl.particles:update(options.preroll) end
end)

function ParticleHandler:draw()
	self.pl.particles:draw(bludG.camera.scroll.x, bludG.camera.scroll.y, bludG.camera.scale)
end
function ParticleHandler:update()
	self.pl.particles:update(bludG.elapsed)
	self.age = self.age + bludG.elapsed
	if self.alive and self.age > self.lifetime and not self.immortal then
		self.alive = false
		self.pl.particles:stop()
	end
	if not self.alive and self.age > self.lifetime+self.cooldown and self.exists then
		self.exists = false
	end
end
function ParticleHandler:setPosition(x, y)
	Object.setPosition(self, x, y)
	if self.pl then
		self.pl.particles:setPosition(x, y)
	end
end

ParticleZip = class(Object, function(o, x, y, x2, y2, dataFile, sprite, ...)
	local arg = {...}
	if arg[1] == nil then
		options = {}
	else
		options = arg[1]
	end
	Object.init(o, x, y, 1, 1)
	o.ph = ParticleHandler(x, y, dataFile, sprite, options)
	Tweener:addTween(o.pos, {x=x2, y=y2}, {onComplete=function()
		o.exists = false
	end})
end)
function ParticleZip:update()
	self.ph:setPosition(self.pos.x, self.pos.y)
	self.ph:update()
end
function ParticleZip:draw()
	self.ph:draw()
end
