Hi everyone. So I'm working on a Tower Defense game. If you're not familiar with Tower Defense, all that is necessary for you to know for this post is that Enemies move through a path while the user constructs Towers that periodically shoot some kind of projectile that inflicts damage on the Enemy.
Here's my trouble. I'm trying to design my Bullet class and I can't quite decide what I should do. The designer tells me that he wants bullets from towers to "follow" an enemy until they collide. He also says that if a bullet is following an enemy and the enemy dies before the bullet reaches the enemy, then the bullet should just disappear.
So I'm trying to decide how I can accomplish this. The "following" mechanism isn't too bad... I just do something like
bullet.moveHoriz((target.x - bullet.x)*bullet.vel)
. At least something similar to that. The difficulty lies with how I should tell the bullet when its enemy has been defeated. I was thinking about having the Bullet store an Enemy pointer, but then how does the bullet know when there's no longer a proper Enemy to follow?
One possible solution I thought of was to have each Enemy have a std::vector of Bullet pointers which contains every bullet that is "following" the Enemy. Then, in the enemy destructor I could do something like
1 2
|
for (int i=0; i < followers.size(); i++)
followers[i]->die();
|
Does that seem like a valid solution?.. Or is there a better way you can think of?
Thanks.