Sign in to follow this  

Another beginner topic about game

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

Hello, everyone.

I'm quite new in game development. But trying to learn it [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
Now i'm trying to create tower defense game for studies project. Using java with swing and awt. No addition libs for now. Created everything: towers (buy/upgrade/shooting and so on), minions (walking/killing/scoring and so on), tilebased map and all other needed parts.

But now have one issue: can't make normal waves and rounds. Or better to say: can't make good algorithm for these parts.
Was thinking this way: rounds object holding arrayList this different enemies. Every array member would represent different round (every round is different wave, and every wave is made from x size minnions arrayList). And from there i can't move any more. What could be rounds states (start/waiting/end and etc). How give information about this round minion info to wave? how start wave? how end it? how change rounds?

or basically what i'm asking is - what can be rounds states and how go from one to another by tracking information it that round(wave)?



P.s.Sorry for bad english, not my default language [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Share this post


Link to post
Share on other sites
What I did on one of my very first projects was to make a wavemanager. What I basically did was make a class that consisted all the information I needed about a wave, like how many enemies are alive or what number of wave this was.

The class basically had 2 functions I used:

A spawnwave function which just added 10 new enemies (hardcoded, but you can play with it obviously). In my case I called this function when all 10 enemies were dead or off the screen.

I also had a tick function which only handles the enemy logic.

The wavemanager was an object of a level object, so I could just call that function whenever a wave was done. You can use whatever rule you want to spawn a new wave of enemies and even keep track of how many waves have already been so you can stop spawning waves at a certain point.

I could post the source, but it's in C++, let me know if you want to see it anyway and I'll try to refactor it, it was one of my first projects and it's ugly :P

Share this post


Link to post
Share on other sites
It's not much of an algorithm really, but here goes! (Note that this is old and in my opinion ugly!)

Wavemanager.cpp
[code]void WaveManager::SpawnWave()
{
MobsWaveAlive = 10;
Waves++;
for(i = 0; i < 10; i++)
{
MobsWave[i] = new Enemy();
MobsWave[i]->currentEnemyType = Enemy::EnemyType::RANGED;
MobsWave[i]->init();
VecEnemyPosWave[i] = MobsWave[i]->getEnemyPos();
VecEnemyPosWave[i].x = SCRWIDTH + VecEnemyPosWave[i].x - (i * 48) ;
MobsWave[i]->setEnemyPos(VecEnemyPosWave[i]);
VelocityX = 1.0f;
VelocityY = 0;
MobsWave[i]->SetMobVx(VelocityX);
if ( Waves % 2)
{
MobsWave[i] = new Enemy();
MobsWave[i]->currentEnemyType = Enemy::EnemyType::MELEE;
MobsWave[i]->init();
VecEnemyPosWave[i] = MobsWave[i]->getEnemyPos();
VecEnemyPosWave[i].x = SCRWIDTH + VecEnemyPosWave[i].x - (i * 48) ;
MobsWave[i]->setEnemyPos(VecEnemyPosWave[i]);
VelocityX = 1.0f;
VelocityY = 0;
MobsWave[i]->SetMobVx(VelocityX);
}


}
}[/code]

Everytime I call the spawnwave function. I increment wave by 1 to keep track of how many waves.
I set the amount of enemies that are alive to 10. I had a fixed number of enemies, but you can diverse that with some tuning.

[code]void WaveManager::Tick(Surface* m_screen, float a_DT)
{
for(int i = 0; i < 10; i++)
{
if(MobsWave[i] != NULL)
{
MobsWave[i]->tick(m_screen, a_DT);
MobsWave[i]->doLogic(a_DT);
}
}
}[/code]

For every enemy (the fixed 10) I just update their whatever logic they have, all handled in the enemy class itself.

level.cpp
[code] if (!isEnd)
{
if (wavemanager->Waves == 2)
powerup->tick(m_Screen, a_DT);
wavemanager->Tick(m_Screen, a_DT);
for (int i = 0; i < 10; i ++)
{
Enemy* enemy;
Spell* spell;
Spell* enemyspell;
for (int j = 0; j < 1; j++)
{
if (wavemanager->MobsWave[i] != NULL)
{
enemyspell = wavemanager->MobsWave[i]->m_spell[j]->getSpell();
if (collision->Intersect(enemyspell, player))
{
player->setIsAlive(false);
wavemanager->MobsWave[i]->m_spell[j]->setIsAlive(false);
}
}
}
if (wavemanager->MobsWave[i] != NULL)
{
spell = player->m_spell[i]->getSpell();
enemy = wavemanager->MobsWave[i]->GetEnemy();
if (collision->Intersect(powerup, player))
{
player->m_spell[i]->CurrentPower = Spell::Type::UPGRADE;
powerup->setIsAlive(false);
}
if (collision->Intersect(enemy, player))
{
player->setIsAlive(false);
}
if (player->m_spell[i]->getIsAlive())
{
if (collision->Intersect(enemy, spell))
{
player->m_spell[i]->setIsAlive(false);
wavemanager->MobsWave[i]->removeEnemyHealth(player->m_spell[i]->getSpellDamage());
if (wavemanager->MobsWave[i]->getEnemyHealth() <= 0)
{
wavemanager->MobsWave[i]->setIsAlive(false);
SAFE_DELETE(wavemanager->MobsWave[i]);
int nummobs = GAME->getLevel()->getWaveManager()->GetMobsAlive() -1;
GAME->getLevel()->getWaveManager()->SetMobsAlive(nummobs);
if (nummobs <= 0)
{
GAME->getLevel()->getWaveManager()->SpawnWave();
}
}
//SAFE_DELETE(player->m_spell[i]);
}
}
}
}
}[/code]

I created the wavemanager in my level class, I only had one level so it didn't matter in my case. In this part I handled the collision testing with the player and the enemy and their spells. If an enemy got killed, I decremented the counter in my wavemanager and if that reached zero, I spawned another wave.

Now with the keeping track of how many waves have spawned you can decide to use that as a factor of spawning a new wave, of you could use a certain amount of time between each wave. Because I used a fixed amount for every wave and I only spawned a new wave when all the enemies were dead, you will most likely need to refactor this to suite your need more, but the general idea behind this should be clear [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Share this post


Link to post
Share on other sites

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