Jump to content
  • Advertisement
Sign in to follow this  
twoaterisn

multiple enemies

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

hey, I've bee thinking for a while about how to handle a variable amount of objects (in my case enemies) in a game. I refuse to google it just to make sure I can find a solution by myself. so this is what I came up with: I make a class "enemy". In this class I put a pointer to an other enemy, lets call it enemy.pointer. So when I have to add an enemy, I use new and put it in the empty location my last enemy.pointer is pointing to. For removing an enemy: enemy1.pointer points to enemy2 and enemy2.pointer points to enemy3 to remove enemy2 i make enemy1.pointer point to enemy 3 and use delete on enemy 2. if (this==crap) {don't tell me a better way.} else {any further hints are welcome} thanks, TH

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by twoaterisn
hey,

I've bee thinking for a while about how to handle a variable amount of objects (in my case enemies) in a game. I refuse to google it just to make sure I can find a solution by myself.

so this is what I came up with:

I make a class "enemy". In this class I put a pointer to an other enemy, lets call it enemy.pointer.
So when I have to add an enemy, I use new and put it in the empty location my last enemy.pointer is pointing to.
For removing an enemy:
enemy1.pointer points to enemy2 and enemy2.pointer points to enemy3
to remove enemy2 i make enemy1.pointer point to enemy 3 and use delete on enemy 2.


if (this==crap)
{don't tell me a better way.}
else
{any further hints are welcome}
It's not crap :-) But depending on what language you're using, there are probably better ways. As you requested I won't be specific, but I will say that you're reinventing a wheel here (specifically a very common data structure). In general, implementing this particular structure from scratch can be somewhat error-prone, but it can be a good exercise as well.

Share this post


Link to post
Share on other sites
Quote:
Original post by twoaterisn
hey,

I've bee thinking for a while about how to handle a variable amount of objects (in my case enemies) in a game. I refuse to google it just to make sure I can find a solution by myself.

so this is what I came up with:

I make a class "enemy". In this class I put a pointer to an other enemy, lets call it enemy.pointer.
So when I have to add an enemy, I use new and put it in the empty location my last enemy.pointer is pointing to.
For removing an enemy:
enemy1.pointer points to enemy2 and enemy2.pointer points to enemy3
to remove enemy2 i make enemy1.pointer point to enemy 3 and use delete on enemy 2.


if (this==crap)
{don't tell me a better way.}
else
{any further hints are welcome}

thanks, TH

It's called a linked list if you want to research this further. It is also implemented in the STL as std::list if you are using C++.

Share this post


Link to post
Share on other sites
I'm using C++.

I'll give it another thought, but if i can't come up with anything better I'll use this and program it myself. Being a beginner I think I can use the practice :)

thanks for the advice guys...

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!