Jump to content
  • Advertisement
Sign in to follow this  
baddogj

Timing Enemy Creation

This topic is 5108 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 am creating a 2d side scroller game with blitzbasic. i got everything down but the timing. My current implementation creates a new enemy every frame. I tried to slow down the creation by using delay on the enemy creation, but all it did was delay the whole game. so what i am trying to ask is how do i slow down the enemy creation without slowing down the entire program?

Share this post


Link to post
Share on other sites
Advertisement
You'll need some kind of timer.

The most simple thing you could do is to store the number of the current/last frame in a variable. Also store when the last enemy was created in a variable. Decide on how often you want to add enemies and update the lastenemy variable when you add a new enemy.

Of course... you might want to use a real timer that actually measures time instead.

Share this post


Link to post
Share on other sites
what i was thinking of trying to do was create an actual timer. Then i would have a certain number. every time the number divided into the time with a remainder of 0 create an enemy.

Share this post


Link to post
Share on other sites
here's what i have come with:

timer= createtimer(100) ;100 is when to create a tick

...

create_enemy()
time= timerticks(timer) ;time equals total # of current ticks

if (timer modulus 3=0) then ;if = 0 crate an enemy.
{
enemy.enemy=new enemy
}

does anyone know of a better way of doing this?

Share this post


Link to post
Share on other sites
Leffe(or anyone else) could you elaborate on your idea of current and last frame. possibly post example code, thanks, in advance.

Share this post


Link to post
Share on other sites
Have two variables:

1) how often to create an enemy (in ticks)
2) how long since the previous enemy was created

Each physics step (tick), then do this:


curTick++;
if( curTick >= howOftenToCreateAnEnemy ) {
curTick -= howOftenToCreateAnEnemy;
CreateEnemy();
}


You can change the "++" to "+= elapsedTime" or whatever, depending on whether you use ticks or seconds for your measurements (if it's seconds, you probably want double rather than int for the counter, too :-)

Share this post


Link to post
Share on other sites
You could also just create a new enemy every 10th frame or so -- though that wouldn't be as accurate as a timer.

Share this post


Link to post
Share on other sites
Quote:
Original post by mumpo
You could also just create a new enemy every 10th frame or so -- though that wouldn't be as accurate as a timer.

yeah, i tried that. it worked fairly well, but the time would change constantly becase i use random enemies, and some of them are more detailed than others, so the time between creations would slow down and speed up constantly.

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!