:NAME tutorial4

:GLOBAL int32					state
:GLOBAL float32					timer
:GLOBAL float32					focus_start_time
:GLOBAL float32					focus_start_scale
:GLOBAL c_object*				focus
:GLOBAL c_object*				message


local tutoriallib = require "scripts/tutorial_utils"

k_bottom_threshold= -5.7

local state= nil

-- ------------ initial delay and message 1 ------------

--tutoriallib.add_delay(.75)
--tutoriallib.make_state("message1")

-- ------------ wait for the omap to appear, and delay ------------

state= tutoriallib.add_delay(0)
function omap_appear()
	local ws= world_state_get()
	local player= ws.primary_player_get()
	if (player) then
		local target= player.target_get()
		if (target) then
			--if (target.is_immediate()) then
			--	global.timer= 0
			--if ((global.timer == 0) and target.is_known() and not target.is_immediate()) then
			if (target.is_known() and not target.is_immediate()) then
				return true
			end
		end
	end
end
state.end_func= omap_appear

tutoriallib.add_delay(1)

-- ------------ message 3, remove message 1 ------------

state= tutoriallib.make_state("message3")
function remove_message_1()
	tutoriallib.remove_bubble("message1")
	
	-- put the focus on the player
	local ws= world_state_get()
	local player= ws.primary_player_get()
	if (player) then
		local target= player.target_get()
		if (target) then
			local pos= target.location.point
			global.focus.position_set(pos.x, pos.y)
		end
	end
end
state.start_func= remove_message_1
tutoriallib.focus_on(state, "player", tutoriallib.k_scale_normal)

-- ------------ message 4 ------------

tutoriallib.make_state("message4", true)

-- ------------ wait for the player to get near the exit, then delay ------------

state= tutoriallib.add_delay(0)
function wait_for_player_to_near_exit()
	local ws= world_state_get()
	local player= ws.primary_player_get()
	if (player) then
		local position= player.world_position_get()
		if (position.y < k_bottom_threshold) then
			return true
		end
	end
end
state.end_func= wait_for_player_to_near_exit

tutoriallib.add_delay(1)

-- ------------ message 5, delete messages 3 and 4 ------------

state= tutoriallib.make_state("message5")
function remove_bubbles_3_4()
	tutoriallib.remove_bubble("message3")
	tutoriallib.remove_bubble("message4")
end
state.start_func= remove_bubbles_3_4
			
-- ------------ more messages and delay ------------

tutoriallib.make_state("message6")
tutoriallib.make_state("message7")
tutoriallib.add_delay(0)



-- ------------ init and update ------------


function global_initialize(g)
	g.state= 0
	g.message= nil
	g.focus= nil
	g.timer= 0
	g.focus_start_time= 0
	g.focus_start_scale= tutoriallib.k_scale_out
end

function start()

	local world= world_get()
	local ws= world_state_get()
	global.focus= object_place("focus")
	global.focus.hide(true)
	tutoriallib.start()

end

function update()
	tutoriallib.update(k_states, global)
end

system_register(start, update, nil, nil)
