summaryrefslogtreecommitdiffhomepage
path: root/ray.lua
blob: 486c50579da4f5305a49361b0e98ecd8fa366d03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
-- `Ray`
-- That awesome effect that blinks when player dies!

-- WHOLE CODE HAS FLAG OF "need a cleanup"

Ray = {
	naut = nil,
	world = nil,
	delay = 0.3
}
function Ray:new(naut, world)
	-- Meta
	local o = {}
	setmetatable(o, self)
	self.__index = self
	-- Init
	o.naut = naut
	o.world = world
	return o
end
function Ray:update(dt)
	self.delay = self.delay - dt
	if self.delay < 0 then
		return true -- delete
	end
	return false
end
function Ray:draw(offset_x, offset_y, scale)
	love.graphics.setLineStyle("rough")
	love.graphics.setLineWidth(self.delay*160*scale)
	local x, y = self.naut:getPosition()
	local m = self.world.map
	local dy = m.height
	if y > m.center_y then
		dy = -dy
	end
	local dx = m.width
	if x > m.center_x then
		dx = -dx
	end
	love.graphics.line((m.center_x+offset_x+dx)*scale,(m.center_y+offset_y+dy)*scale,(x+offset_x)*scale,(y+dy*0.7+offset_y)*scale)
	love.graphics.setLineWidth(1)
end