enemy shooting?
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?
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
ToohrVyk
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
Scott Simontis
e-mail:ageofscott@comcast.net
AIM:ssimontis
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
ToohrVyk
What I do in my programs is to have a tick counter running the logic (firing, etc) independently of graphics, so the graphics rate will update as fast as possible on the computer, but the logic rate will update the same on any machine.
Resist everyone
I am your only friend. Click here for more information.
Resist everyone
I am your only friend. Click here for more information.
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
Scott Simontis
e-mail:ageofscott@comcast.net
AIM:ssimontis
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]
[edited by - Erzengeldeslichtes on September 21, 2003 9:59:54 PM]
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement