std.include("scripts/common.lua")

function init_level()
   -----------------------------------
   -- Create portal
   local spawn_point=get_trigger_point(65280)
   local p=get_trigger_point_world_pos(spawn_point)
   local portal=instance_game_sprite("portal","portal",p)
   set_hostile(portal,false)
   set_shadow(portal,false)
   -----------------------------------
   -- Spawn old man
   local player=get_player()
   set_frame(player,frame_north)
   enable_input(player,false)
   enable_anim(player,false)
   enable_movement(player,false)
   -- Particle system
   local spawn_point=get_trigger_point(1)
   local p=add_vec3(get_trigger_point_world_pos(spawn_point),{ 1.5,0,4.5 })
   instance_particle_system("puff_white_smoke",p)
   -- Old man
   wait_time(1000)
   local old_man=instance_game_sprite("old_man","old_man",p)
   set_frame(old_man,frame_south)
   wait_time(2000)
   -----------------------------------
   -- Speech part
   local text_id
   text_id=say(old_man,"Oh dear...",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(player,"Er... I'm dead, ain't I?",4000,{ 0.2,1.0,0.1,1 }); wait_text(text_id)
   text_id=say(old_man,"Well...",2000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"Yes...",2000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(player,"Oh...",2000,{ 0.2,1.0,0.1,1 }); wait_text(text_id)
   text_id=say(player,"Well, that sucks...",2000,{ 0.2,1.0,0.1,1 }); wait_text(text_id)
   text_id=say(old_man,"Lucky for you,\nI have some power still...",1000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"Just hop into the portal ahead!",4000,{ 1,1,0,1 }); wait_text(text_id)
   -----------------------------------
   -- Disappear old man
   -- Particle system
   instance_particle_system("puff_white_smoke",p)
   -- Old man
   wait_time(1000)
   kill_game_sprite(old_man)
   -----------------------------------
   -- Renable player
   enable_input(player,true)
   enable_anim(player,true)
   enable_movement(player,true)
end
