Jump to content
  • Advertisement
Sign in to follow this  
yurian

C++ and Allegro, monster waves

This topic is 3473 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've been wondering how to store information on monster waves. How do I say to send a wave of enemy ships firing in a set pattern at set times? Also could anyone show me to a great tutorial for platform jumping games?

Share this post


Link to post
Share on other sites
Advertisement
Going off your topic subject here, I'll head off in the direction of C++.
Since you aren't specifying an API or other resources, I'll be as clear as I can be.

You could use some STL containers such as lists or vectors. Vectors are more efficient in accessing their own data, but are not so much when adding/removing elements quickly and repeatedly. This is contrary to the std::list, which is great for moving/adding/removing elements but no so much in access.

I would make a std::list of std::vectors. (Maybe vise versa, but lists for real time access. I'm sure people have much better ideas, but I'd suggest being more specific in your question to get a better answer.)

I would push back monsters for a wave on a vector and when you are done with that vector you could push it back on the list. When you are ready for action in the game loop, you can loop through the list size and "release the hounds" one wave after another until the list is empty.

I'd suggest you at least go somewhere like Chad Vernon or DirectXTutorial.com. The latter is pretty beginner friendly for C++/DirectX users, but I'd recommend looking into the Game Institute most. Here

I cannot explain time intervals or how enemies should behave without going off on game loops and making this post book length, so it is up to you to research.
Let's try something like this. I'm tossing many habits into the wind here since I have little to go on.

Setup...

std::list< std::vector<CMonster*> > listWaves;
std::vector< CMonster* > vMonsters;
CMonster* pNewMonster = NULL;

for (int i = 0; i < nMonsters; i++)
{
CMonster* pNewMonster = new CMonster;
vMonsters.push_back( pNewMonster );
}

listWaves.push_back(vMonsters);


Manage...

// Since monsters may be instansised, use their pointers
// and save clean up for later.
std::list< std::vector<CMonster*> > tmp;

tmp = listWaves;

while (!tmp.empty())
{
SendWaveAfterPlayer( tmp.front() );
tmp.pop_front();
}


Cleanup... ( EDIT: This is bad code. It may try to free an already freed pointer. Hopefully the idea is still clear.)

while (!listWaves.empty())
{
for ( int i = 0; i < (listWaves.front()).size(); i++ )
{
delete (listWaves.front());
}
listWaves.pop_front();
}


Hope that helps!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!