GameDev : Speed Powerup [and how start to think in modular way in OOP (Part II)]

We have a switch statement, now we need the logic for Speed Powerup. Inside Player script, we have a Coroutine to manage Triple Shot mechanics.

Now we need a Coroutine to manage Speed Powerup.
What’s we want?
Let’s say the speed must be double the normal.

I create a speedMultiplier variable

I assigned the value to 2 so we can multiply it by our speed value.

Inside Player Class, we create SpeedBoostIsActive() to start a Coroutine

The Coroutine manage the cooldown of Speed Powerup

What happen here is simple this : we double the speed, wait for 5 seconds, then DIVIDE the speed (at this moment is 10) by speed multiplier, so it’s back to 5.

We try to make things as simple as possible.

After this, we simply call this method inside the Switch Statement

If we make a try

If we look at Player Inspector, our speed is now 10, and after 5 seconds it return to 5.
And again, everything works fine!

Always in love with programming, even if late (I'm already 39 years old) I decided to follow my dream! We will see how far my passion will take me!