Background Game Timer?

What method would I have to implement into my program if I want to make it so if my character casted a spell (this is a console text based RPG) and I wanted it so the character couldn't cast the spell again for 60 seconds but still do other actions? I also would need a visible timer that appears on screen that counts down in real time, without making user input impossible.
facebookisgayyy wrote:
this is a console text based RPG
No, it's not, because making a console game of any kind is a thousand times harder than just using something along the lines of SFML.

As for your question, you can use time(0) to get a time in seconds. You can store the start time and then use math to get how much time has passed since then and make it count down.

And as for your name, I don't really see how a website can be 'happy'.
Last edited on
Unless the game is moving in realtime (which I doubt), there isn't much point in a time-based cooldown. After all, if a person really wants to cast a spell again, all they'd have to do is wait for a minute and then it'll work.

If the game is turn based, it makes far more sense for the cooldown to also be turn based. IE, rather than make them wait 60 seconds, just make them wait 5 turns or whatever.

But yeah if you really want to go with a 60 second cooldown, LB's suggestion of using time() will work just fine. When the user tries to cast a spell, check time() and see if it has been 60 seconds since the last time they tried to cast one. If not, don't let them cast.
Topic archived. No new replies allowed.