summaryrefslogtreecommitdiffhomepage
path: root/ray.lua
blob: 433ef1cf10d924828d8b12e7a990e05d2e776f1e (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
-- `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
	love.graphics.line((-x+offset_x)*scale,(-y+offset_y-dy*0.7)*scale,(x+offset_x)*scale,(y+dy*0.7+offset_y)*scale)
	love.graphics.setLineWidth(1)
end