Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

_SKOTTIE_

enemy shooting?

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

im scripting my enemy movements and attacks in my 2d top down shooter game. unforunately, i dont want to have to script every bullet. so each frame i want to test to see if the enemy shoots randomly.... but that means that the machines that get better frame rates will have more bullets...... how can i go about having random shooting with teh same frequency on all machines?

Share this post


Link to post
Share on other sites
Advertisement
Make your game logic independent of the frame rate (ie have the game logic run every x milliseconds, and draw frames whenever you have the time to). Then, the game steps will go at the same speed on all computers, and you can use them to randomly fire bullets.

ToohrVyk

Share this post


Link to post
Share on other sites
I am not sure, but you can use a sleep() statement on Windows and generate a random number to have them randomly shoot. Or, make it do the logic, sleep(10), and do the logic again.

Scott Simontis
e-mail:ageofscott@comcast.net
AIM:ssimontis

Share this post


Link to post
Share on other sites
sleep(10) is a bad solution, because everything is paused (so no frames are rendered : lowers the framerate), and the sleep duration is not controlled correctly (it may be 10 ms, or it may be more, depending on the system load and stability). Besides, 10ms can be ok if the logic AND frame are done in 15 ms (->25ms per step) but doesn''t work anymore if the rest gets executed in more (50 ms per step on slower machines) or faster (15ms on faster machines). sleep() should not be used where precise timing is required. In this case, it will only result in an overall slower speed, but the speed impact will be different on each and every configuration.

ToohrVyk

Share this post


Link to post
Share on other sites
Or, get the tick count from the processor, and check to see if it increased by x ammount of seconds, then do the rendering. It might be slow, but will probably work.

Scott Simontis
e-mail:ageofscott@comcast.net
AIM:ssimontis

Share this post


Link to post
Share on other sites
You should never, ever, ever do frame-rate-dependent applications. All of your movement should be based off delta time. Any logic you need done at specific intervals should have a "last time done" saved on an object. You should have it randomly shoot a bullet every x seconds, you say if(CurrentTime - LastTimeDone > WaitIntervalInSeconds * ValueOfSecondAccordingToTimer) { DoStuff(); }. It's not slow, either.

[edited by - Erzengeldeslichtes on September 21, 2003 9:59:54 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Erzengeldeslichtes
You should never, ever, ever do frame-rate-dependent applications. All of your movement should be based off delta time. Any logic you need done at specific intervals should have a "last time done" saved on an object. You should have it randomly shoot a bullet every x seconds, you say if(CurrentTime - LastTimeDone > WaitIntervalInSeconds * ValueOfSecondAccordingToTimer) { DoStuff(); }. It''s not slow, either.



Coupling the logic updates with the graphical frame updates is just fine for many 2D games and those that exist in a discrete world.

Share this post


Link to post
Share on other sites

  • 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!