Timing Enemy Creation

Started by
11 comments, last by baddogj 19 years, 5 months ago
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?
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="88" height="70" id="H2lvl" align="middle"> <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="http://www.ironhive.com/CFCs/H2lvl.swf?gamertag=jBaddog" /> <param name="quality" value="high" /> <param name="wmode" value="transparent"> <embed src="http://www.ironhive.com/CFCs/H2lvl.swf?gamertag=jBaddog" quality="high" bgcolor="#ffffff" width="88" height="70" name="H2lvl" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object>
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.
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.
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="88" height="70" id="H2lvl" align="middle"> <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="http://www.ironhive.com/CFCs/H2lvl.swf?gamertag=jBaddog" /> <param name="quality" value="high" /> <param name="wmode" value="transparent"> <embed src="http://www.ironhive.com/CFCs/H2lvl.swf?gamertag=jBaddog" quality="high" bgcolor="#ffffff" width="88" height="70" name="H2lvl" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object>
That'd work too. If the timer doesn't skip any steps.
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?
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="88" height="70" id="H2lvl" align="middle"> <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="http://www.ironhive.com/CFCs/H2lvl.swf?gamertag=jBaddog" /> <param name="quality" value="high" /> <param name="wmode" value="transparent"> <embed src="http://www.ironhive.com/CFCs/H2lvl.swf?gamertag=jBaddog" quality="high" bgcolor="#ffffff" width="88" height="70" name="H2lvl" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object>
Leffe(or anyone else) could you elaborate on your idea of current and last frame. possibly post example code, thanks, in advance.
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="88" height="70" id="H2lvl" align="middle"> <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="http://www.ironhive.com/CFCs/H2lvl.swf?gamertag=jBaddog" /> <param name="quality" value="high" /> <param name="wmode" value="transparent"> <embed src="http://www.ironhive.com/CFCs/H2lvl.swf?gamertag=jBaddog" quality="high" bgcolor="#ffffff" width="88" height="70" name="H2lvl" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object>
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 :-)
enum Bool { True, False, FileNotFound };
thanks, that really helps. ill try doing that tonight.
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="88" height="70" id="H2lvl" align="middle"> <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="http://www.ironhive.com/CFCs/H2lvl.swf?gamertag=jBaddog" /> <param name="quality" value="high" /> <param name="wmode" value="transparent"> <embed src="http://www.ironhive.com/CFCs/H2lvl.swf?gamertag=jBaddog" quality="high" bgcolor="#ffffff" width="88" height="70" name="H2lvl" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object>
You could also just create a new enemy every 10th frame or so -- though that wouldn't be as accurate as a timer.
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.
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="88" height="70" id="H2lvl" align="middle"> <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="http://www.ironhive.com/CFCs/H2lvl.swf?gamertag=jBaddog" /> <param name="quality" value="high" /> <param name="wmode" value="transparent"> <embed src="http://www.ironhive.com/CFCs/H2lvl.swf?gamertag=jBaddog" quality="high" bgcolor="#ffffff" width="88" height="70" name="H2lvl" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object>

This topic is closed to new replies.

Advertisement