playerLightning = {}
lightningScale = 0
alienLightning = {}
-- a chuck of text that pops on the screen, then falls off
TextPop = class(Object, function(o, x, y, text)
  Object.init(o, x, y,10, 10)
  o.text = StringObject(x, y, text, nil, .75)
  o.text:setPosition(x-o.text.w/2, y-o.text.h/2)
  o.text:setColor(0,0,0)
  Tweener:addTween(o.text, {multiplier=1.25}, {time=0.5, func='outBounce', onComplete=function()
    Tweener:addTween(o.text, {multiplier=1}, {time=0.5})
    Tweener:addTween(o.text.pos, {y=o.text.pos.y+100*r_scale}, {time=1, func='inExpo'})
    o.fade = Tweener:addTween(o.text.tint, {a=0}, {time=2,onComplete=function()
      Object.kill(o)
    end})
  end})
end)
function TextPop:draw()
  self.text:draw()
end
function TextPop:update()
  self.text:buildSubs()
  self.text:setPosition(self.pos.x-self.text.w/2, self.pos.y-self.text.h/2)
  self.text:update()
end
-- lightning that goes between a healing room and a room being healed
PlayerLightning = class(Object, function(o, a, b)
	-- should eventually position it within a bounding box created by the two rooms
	o.a = a:center()
	o.b = b:center()
	o.b:sub(o.a)
	o.dist = o.b:length()
	Object.init(o, o.a.x, o.a.y, 20, 20)

	-- we cache the lightning after the first load.
	-- probably shouldn't be in a global, but whatever
	if playerLightning[1] == nil then
		for i=1,3 do
			playerLightning[i] = SvgLoader(svg_root .. "defence/heal_bolt_" .. i .. ".svg", true)
		end
		lightningScale = playerLightning[3]:getMaxY()
	end
	o.scale = o.dist/lightningScale
	o.rot = math.pi-o.b:angle()+(math.pi)
	o.currentAnimation = AnimationModel(playerLightning, {rate=100})
	o.drawType = 'svg'
	o.fade = Tweener:addTween(o.tint, {a=0}, {time=0.5, func="inExpo", onComplete=function()
		Object.kill(o)
	end})
end)
function PlayerLightning:draw()
	if self.alive then
		self.svg = self.currentAnimation:getSprite()
		self.svg:resetTransform()
		self.svg:scale(1, self.scale)
		self.svg:rotate(self.rot)
		Object.draw(self)
	end
end
PlayerLine = class(Object, function(o, a, b, fade)
	-- should eventually position it within a bounding box created by the two rooms
	o.a = a
	o.b = b
	o.w = 4
	o.sprite = sprites['tiles']['white.png']
	Object.init(o, o.a.x, o.a.y, o.b.x, o.b.y)
	o.svg = ObjectGroup()
	o.svg:setSheet(sheets['tiles'])
	if fade then
		o.fade = Tweener:addTween(o.tint, {a=0}, {time=1.5, func="inExpo", onComplete=function()
			Object.kill(o)
		end})
	end
end)
function PlayerLine:fadeNoKill()
	if self.fade then Tweener:removeTween(self.fade) end
	self.fade = Tweener:addTween(self.tint, {a=0}, {time=3, func="outExpo"})
end
function PlayerLine:draw()
	if self.alive then
		-- translate the points into camera points
		local a = bludG.camera:worldToScreen(self.a)
		local b = bludG.camera:worldToScreen(self.b)
		-- self:setColor(255, 255, 255, 205)
		self.svg:drawLine(a.x, a.y, b.x, b.y, self.tint.r, self.tint.g, self.tint.b, self.tint.a, self.w*r_scale)
	end
end

-- lightning that goes between a healing room and a room being healed
AlienLightning = class(PlayerLightning, function(o, a, b)
	PlayerLightning.init(o, a, b)
	-- we cache the lightning after the first load.
	-- probably shouldn't be in a global, but whatever
	if alienLightning[1] == nil then
		for i=1,5 do
			alienLightning[i] = SvgLoader(svg_root .. "defence/alien_bolt_" .. i .. ".svg", true)
		end
	end
	o.currentAnimation = AnimationModel(alienLightning, {rate=100, loop=false})
end)