Sign in to follow this  

Spawn delay between enemies

This topic is 2044 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]
[color=#000000][font=Arial,]Here is my code for loading a new wave:[/font][/color]
[CODE]
public void LoadWave()
{
if (spawn == true)
{
maxTanks += 2;
killsInWave += 2;
waveNum += 1;
tanks = new Tank[maxTanks];
for (int i = 0;
i < maxTanks;
i++)
{
tanks[i] = new Tank();
tanks[i].Initialize(map);
tanks[i].LoadContent(Content);
}
spawn = false;
}
}
[/CODE]
[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]
[color=#000000][font=Arial,]Thanks in advance![/font][/color] Edited by SuperBalloon

Share this post


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

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

Share this post


Link to post
Share on other sites

This topic is 2044 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this