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

function init_level()
   set_ambient_light(0.5,0.5,0.5)
   -----------------------------------
   -- Walk
   local player=get_player()
   set_inertia(player,1)
   enable_input(player,false)
   set_movement_vector(player,{0,0,0.005})
   wait_time(1000)
   local text_id
   text_id=say(nil,"Covenant presents...",5000,{ 1,1,1,1 }); wait_text(text_id)
   text_id=say(nil,"AN OLD MAN AND HIS QUEST",5000,{ 1,1,1,1 }); wait_text(text_id)
   text_id=say(nil,"A Ludum Dare 48-hour developed game",5000,{ 1,1,1,1 }); wait_text(text_id)
   -----------------------------------
   -- Old man
   set_movement_vector(player,{0,0,0})
   local p=add_vec3(get_object_world_pos(player),{ -4,0,4 })
   instance_particle_system("puff_white_smoke",p)
   set_frame(player,frame_north)
   enable_movement(player,false)
   enable_anim(player,false)
   -- Old man
   wait_time(1000)
   local old_man=instance_game_sprite("old_man","old_man",p)
   set_frame(old_man,frame_south)
   text_id=say(old_man,"Well met, peasant!",2000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(player,"Hum?!",1000,{ 0.2,1.0,0.1,1 }); wait_text(text_id)
   text_id=say(old_man,"I am Van Conet, court mage...",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"I seek valiant men that\nare willing to embark on\nan epic quest!",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(player,"Quest?! What quest?!",2500,{ 0.2,1.0,0.1,1 }); wait_text(text_id)
   text_id=say(player,"Don't you guys have\nknights for that?!",2500,{ 0.2,1.0,0.1,1 }); wait_text(text_id)
   text_id=say(old_man,"Ah, alas, for a variety of\nreasons, let's just say that...",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"...we ran out!",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(player,"Ran out?! What do you mean ran out?!",4000,{ 0.2,1.0,0.1,1 }); wait_text(text_id)
   text_id=say(old_man,"No time for that now...",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"Princess Dhalya was poisoned\nby an Evil Cult,\nand we need someone to get the cure!",3000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"Lucky you, you got selected!",3000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(player,"Wait a minute, nah, nah, nah...",4000,{ 0.2,1.0,0.1,1 }); wait_text(text_id)
   text_id=say(player,"I ain't going on no quest!",4000,{ 0.2,1.0,0.1,1 }); wait_text(text_id)
   text_id=say(old_man,"Ok, ok...\nI can't force you...",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"I'll just open a portal to\nthe dungeon where the antitode is held...",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"If you decide to help us,\njust walk through...",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"If not, just walk away...",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"...coward...",2000,{ 1,1,0,1 }); wait_text(text_id)
   instance_particle_system("light_burst",p)
   wait_time(1000)
   local portal
   for i=-2,2,2 do
      portal=instance_game_sprite("portal","portal",add_vec3(get_object_world_pos(player),{ i,0,2 }))
      set_hostile(portal,false)
      set_shadow(portal,false)
      portal=instance_game_sprite("portal","portal",add_vec3(get_object_world_pos(player),{ i,0,-2 }))
      set_hostile(portal,false)
      set_shadow(portal,false)
   end
   for i=-2,2,2 do
      portal=instance_game_sprite("portal","portal",add_vec3(get_object_world_pos(player),{ -2,0,i }))
      set_hostile(portal,false)
      set_shadow(portal,false)
      portal=instance_game_sprite("portal","portal",add_vec3(get_object_world_pos(player),{ 2,0,i }))
      set_hostile(portal,false)
      set_shadow(portal,false)
   end
   instance_particle_system("puff_white_smoke",p)
   wait_time(1000)
   kill_game_sprite(old_man)
   enable_input(player,true)
   enable_anim(player,true)
   enable_movement(player,true)
end
