Creating a Unique Powerup that Helps and Hurts the Player

Blake Zoeckler
4 min readJun 4, 2021

--

Objective: Create a powerup that negatively affects the player.

Today we’ll be adding yet another new powerup to Galaxy Shooter. However, there’s a twist with this one. Not only will it help the player, but also temporarily hurt them as well, by disallowing them from firing for a few seconds!

New sprite for the Upgrade powerup

Here’s how this “Upgrade” powerup is planned to work:

  • When the player collects the powerup, he is unable to fire lasers for a few seconds, because the laser weapon is busy upgrading itself.
  • The ammo display in the top left will change to a progress gauge that displays “Upgrading…”
  • When the progress bar is full, the player’s ammo will return, they can fire lasers again, and the player will have more maximum ammo and a faster fire rate!

When the Player collides with the powerup, UpgradeWeapon is called, which in turn calls the UpgradeRoutine coroutine. First, this will set a boolean variable _isUpgradingWeapon to true, which will prevent the player from firing or using another Upgrade powerup. Then, over the next few seconds, we just call the UI Manager every frame to update the progress gauge that is displayed on screen. Finally, when the enough time has elapsed, we allow the player to fire again, and give them bonuses to ammo and attack speed.

We’ll have to adjust the player’s laser firing ability to account for this. First, in update, the player is no longer allowed to fire lasers if their weapon is upgrading.

Player.Update edits

Then, when they do fire a laser, the cooldown time is divided by their attack speed. By default, this attack speed is 1, so we just use the base fire rate. However, as the player accrues upgrades, the attack speed will increase more and more, which makes the laser’s cooldown time smaller and smaller.

Player.FireLaser edit

Here’s the difference that the attack speed makes when firing lasers:

Now for the progress bar, I decided to try a slightly different approach to what we did for the thruster heat gauge. Once again we start with a slider and remove the handle, but this time the Background is a transparent image with a mask component attached.

Without the mask, the fill would create a solid blue rectangle that covers the background, but with the mask, the fill color only affects the area covered by that background image. We just need to make the Fill Area and Fill as children as the background.

Now the code for the UIManager is simple. Just activate the gauge, change the text to “Upgrading…” and set the value of the gauge to the progress toward upgrade completion.

New public method in UIManager

When the upgrade is complete, the player’s ammo count is updated to max, so we can use that to turn off the progress gauge and set the text back to displaying how much ammo is available.

UIManager.UpdateAmmoCount edit

All done! Now we have a risky but powerful tool available to the player.

--

--

Blake Zoeckler
Blake Zoeckler

Written by Blake Zoeckler

I’m a passionate and talented software engineer seeking an opportunity in game development.

No responses yet