Countdown clock

Started by aussie, Sat 02/10/2004 12:45:22

Previous topic - Next topic

aussie

I'd like my game to take place in ten minutes. If the player can't finish it within that period of time, the game ends and he loses.

For that, I'd like to have a countdown clock in the upper right corner of the screen, so the player knows eactly how long there's left.

I know clocks have been spoken of before, but I'm not sure if this has been done. Ideas?

It's not the size of the dog in the fight. It's the size of the fight in the dog.

http://www.freewebs.com/aussiesoft/

strazer

Try this:

Code: ags
// main global script

int gameloops=0;

function repeatedly_execute() {
//...

gameloops++;
int mins = ((gameloops / GetGameSpeed()) / 60) % 60;
if (mins == 10) {
 Display("You lose!");
 RestartGame();
}

//...
}

aussie_unplugged

Thanks strazer, that works pretty well. I thinks I can get the second working from there.

BTW, how could I get the clock permanently on the screen?

strazer

#3
Hm, that's actually not the countdown clock you were asking for...

Then how about this:

Code: ags
// main global script

int countdown=-1; // countdown initally off


function repeatedly_execute_always() {
// runs even when game is blocked

//...

if (countdown > -1) countdown--; // if countdown enabled, decrease it
int mins = ((countdown / GetGameSpeed()) / 60) % 60;
int secs = (countdown / GetGameSpeed()) % 60;
string buffer;
StrFormat(buffer, "%02d:%02d", mins, secs);
SetLabelText(YOURGUIHERE, YOURLABELNUMBERHERE, buffer);

//...
}


function repeatedly_execute() {
//...

if (countdown == 0) { // countdown expired
Display("You lose!"); // not allowed in rep_ex_always
RestartGame();
}

//...
}


export countdown;


// room script file

import int countdown;


function room_a() {
  // script for room: First time player enters screen
//...

  countdown = (10*60) * GetGameSpeed(); // start countdown (ten minutes)

//...
}

aussie_unplugged

YOU GURU!!!  ;D

That works perfect.

One last question:

What if I want to start the clock right after the intro (as it is, the coundown would be starting as the intro begins, right?);

If that works I'm gonna have to put your name in the credits in big flashy golden characters!!!

strazer

#5
QuoteWhat if I want to start the clock right after the intro (as it is, the coundown would be starting as the intro begins, right?)

True.
I've finally put the code into a testgame and updated my post above. Should work now.
Move
  countdown = (10*60) * GetGameSpeed(); // start countdown (ten minutes)
to the "Player enters screen (after fadein)" script of the room that follows the intro.

QuoteIf that works I'm gonna have to put your name in the credits in big flashy golden characters!!!

Hehe, you don't have to do that. I'm just glad I could help. :)

aussie_unplugged

Quote from: strazer on Sat 02/10/2004 17:29:36
QuoteWhat if I want to start the clock right after the intro (as it is, the coundown would be starting as the intro begins, right?)

True.
I've finally put the code into a testgame and updated my post above. Should work now.
Move
Ã,  countdown = (10*60) * GetGameSpeed(); // start countdown (ten minutes)
to the "Player enters screen (after fadein)" script of the room that follows the intro.

QuoteIf that works I'm gonna have to put your name in the credits in big flashy golden characters!!!

Hehe, you don't have to do that. I'm just glad I could help. :)


Nah, that didn't quite do the trick...

1. I get a message saying "undefined token: countdown". I think it's because the room scripts are not in the global script (only characters and dialogs are, I think).

2. Still, if I put it under "Player enters screen (after fadein)", the clock should start every time I get into the screen, shouldn't it? I would probably have to be in "First time player enters screen", if anything.


strazer

1. Hence the "export" and "import" lines above.

2. You're right!

aussie_unplugged

Oh, of course... the old import and export statements!  :-\

How could I forget...

You're a champ straz. It works perfect now.


strazer

It recently dawned on me that there could be a problem:

Repeatedly_Execute_Always runs even when the game is blocked, Repeatedly_Execute does not.
Therefore, Rep_Ex won't notice the expiration (countdown == 0) when the countdown expires during a blocking scene since Rep_Ex_Always decreases it until it's -1.

So you might have to use another variable after all (iscountdownexpired or something), use Timers or put everything in Rep_Ex.

I don't want to edit the code again, so keep this in mind and change it yourself.

aussie

In any case, I have noted that the clock does stop when a message pops up, for example. Not that it bothers me. In fat, it works quite well and I'm a fair way along the game now.

I'll just try to put everything in Rep_Ex_Always, see how it goes.
It's not the size of the dog in the fight. It's the size of the fight in the dog.

http://www.freewebs.com/aussiesoft/

aussie_unplugged

It's fixed and it works now. Only that the game waits for the blocking action to finish in order to trigger the required event.

But that's ok.

SMF spam blocked by CleanTalk