Jump to content
  • Advertisement
Sign in to follow this  
Iwek

Help with shooting delay

This topic is 3918 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

long start = GetTickCount(); long edelay = 5000; if (start == edelay){ for (int i = 0; i <= ENEMY_COUNT; i ++){ enbullet.y = enemyArray.y + 43; enbullet.x = enemyArray.x + 39; enbullet.y -= enemyArray.movey; } edelay = start + 5000; } I am trying to set this up so that the bullets are brought onscreen every 5 seconds and then moved down the screen. Unfortunetly, nothing happens at all. The bullets are never brought on screen. This code is just a small part of the game loop. Any help is appreciated, thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
You'll want to check if start >= edelay, not just equal to. That is assuming that this is ran every frame. Since one frame doesn't last exactly one millisecond (probably lasts longer), it can skip over any integer easily enough.

And when you do this, you should also simply increment edelay by 5000, rather than setting it to start + 5000. This is because, over time, if each time you shoot you're actually at, say, 5010 ms, the gun shots will get off from the original amount. Not a big deal, but it could cause patterns to go wacky after a while.

Share this post


Link to post
Share on other sites
You might want to take a closer look at the logic.
My guess is that your program never enter the 'if' since GetTickCount returns a number much bigger than 5000.
Ezbez reply got the hints you need.
Here is one way to do it

// GetTickCount returns elapsed milliseconds since system start
long last = GetTickCount();

while(!done) // simulation loop, running until 'done' is true
{
// enter this if 5000 or more milliseconds has passed since last time
if(last + 5000 <= GetTickCount())
{
<update stuff>
last = GetTickCount(); // update last frame counter
}
}






[Edited by - pulpfist on September 30, 2007 7:21:30 AM]

Share this post


Link to post
Share on other sites
yer you really need to re-visit how GetTickCount() works, but you have it working now so I guess you have already :)

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!