I am making a tank game, and I am trying to implement a reload function. What I have now is this:
void Turret::shoot(double deltaTime)
if(timeSinceLastFired > cooldown && shotLimit > 0)
Shot* shot = new Shot();
shot->setPos(sprite.GetPos() + direction * bulletOffset);
timeSinceLastFired = 0;
reload = deltaTime + 2.0f;
void Turret::Update(double deltaTime)
timeSinceLastFired += deltaTime;
ShotList::iterator s = shots.begin();
if((*s)->GetAge() >= bulletTimeLimit)
s = shots.erase(s);
if(deltaTime > reload && shotLimit < 5)
shotLimit = 5;
Before, I had a logic check that allowed it to check if the list was under 5, and if it was, it would allow me to fire. This became a problem when I started colliding the bullets with other tanks and deleting them, it allowed me to rapid fire into the other tank. I redid the code like this, following this line of logic:
When a bullet is fired, 1 is subtracted from the bullet allowance and deltaTime + 2 is set as the value for reload. When the next bullet is going to be fired, check if the bullet allowance is greater than zero and if it is, fire. When deltaTime is greater than reload, set the bullet allowance back to 5, and allow firing again.
If I set a break point on the reload part of the code, it hits it after the elapsed time has passed, and if I hit continue, it will allow me to shoot again, so I really don't know what is going wrong here.
The problem is that my tank stops firing after 5 shots are fired, no matter how. I can post any more code that you would like to see, but I need some help fairly urgently.