Sign in to follow this  
yurian

C++ and Allegro, monster waves

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
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())[i];
}
listWaves.pop_front();
}


Hope that helps!

Share this post


Link to post
Share on other sites

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