Advertisement
snake5

SGScript saves the day | LD33 level script

Aug 24th, 2015
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global MSGTIME = 5.0;
  2. global MONEY_TARGET = 500.0;
  3. global MONEY_TARGET_STR = "50 000";
  4.  
  5. function GET_TOTAL_MONEY()
  6. {
  7.     return string_format( "{1:f.2}", 950000 + money_total );
  8. }
  9.  
  10. function onLevelStart()
  11. {
  12.     global money_total = 0.0;
  13.     global donations = [];
  14.     global cur_donation = 0;
  15.     global goal_reached = false;
  16.     global mission_failed = false;
  17.     global hackcount = 0;
  18.    
  19.     for( i = 0; i < 5; ++i )
  20.         donations.push( ( i + 1 ) * 3.4 * 1000 );
  21.     donations.shuffle();
  22.    
  23.     ObjectiveAdd( "Discover a computer", OS_Open );
  24.     ObjectiveAdd( "Steal $" $ MONEY_TARGET_STR, OS_Open );
  25.     ObjectiveAdd( "Get out", OS_Hidden );
  26.    
  27.     EntitySetProperties( "walker1", "patrol_path",
  28.     [
  29.         { type = "move", target = GetNamedPosition("center") },
  30.         { type = "wait", time = 1.0 },
  31.         { type = "move", target = GetNamedPosition("ew_elev") },
  32.         { type = "move", target = GetNamedPosition("ew_desk1") },
  33.         { type = "look", target = GetNamedPosition("ew_desk1in") },
  34.         { type = "wait", time = 2.0 },
  35.         { type = "move", target = GetNamedPosition("ew_cnr1") },
  36.         { type = "move", target = GetNamedPosition("ew_elev") }, // TODO
  37.     ]);
  38.    
  39.     EntitySetProperties( "walker_fw", "patrol_path",
  40.     [
  41.         { type = "move", target = GetNamedPosition("farwall") },
  42.         { type = "wait", time = 1.0 },
  43.         { type = "move", target = GetNamedPosition("ww_cnr1") },
  44.         { type = "move", target = GetNamedPosition("ww_desk1") },
  45.         { type = "look", target = GetNamedPosition("ww_desk1in") },
  46.         { type = "wait", time = 2.0 },
  47.         { type = "move", target = GetNamedPosition("ww_wall") },
  48.         { type = "wait", time = 1.0 },
  49.         { type = "move", target = GetNamedPosition("ww_desk1") },
  50.         { type = "look", target = GetNamedPosition("ww_desk1in") },
  51.         { type = "wait", time = 1.0 },
  52.         { type = "move", target = GetNamedPosition("ww_cnr1") },
  53.     ]);
  54.    
  55.     SetMusic( "/intro_music" );
  56.     SetCutsceneFunc(function(t)
  57.     {
  58.         if( t < 5 ) SetCameraPosDir( vec3(5-t*2,-5,1), vec3(0,1,0) );
  59.         else if( t < 15 )
  60.         {
  61.             a = t*0.5;
  62.             s = sin(a);
  63.             c = cos(a);
  64.             SetCameraPosDir( vec3(c*5,s*5,2.5), -vec3(c,s,0.5) );
  65.         }
  66.         else if( t < 30 )
  67.         {
  68.             b = pow( t - 15, 0.5 ) * 2;
  69.             SetCameraPosDir( vec3(-3.5-b*0.2,-5+b*0.5,0.5+b*0.2), vec3(-0.1-b*0.04,1,0.4-b*0.15) );
  70.         }
  71.        
  72.         if( t < 1 ) SetCutsceneSubtitle( "" );
  73.         else if( t < 3 ) SetCutsceneSubtitle( "His name is Jack" );
  74.         else if( t < 5 ) SetCutsceneSubtitle( "and he wants to buy a yacht." );
  75.         else if( t < 7 ) SetCutsceneSubtitle( "He needs $ 1 000 000 to do that" );
  76.         else if( t < 9 ) SetCutsceneSubtitle( "so he steals money from charities." );
  77.         else if( t < 11 ) SetCutsceneSubtitle( "He is a monster..." );
  78.         else if( t < 13 ) SetCutsceneSubtitle( "...and, for the moment, you are him." );
  79.         else if( t < 15 ) SetCutsceneSubtitle( "" );
  80.         else if( t < 17 ) SetCutsceneSubtitle( "Hack computers to get the remaining $ 50 000" );
  81.         else if( t < 19 ) SetCutsceneSubtitle( "but don't do it while somebody's watching!" );
  82.         else SetCutsceneSubtitle( "" );
  83.        
  84.         if( t > 20 )
  85.         {
  86.             SetMusic( "/game_music" );
  87.             return true;
  88.         }
  89.     }, 0);
  90.    
  91.     SetShowMoney( true, 950000 + money_total );
  92.     SetShowSuspicion( true );
  93. }
  94.  
  95. function HackState( add )
  96. {
  97.     global hackcount;
  98.     hackcount += add;
  99.     SetMusicVar( "stealing", hackcount > 0 );
  100. }
  101.  
  102. function OnMissionFailed( pos )
  103. {
  104.     global mission_failed;
  105.     if( mission_failed )
  106.         return;
  107.     mission_failed = true;
  108.    
  109.     EndGame( "Failed!", false );
  110. }
  111.  
  112. function OnMoneyStolen()
  113. {
  114.     global money_total, donations, cur_donation;
  115.     stolen_money = donations[ cur_donation++ % donations.size ] + rand() % 500;
  116.     money_total += stolen_money;
  117.     println( "Stolen: ", stolen_money, ", total now: ", money_total );
  118.     SendMessage( MT_Info, "Stolen: " $ stolen_money $ ", total now: " $ GET_TOTAL_MONEY() );
  119.     SendMessage( MT_Warning, "Hacking done, hide your tracks!", MSGTIME );
  120.    
  121.     SetShowMoney( true, 950000 + money_total );
  122. }
  123.  
  124. function OnHackingStarted( cold )
  125. {
  126.     HackState( 1 );
  127.     if( cold )
  128.     {
  129.         SendMessage( MT_Warning, "Hacking started! Watch out for employees!", MSGTIME );
  130.     }
  131. }
  132.  
  133. function OnHackingStopped( done )
  134. {
  135.     if( done )
  136.     {
  137.         if( money_total >= MONEY_TARGET && goal_reached == false )
  138.         {
  139.             global goal_reached = true;
  140.             SendMessage( MT_Info, "Successfully stolen $" $ MONEY_TARGET_STR $ ". Time to get out.", MSGTIME );
  141.             ObjectiveSetState( 1, OS_Done );
  142.         //  ObjectiveSetState( 2, OS_Open );
  143.             SetCutsceneFunc(function(t)
  144.             {
  145.                 b = pow( t * 0.2, 0.5 ) * 5;
  146.                 if( b > 6 )
  147.                     b = 6;
  148.                 SetCameraPosDir( vec3(-2.5+b,-5,2.5), vec3(1,-0.4+b*0.15,-0.4) );
  149.             });
  150.             EndGame( "Success!", true );
  151.             return;
  152.         }
  153.         else
  154.         {
  155.             SendMessage( MT_Info, "Well done! Now look for another PC to hack...", MSGTIME );
  156.             SendMessage( MT_Continued, "...or wait for the next donation!", MSGTIME );
  157.         }
  158.     }
  159.     HackState( -1 );
  160. }
  161.  
  162. function OnDiscoveredComputer()
  163. {
  164.     SendMessage( MT_Info, "Computer discovered", MSGTIME );
  165.     ObjectiveSetState( 0, OS_Done );
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement