'How to increase my enemy's health every time player gets an increment of 50 score?

To increase difficulty of my game over time, I am thinking of increasing enemy's health everytime player's score gets an increment of 50. Each enemy kill gives 10 points to the player.

Now I don't understand why I am having trouble with this as it can't be that complicated.

This is how I am trying to make it work but creating a new instance of enemy resets the health back to original (100). How can I get around it so that new updated health gets applied to all new instances of enemies after every 50 score increment?

Code snippet:

struct Enemy
{
    Float2 mPos         = Float2(0.0f, 0.0f);
    Float2 mVelocity    = Float2(0.0f, 0.0f);
    Float2 Knockback    = Float2(0.0f, 0.0f);

    float mHealth       = 0.0f;
    float mLastHit      = 0.0f;
};

// How often enemies spawn
gameState->mEnemySpawnCounter = 5.0f;

Enemy* enemy = new Enemy();
gameState->mEnemies.push_back(enemy);

// This is likely the issue as after a new enemy spawns, health gets reset to 100. How can I get around it?
enemy->mHealth = 100.0f;

// Enemies health increases specifically on multiples of 50 score and then gets reset back to 100 (If the score becomes 60 for example)
if (gameState->mPlayerScore % 50 == 0 && gameState->mPlayerScore > 0)
{
    enemy->mHealth += 20.0f;
}

I guess I need another variable to keep track of enemy health? Any help on this will be much appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source