Reputation: 1577
I'm making this game, and it involves enemies. it's pretty boring for them to stay the same speed so I want the enemy speed to increase as the player scores higher. It's difficult to make certain algorithms with love since mostly everything is updated every frame with this game engine. Which is what is actually giving me the problem right now.
The first part of my logic is correct (the part where the enemy.speed
increases after the player_score
passes 10) but once it passes (or reaches) 10, the enemy.speed
value will continue to increase by 10 every frame. Even with the enemiesReadyToSpeedUp
boolean that I put in place specifically for this reason! (to stop the enemy.speed
from rapidly increasing)
so once the player score exceeds 10 the game becomes unplayable since the enemy begins to move at the "speed of light."
function enemySpeedUp()
-- Once player score > scoreLimit + 10, enemy's speed will increase by 10,
-- and the scoreLimit will increase by 10
enemiesReadyToSpeedUp = false
scoreLimit = 0
if(player_score >= scoreLimit + 10) then
enemiesReadyToSpeedUp = true
end
if(enemiesReadyToSpeedUp == true)then
enemy.speed = enemy.speed + 10
scoreLimit = scoreLimit + 10
enemiesReadyToSpeedUp = false
end
end
Things I've Tried:
enemy.speed = enemy.speed + player_speed
but that was a pretty obvious mistake as enemy.speed
increased every frame and I got the same result as my first mistake.Upvotes: 0
Views: 272
Reputation: 5857
Your mistake is initializing scoreLimit
with 0
right within enemySpeedUp()
function.
Move that assignment out, do it at the same place where you set initial player_score
value.
Upvotes: 1