dofile("scripts/entities/entityinclude.lua")

h1 = 0
h2 = 0
past = 0

timer = 0

levelAt = 1
pastDefault = false

n = 0

function init(me)
	h1 = getNode("WATERLEVEL_HIGH")
	h2 = getNode("WATERLEVEL_LOW")
	past = getNode("RAISE_WATERLEVEL")
	bossRoom = getNode("NAIJA_ENTER")
	n = getNaija()
	
	loadSound("waterlevelchange")
end
	
function activate(me)
end

function update(me, dt)
	if not isFlag(FLAG_BOSS_SUNWORM, 0) then
		setWaterLevel(node_y(getNode("ENDWATERLEVEL")))
		return
	end
	if entity_x(n) > node_x(past) then
		if not pastDefault then
			setWaterLevel(node_y(h1), 2)
			pastDefault = true
		end
	else
		pastDefault = false
		timer = timer + dt
		if timer > 7 then
			playSfx("waterlevelchange")
			if levelAt == 1 then
				levelAt = 2
			else
				levelAt = 1
			end
			if levelAt == 1 then
				setWaterLevel(node_y(h1), 2)
			elseif levelAt == 2 then
				setWaterLevel(node_y(h2), 2)
			end
			timer = 0
		end
	end
end
