Galaxy Shooter Frame Work Series / Negative Power Up.

Jonathan Fagan
3 min readMar 21, 2023

--

Objective: Creating a negative power up. Houston we have a problem.

Looking at all of our power ups, we have something to give the player POWER but how about we cause a little havoc? How about we create a negative power up.

First we have to think about what our power ups do. They give us a triple shot. Speed boost. Shields. We even have player specific abilities, like thrusters and a special beam. That’s cool huh? Yeah.. let’s take it all away for a period of time. Oh and while we’re at it, let’s flip the movement controls to.

To accomplish this let’s break everything down bit by bit and strip things away one at a time. First we’ll create a bool called _poweredDown. Like the name suggest we will power down our player.

Let’s start by sealing off our LaserBeam and Thrusters so we can’t use neither one while _poweredDown is true.

if (Input.GetKeyDown(KeyCode.X) && _specialMeter == 100 && !_poweredDown)
{
_specialMeter = 0;
_isBeamActive = true;
}
 void Thrusters()
{
if (_poweredDown) return;

switch (_boosting)
{
case false:
if ((_thrusterAmount < _maxThrusterAmount) && Time.time > _canRecharge)
{
_canRecharge = Time.time + _thrusterRechargeRate;
_thrusterAmount += _thrusterRechargeAmount;
_uiManager.UpdateThrusterBar(_thrusterAmount / _maxThrusterAmount);
}
break;

case true:
_thrusterAmount -= _thrusterDecayRate * Time.deltaTime;
_uiManager.UpdateThrusterBar(_thrusterAmount / _maxThrusterAmount);
if (_afterImageCounter <= 0)
{
AfterImageEffect();
}

break;
}
}

With our code amended like this, now we can’t use our special abilities at all. Now let’s move on to creating more havoc for the player by flipping the controls. In our CalculateMovement method lets flip the controls when we are powered down.

 void CalculateMovement()
{
if (_poweredDown)
{
_movement.x = -Input.GetAxisRaw("Horizontal");
_movement.y = -Input.GetAxisRaw("Vertical");
}
else
{
_movement.x = Input.GetAxisRaw("Horizontal");
_movement.y = Input.GetAxisRaw("Vertical");
}

transform.Translate(_movement * _speed * Time.deltaTime);
}

Okay so yeah now we are getting somewhere. Left is now equal to right and right is now equal to left. Up is down and down is up. Good luck fighting with flipped controls.

We also need to also make sure that what ever active abilities we have now are false, and we stop all the coroutines associated with them.

 if (_poweredDown)
{
_speed = _speedDefault;
_tripleShotActive = false;
_speedBoostActive = false;
StopCoroutine("PowerUpTime");
StopCoroutine("SpeedCoolDown");
}

Last we need to set these the variable initial state for when we collect the debuff. And return to normal after the debuff period ends.

 public void PoweredDown()
{
_poweredDown = true; //set poweredDown to true
_shieldHp = -1; //set _shieldHp to -1 so we can see a bad shield
Shields(); //call the Shields Function to update the Shield
StartCoroutine(NegativeCoolDown(_powerUpTime));//start the debuff period
}
 IEnumerator PoweredDown(float time)
{
yield return new WaitForSeconds(time);
_poweredDown = false;
_shieldHp = 0;
_shieldVisualizer.SetActive(false);
}

Let’s also give a visual que about when they collected a power up. So in the Shields function lets add a new color for when the hp is -1.

switch (_shieldHp)
{
case 3:
_shieldSprite.color = Color.white;
break;
case 2:
_shieldSprite.color = Color.magenta;
break;
case 1:
_shieldSprite.color = Color.red;
break;
default:
_shieldSprite.color = Color.yellow;
break;
}

Now with all the heavy lifting done. This is how everything turned out.

--

--