Jump to content
  • Advertisement
Sign in to follow this  
Zmurf

Timing?

This topic is 4824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm making a Bomberan clone in C++/OpenGL. So far so good. But now when my bomberman drops a bomb i want to make a timer function to make the bomb go off after a specified time, i've looked into using <time.h> but I can't figure out how to use it. Any help?

Share this post


Link to post
Share on other sites
Advertisement
I don't want to sound unhelpful but this topic has been done to death on these forums a quick search of timer will give you everything from ready made timer classes to countless forum questions on how to implement every different type avaliable to you.

heres a very simple example for you

DWORD Timer; // Global, class member or what ever

When you drop a bomb use: Timer = GetTickCount();

Then to find out how much time has passed

Time = GetTickCount() - Timer;

Will place the time in milliseconds into variable time. Its not great or even accurate but is a quick dirty way to do it. Use the search to find something a bit better.

Share this post


Link to post
Share on other sites
Best option is to make the bomb update itself every so often (every frame/ every second, however you feel most suitable for the precision you require.)

Your bomb has an update function;
Your bomb knows the time when it was dropped
Your bomb has a delay
Your bomb knows or can poll the current time


Class Bomb
{
public:
void DropBomb();
void Update();
void Detonate();

private:
Time m_DroppedTime;
float m_Delay;

};

// drop the bomb
void Bomb::DropBomb(float delay)
{
m_DroppedTime = Time::GetCurrentTime();
m_Delay = delay;
}

// update the bomb every n frames
void Bomb::Update()
{
if (Time::GetCurrentTime() - m_DroppedTime > m_Delay)
Detonate();
}

void Bomb::Detonate()
{
// do some funky stuff here
}





Share this post


Link to post
Share on other sites
If your trying to use the old c header for timing, take a look at this site, it might help you for your timer

http://www.cplusplus.com/ref/ctime/clock.html

Hope this helps you!

Share this post


Link to post
Share on other sites
Here is a timer class I made...


class CTimer {
int counter;
public:
CTimer(): counter(0) {}
bool Timer(int ms)
{
int tick_count = (int)GetTickCount();
if((tick_count - counter) > ms)
{
counter = tick_count;
return true;
}

return false;
}
};


Share this post


Link to post
Share on other sites
Why aren't you thinkin' of using a counter variables (I often name it as 'unsigned char m_ucPowerLevel') to make the bomb explode when its power level reaches the limit ?
This way is very fast 'cause your object doesn't have to call GetTickCount () or somethin' like that ev'ry frame. And... It is totally accurate, think of your player has a low-speed computer. If you use any of timing function, he/she will notice that the bomb explode slower/faster.
I always use this way because it make the object more real (your bomb need time to burn itself, but time in such computer game varies between computers).
Isn't that right ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Skeleton_V@T
Why aren't you thinkin' of using a counter variables (I often name it as 'unsigned char m_ucPowerLevel') to make the bomb explode when its power level reaches the limit ?
This way is very fast 'cause your object doesn't have to call GetTickCount () or somethin' like that ev'ry frame. And... It is totally accurate, think of your player has a low-speed computer. If you use any of timing function, he/she will notice that the bomb explode slower/faster.
I always use this way because it make the object more real (your bomb need time to burn itself, but time in such computer game varies between computers).
Isn't that right ?


If you update the counter function every frame then it becomes dependant on computer speed. Using the timer functions (like GetTickCount()) will be independant of computer speed since it's based on the elapsed time. GetTickCount is fairly accurate to several ms if I'm not wrong so it should be sufficient for the OPs task.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!