How to Code Real Time Events Taking Place?

Started by Vverano7, Sat 30/12/2017 02:25:56

Previous topic - Next topic

Vverano7

Hi, I am new to AGS and am creating a game. In my game, I want the player to have a lot of freedom and choice in regard to catching this one thief character. I was kinda reminded of a game like The Last Express, where events will take place real time. I wanted to have something like this in my game. For example, the thief would be at Scene 1 in 1 minute, Scene 5 at minute 7, etc... Would it be possible to code this? I want the player to have to find the thief based off what point the thief is up to. For example, if the player were to merely follow the thief, he would continuously walk through around 10 scenes before completing a game event. How would I code this? (Sorry for the weird wording)

Thank you.

Snarky

Keep track of the in-game time using a global variable, which you update in repeatedly_execute(). Base your game logic on the value of this variable.

To keep track of time, use something like this:

Code: ags
// Global variables:
// int timeCounter
// bool isTimeRunning

function repeatedly_execute()
{
  if(isTimeRunning)
    timeCounter++;
}


To make the thief carry out some script at various times, I would use an enum with the times for the different steps, and update his progress in repeatedly_execute():

Code: ags
enum ThiefAction
{
  // A list of the different things the thief does at what time (in seconds)
  eThiefBeforeBreakIn = 0,
  eThiefEnterHouse = 120,
  eThiefOpenSafe = 150,
  eThiefGetawayGarden = 180,
  eThiefGetawayStreet = 200,
  eThiefHideOut = 240
};

ThiefAction currentThiefAction;

function repeateadly_execute()
{
  switch(currentThiefAction)
  {
    case eThiefBeforeBreakIn:
      // TODO: Logic for before break-in
      // Switch to next state at the right time
      if(timeCounter * GetGameSpeed() >= eThiefEnterHouse)
      {
        cThief.ChangeRoom(OFFICE);
        currentThiefAction = eThiefEnterHouse;
      }
      break;
    case eThiefEnterHouse:
      if(timeCounter * GetGameSpeed() >= eThiefOpenSafe)
      {
        safeIsOpen = true; // This is some global variable
        currentThiefAction = eThiefOpenSafe;
      }
      break;
    case eThiefOpenSafe:
      if(timeCounter * GetGameSpeed() >= eThiefGetAwayGarden)
      {
        cThief.ChangeRoom(GARDEN);
        currentThiefAction = eThiefGetAwayGarden;
      }
      break;
    // ETC.
  }
}

SMF spam blocked by CleanTalk