Switch Statements to the Rescue

Rob George
2 min readApr 14, 2021

--

Day 17 — Aspiring Game Creator

2D Game Dev: Galaxy Shooter

Shields are great, but there is a cost!

Objective: Implement The Shield Power-Up & convert ActivatePowerUp IF-THENs to Switch

Pseudo Code:

  • Create Shield Power-Up
  • Create Shield Game Object which encases Player Ship
  • Damage/Hits
  • Shrink Shield per hit
  • When Shields are activate Power-Up can not be picked up

Making the necessary conversation from IF-THENs to SWITCH is extremely easy and looks so much neater!

Initially, implementing the Shield power-up was similar to the Triple Shot & Speed Boost power-ups, and similarly, the meat of the power-up is where the code is dramatically different.

The Shield in Galaxy Shooter is an obviously PLUS!, no enemy is getting through it!— even when enemies have the ability to shoot, the Shield will remain powerful.

Unfortunately, nothing will get through it either. Power-ups and eventually other space collectibles — as I write this I’m still deciding whether the Shield can be powered down and maybe powered back up at a cost … something to think about.

Implementing the animation for the shield was similar to animating the power-up.

This particular shield wanted a bit more zing so just a quick visit to the animator and tweaked color, alpha and scale.

Currently, the shield can with stand three direct hits from an enemy ship. Each hit reduces the shield a third.

I loved the idea of enemies colliding, being zapped and destroyed so that simply fed the same idea for power-ups and again, there’s a cost to The Shield!

The cost of The Shield Power-up!

--

--

Rob George
Rob George

No responses yet