I'm building a game where the player's character can attack bad guys and vice versa. I built this with the concept of an "attack cooldown" because I don't want units to be able to attack each other every single frame. I want there to be some delay between attacks. Here's roughly how it works:
if unit.ticksUntilAttack <= 0
unit.ticksUntilAttack = unit.attackCooldown
unit.ticksUntilAttack = unit.ticksUntilAttack - 1
I also have a page where I show the character's stats and list this as "Attack Cooldown". I was showing my friend and he said, "Why don't you rename that to 'Attack Speed'"? I explained that it's not really the speed at which you attack because "smaller is better". We both agreed that "attack speed" is a more standard way to show this concept and that I should change things the way he suggests.
The problem for me is that "attack cooldown" is a much more intuitive way for me to program the solution. I'm wondering if there's some "trick" to refactoring the current code I've got. I'm thinking something like this:
if unit.attackSpeedAccumulator >= SUM_NEEDED_TO_ATTACK //a constant that's the same for every unit
unit.attackSpeedAccumulator = 0
unit.attackSpeedAccumulator = unit.attackSpeedAccumulator + unit.attackSpeed
Is there a smarter way to do this?