Creating a time limit in a game [SOLVED]

Started by kec, Sun 31/07/2005 21:41:06

Previous topic - Next topic

kec

I want to make a game where I have a limited time to solve a mystery. I also want the player to see how muck time he has left. I also wanna make every ending different when the time expires (how many puzzels you have solved determines the ending) but I don`t want to use points. Being that I am an idiot I need help. So HELP!
I like meat.

monkey0506

#1
In the manual:

SetTimer
IsTimerExpired
SetGlobalInt
GetGlobalInt

Use something like:

Code: ags
/*main global script*/
int time = 24000; /* 10 minutes */

/*game_start*/
SetTimer(1, time);

/*rep_ex*/
if (IsTimerExpired(1)) {
  /* end game */
  }
else {
  int timemins = time / 2400;
  int timesecs = ((time / 2400) - timemins) * 60;
  string strtime;
  StrFormat(strtime, "%d minutes %d seconds remain", timemins, timesecs);
  Labelname.SetText(strtime);
  time--;
  }


And then just use the GlobalInts as flags to determine the interactions at the end of the game.  Set a GlobalInt whenever an important end changing action happens, and test it when running the ending interactions.

Edit:  Also, the seconds is based upon floating point math (it requires the decimals to remain at least until multiplied by 60) so you may have to change that to:

Code: ags
float timesecsfl = ((IntToFloat(time) / 2400.0) - IntToFloat(timemins)) * 60.0;
int timesecs = FloatToInt(timesecsfl);


Or something like that.  I'm not sure when the decimal point gets truncated, so the first bit may work...otherwise replace the definition for timesecs with the above.

Edit:  Furthermore, this code requires AGS 2.7 or higher.  If you are using the beta for 2.71 you could make use of the new String type by doing the following in place of the old "string" type functions:

Code: ags
Labelname.Text = String.Format("%d minutes %d seconds remain", timemins, timesecs);

kec

I like meat.

SMF spam blocked by CleanTalk