fade = {}

function fade.reset()
	fade.move = false
	fade.time = nil
end

function fade.off()
	fade.move = true
	fade.time = nil
end

function fade.think()
	if not fade.time return end
	fade.time = fade.time+1
	if fade.time > 30
		fade.time = nil
	end
end

function fade.draw(screen)
	if not fade.time and not fade.move
		for y = 0,240,16
			for x = 0,320,16
				screen.draw(graphics[Fade],{240,0,16,16},{x,y})
			end
		end
	end
	if not fade.time return end

	-- TODO: Different fade wipe animations instead of this one shitty generic filler.
	local frame = math.floor(fade.time / 2)
	if fade.move
		frame = 15-frame
	end
	if frame < 0
		frame = 0
	elseif frame > 15
		frame = 15
	end
	for y = 0,240,16
		for x = 0,320,16
			screen.draw(graphics[Fade],{16*frame,0,16,16},{x,y})
		end
	end
end
