Galaxy Shooter — Limiting The Thrusters

Joshua Nielsen
5 min readAug 3, 2021

Greetings, and welcome to this special series of articles. In this series, the intention is to take a solid functional base game and add some extra features that (hopefully) make it just a little more special.

The base game we have here is called Galaxy Shooter. It’s a Galaga-style 2D shmup that I put together while going through the 2D Game Development course for GameDevHQ. It has a controllable player ship, enemies, powerups, sound effects, music, and more. It is, as stated above, a fully functional game that can already be played and enjoyed in its current state.

But let’s see what else we can make it do.

In a previous article, we had implemented “thrusters” that allow the player to move faster when used. But at present there is no reason not to use them constantly. In this article, we’re going to add a fuel/energy aspect to the thrusters. Using the thrusters will expend the energy and the energy will recharge when the thrusters are not being used.

In addition to that, we will add a UI element to show us the current status of our thruster energy. In another previous article, we had added a meter on the side to show the player’s current ammo level. We will add another meter to show the player’s thruster energy. Let’s get started!

Limiting the thrusters

The thrusters functionality is pretty simple at this point. Within the section of the script that handles player movement, there is a code block that checks if the shift key is being pressed. If it is, the speed variable is adjusted. Otherwise it isn’t. This is simple, but it works.

For the change, the first thing we’ll need is some script level variables to represent our current and maximum levels of energy, just as we had made for the ammo levels. These will be float type variables. Within the Start method, the current energy level variable should be set to the value of the maximum energy level.

Then within the thruster code block, the current level of energy should be trending towards zero as the thrusters are used and it should be returning to the max level when the thrusters are not being used. Also, instead of just checking to see if the shift key is being pressed, the script should also check if the current energy level is above zero.

If all of these changes are implemented, we should basically have what we’re looking for.

The thrusters are limited by the current energy level

You might notice that I have some arbitrary values driving the increase and decrease of the thruster energy level. Also, the maximum energy level is actually set to 6. These were values I came to after much trial and error trying to find the right “feel” for the thrusters. You may feel that different values are better for you. Feel free to play with those values on your own.

If we enter the game at this point and start using the thrusters, we should see that they become unavailable after a few seconds of continuous use. We should also see that they are usable again after allowing them to rest for a moment.

So the thrusters work how we want them to, but there’s no visual feedback for the player to get a sense of the status of their thrusters. That’s what we’re going to work on next.

Updating the UI

If you’ve read my previous article covering the addition of the ammo meter to the game, you pretty much know what we’re going to be doing here. Adding a second meter for the thruster energy is going to be nearly identical. In fact, we can even start by going into the Unity Editor and duplicating the ammo meter object of the UI.

After duplicating the ammo meter, we just need to do three things with our new thruster energy meter. First, rename the object from ammo meter to thruster meter (or whatever you feel is appropriate). Second, reposition the new meter as appropriate for the UI. And third, recolor the meter to make it visually distinct from the ammo meter.

Now that we have the meter object in place in Unity Editor, we can then dive into the script. Our work will need to be done in the script managing the game UI, and it will be very similar to what we did for the ammo.

First we’ll need a reference for the thruster meter image. Make this a serialized field so we can just drag and drop using the Unity Editor.

Once we have that reference, then we’re just going to make one short public method in this script. In that method, we’ll want two parameters representing our current and maximum energy levels. We use these two values to set the fill amount of the thruster energy meter.

Updating the thruster energy meter

Once this method is created, we just need to return to our player script and add a call to our new method to the code we wrote earlier.

Making the call to the UI

And finished! We now have a thruster with limited energy, and our UI shows us how much energy we have at any one time. Great!

The thruster energy meter in action

That completes our work with the ship thrusters. In the next article, we’re going to add a little additional feedback to the player by really making them notice when they get hit. Until then, good luck and happy coding!

--

--