summaryrefslogtreecommitdiffhomepage
path: root/not/Ray.lua
blob: 95915910e6dc08a747e08f22a211bb68296b5f1c (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
44
45
46
47
48
49
50
51
52
53
54
--- That awesome effect that blinks when player dies!
Ray = require "not.Object":extends()

function Ray:new (source, world)
	self.source = source
	self.world = world
	self.delay = 0.3
end

function Ray:update (dt)
	self.delay = self.delay - dt
	if self.delay < 0 then
		return true -- delete
	end
	return false
end

-- TODO: For some reason ray needs these 50s on camera boundaries.
-- TODO: Ray draw should be cleaned-up and exploded into methods if possible.
function Ray:draw ()
	love.graphics.setColor(255, 247, 228, 247)
	love.graphics.setLineStyle("rough")
	love.graphics.setLineWidth(self.delay*160)

	-- point b top-left
	-- point c bottom-right
	-- point d ray start
	-- point e ray end

	local x, y = self.source:getPosition()
	local bx, by, cx, cy = self.world.camera:getBoundaries()
	local a = y / x

	bx = bx - 50
	by = by - 50
	cx = cx + 50
	cy = cy + 50

	local dy, dx = bx * a, bx
	if dy < by or dy > cy then
		dy = by
		dx = by / a
	end

	local ey, ex = cx * a, cx
	if ey < by or ey > cy then
		ey = cy
		ex = cy / a
	end

	love.graphics.line(dx, dy, ex, ey)
end

return Ray