Making A 2D Shooter — The Player Levels Up
How the player ship has changed
In the quest to take a 2D shmup from basic and functional to something more complex, many aspects of my game have been upgraded, changed, or added upon. In this article, we’ll be looking at changes to the player, both in terms of capabilities and controls.
As a starting point, the player has basic shmup capabilities. In their “ship” they can move in all directions on a 2D plane, and can fire a projectile straight forward. They also are capable of picking up various powerups that can enhance their capabilities in various ways. For example, one powerup is a shield for the ship that can absorb damage meant for the player.
Ammunition — Introducing Limits
Probably the biggest change for the player is the introduction of an ammunition count for the player’s primary weapon. Previously, the player could fire indiscriminately with no cost. Setting a maximum number of shots the player can fire before they become defenseless forces the player to play more carefully and strategically.
The player restores their ammo through a new powerup, and can check the number of shots they have left by checking a meter that has been added to the user interface. I’ll be covering both of these additions separately in future articles.
From a technical perspective, this was a fairly simple change to make. A new variable was added to the player to track the amount of ammunition they have at present. If that value is below one, the player cannot fire their weapon. Every shot they do make reduces the value of the variable by one. The only thing that restores it is the aforementioned powerup, which restores the value of the variable to the predetermined maximum value.
Thrusters — A New Renewable Resource
A completely new aspect to the game is the addition of “thrusters” to the player ship. Thrusters allow the player to get a quick burst of additional speed when its needed. Using the thrusters adds a new control for the player, as it is activated using the shift key.
Much like with ammunition, thrusters are a limited resource, meaning you can only use it for so long before it is used up. Unlike ammunition, thrusters restore on their own over time, without a powerup.
Within Unity, the thrusters were implemented in a similar fashion to the ammunition. A variable was created to represent the current value of the thrusters. As the shift key is held down, the ship’s speed is increased, but the value of the thruster variable drops. Once it reaches zero, the ship no longer moves faster. Then when the shift key is released, the variable increases again until it reaches a specified maximum value.
As stated earlier, the thrusters do not recharge from a powerup. Instead, the value either increases or decreases in the Update method depending on whether the shift key is being pressed or not.
A Change To Shields
Shields for the player were already in place as a potential powerup. When acquired, the player ship gets a new visual effect and the shield absorbs enemy damage. But as it stands initially, it is a boolean value — the player has a shield or they don’t.
This has been changed to give the shield a numerical value representing its strength level. Instead of only taking one shot before fading away, it can now take multiple, and it can also be restored by collecting another shield powerup.
A related change made to shields is that the visual representation on the player ship will now brighten or fade depending on whether the player is taking damage or restoring their shield.
Once again, this was implemented similarly to the player ammunition. What was once a boolean variable determining whether or not the player had a shield active is now an integer variable representing the shield’s current strength level. This comes into play when the player’s ship collides with an enemy or enemy fire.
Visually, the shield sprite is attached to the player ship, and the value of the alpha, or transparency, of the sprite is adjusted whenever there is a change to the shield’s strength value.
Powerup Attractor — Reeling Them In
Finally, another new control has been added to the player. Instead of being content to either intercept powerups or allow them to drop off the bottom of the screen, the player now has the option of drawing the powerups to their ship by pressing the ‘C’ key. This can add new dimensions of strategy in the game for the player.
This change basically allows the player to adjust the direction of the powerup when the key is pressed. Normally, powerups only travel to the bottom of the screen, but with this change they can instead move in the direction of the player while the key is down.
And that covers the changes to the player. Next time, we’ll go over the new enemies that have been added to the game. Thanks for reading.