• Advertisement
Sign in to follow this  

Timers and enemy spawning

This topic is 4741 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 have a question that's not really specific to any API or platform, just...game development. I'm making a Space Invaders type thing, and I've got different types of enemies (they move at different speeds, have corresponding point values, and so on). My question is, how can I decently handle the spawning of these enemies? Right now I have two enemies and two timers, one for each type of enemy. I'm sure there is some smarter way of doing this. Here's a bit of the code I have:
       enemy[0].alive = true;
       enemy[0].x = -enemy[0].width;
       enemy[0].y = 15;
       timer1 = 0; 
       enemy[1].alive = true;
       enemy[1].x = -enemy[1].width;
       enemy[1].y = 10;
    timer1 += DELAY;
    timer2 += DELAY; 

So it spawns an enemy[0] every 4 seconds and an enemy[1] every 6 seconds. But is there a less clunky way of doing this than what I've got here? (The DELAY is rest(20) if that matters) What do people normally do for this type of stuff?

Share this post

Link to post
Share on other sites
This is certainly not perfect, or perhaps even good, but I don't need timers much and it works:

in main game loop

if (r>33){
if (focused){
for (v=timers;v;v=v->next){
timetmp=(long *)v->data;

in secondary file

class ro_counter{
ro_counter(long inc=0){counter=inc;(new vine(TIMER,&counter))->top(&timers);}
long counter;
virtual ~ro_counter(){

Pardon my use of personal lists [and globals!] but the essense holds. Any class that needs a counter, simply inherits from the ro_counter class. The main game loop then updates the counters all together. The classes themselves can then do whatever they'd like with the counter in their own code [usually in ->update() or ->render()]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement