Jump to content
  • Advertisement
Sign in to follow this  
SuperBalloon

Spawn delay between enemies

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

[color=#000000][font=Arial,]I am working on a tower defence game in XNA, and I have a class called Tank which creates an enemy that follows a route around a map that is found via A*. Right now, I can create multiple instances of Tank, but they all spawn at the same time. This means that they are in exactly the same place as they follow the route, making it appear like there is only one enemy.[/font]
[color=#000000][font=Arial,]Here is my code for loading a new wave:[/font]

public void LoadWave()
{
if (spawn == true)
{
maxTanks += 2;
killsInWave += 2;
waveNum += 1;
tanks = new Tank[maxTanks];
for (int i = 0;
i < maxTanks;
i++)
{
tanks = new Tank();
tanks.Initialize(map);
tanks.LoadContent(Content);
}
spawn = false;
}
}

[color=#000000][font=Arial,]Could anyone give me a little help making each enemy spawn with a delay between it and the last one?[/font]
[color=#000000][font=Arial,]Thanks in advance![/font] Edited by SuperBalloon

Share this post


Link to post
Share on other sites
Advertisement
Create a elapsedTime variable and only spawn a new tank when the elapsedTime >= delay.

int i = 0;
float elapsedTime = 0.0f;
while( i < maxTanks)
{
if(elapsedTime >= delay)
{
tanks = new Tanks();
tanks.Initialize(map);
tanks.LoadContent(Content);
i++;
elapsedTime = 0.0f;
} else
elapsedTime += gametime.Elapsed.TotalSeconds;
}
}
Edited by TiagoCosta

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!