Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Joe on Wed 13/09/2006 11:41:50

Title: TEMPLATE: CountDown
Post by: Joe on Wed 13/09/2006 11:41:50
Hello everyone.

With this template you can make a count down, it's not exactly like a timer, but similar:

Download CountDown template (http://www.fileupyours.com/files/59182/CountDown.rar) (Requires AGS v2.72 or later)

This template shows hours, minutes and seconds.
Title: Re: MODULE:CountDown
Post by: Pedro on Wed 13/09/2006 11:55:28
Oh this is what I was waiting for, thanks Joe
Title: Re: TEMPLATE:CountDown
Post by: Joe on Wed 13/09/2006 12:00:24
Thanks for appreciating my work  :)
Title: Re: TEMPLATE: CountDown
Post by: strazer on Wed 13/09/2006 18:40:22
(This is just a template, not a module.)

Joe, please always state which version of AGS is required to use your stuff (for templates, state the version you made it with).
Title: Re: TEMPLATE: CountDown
Post by: Joe on Wed 13/09/2006 19:08:52
Ok, thanks for your advice :)
Title: Re: TEMPLATE: CountDown
Post by: monkey0506 on Wed 13/09/2006 19:34:21
I think this would work better as a module...if you could work that out...but aside from that it seems okay.
Title: Re: TEMPLATE: CountDown
Post by: Joe on Wed 13/09/2006 19:37:28
I know it should be a module but if I load just the module, it wouldnt be enough because it need a GUI to show the countdown, but if there is a way to make it through an overlay, please tell me. :o
Title: Re: TEMPLATE: CountDown
Post by: monkey0506 on Wed 13/09/2006 20:55:21
You could do something like:

// module script
struct CountdownType {
  Overlay* o;
  int timer;
  int hours;
  int mins;
  int secs;
  import void SetTime(int hours, int mins, int secs);
  };

void CountdownType::SetTime(int hours, int mins, int secs) {
  if (hours < 0) hours = 0;
  if (mins < 0) mins = 0;
  if (mins >= 60) mins = 59;
  if (secs < 0) secs = 0;
  if (secs >= 60) secs = 59; // yeah...I'm feeling lazy....this could be handled better...
  this.hours = hours;
  this.mins = mins;
  this.secs = secs;
  }

CountdownType Countdown;

// rep_ex
if ((!Countdown.timer) && ((Countdown.secs) || (Countdown.mins) || (Countdown.hours))) {
  Countdown.secs--;
  if (Countdown.secs < 0) {
    Countdown.mins--;
    Countdown.secs = 59;
    }
  if (Countdown.mins < 0) {
    Countdown.hours--;
    Countdown.mins = 59;
    }
  Countdown.o = Overlay.CreateTextual(X, Y, WIDTH, FONT, COLOR, String.Format("%d:%d:%d", Countdown.hours, Countdown.mins, Countdown.secs));
  Countdown.timer = GetGameSpeed();
  }
else Countdown.timer--;


Of course none of that is tested...and I didn't actually look at your code to see what you'd already done either. But hopefully this should give you some ideas.