SPACE SHOOTER
UPGRADES
UPGRADES
Types of Upgrades
In the rubric you are required to have two active / functional upgrades. This means that they need to change the behavior of your player in a meaningful way. In short, they require code that extends beyond a simple addition or subtraction.
You are welcome and encouraged to have both in your project. Just make sure that at least two represent a functional change.
Passive (Numerical)
Regain Health
More Max Health
Extra Lives
Additional Damage
Longer Range
Faster Speed
Active (Functional)
Multishot
Shotgun
Missiles
Ally
Regenerating Shield
Speed Boost
Stacking Or Not?
For each upgrade, you should ask yourself - do all of these work together? Consider three examples:
Example #1 - No Overlap
Consider a game with upgrades for multishot, extra lives, more damage, and speed boost.
Two of these are passive, so they're easy.
The active skills use different keys: space to fire simply adds more shots. Pressing "e" activates the speed boost with a cooldown.
Since they use different keys, there is no conflict.
Example #2 - Choose Your Weapon
Consider a game with upgrades for multishot, shotgun, and laser.
All three skills are active, and in this game they all simply activate when pressing space. But each changes the way the player fires. They're all equally good choices, but they are designed to be mutually exclusive.
If this is your approach, you may need to have some way of changing the "active" weapon. A common solution is using the 1-3 hotkeys and letting the player swap weapons like they do in a standard shooter game.
Example #3 - Everything Stacks!
Consider a game with upgrades for multishot, shotgun, and laser.
This is the same as example #2, but we'll design the upgrades differently. Multishot simply adds two side shots to your basic bullets that fan out on the sides. Shotgun adds a small but infrequent burst of projectiles. Laser replaces the basic projectiles with a big beam, but does not affect the other upgrades.
In this case, a player can keep stacking all the upgrades because they are designed to work together. This is my recommended model, and the one I will use in the example below. It requires the least new code, and players love being able to get more powerful over time.
EXAMPLE: MULTISHOT
MAIN / PLAYER
Tracking Multishot
In main, we'll add a new variable to keep track of multishot. For now, let's make it active at the start of the program. We'll change that back later.
boolean hasMultishot = true;
Making The Player Shot Fire on Angles
Please see the tutorial in the More Enemies page on how to make a shot that fires at an angle.
I think the easiest way is to simply modify the PlayerShotBasic class. New code in green, changes in blue.
class PlayerShotBasic extends PlayerProjectile
{
PlayerShotBasic(float x, float y, float xSpeed, float ySpeed)
{
super(x, y, blueShot.width, blueShot.height, xSpeed, ySpeed);
image = blueShot;
damage = PLAYER_SHOT_DAMAGE;
}
}
Once you make this change, you'll have to add a few parameters for the basic bullets to make them fire straight up. In this case, the xSpeed is zero and the ySpeed is -8.
✓ Test your program - it should work exactly as it did before.
Adding More Bullets
In the player's act() method, we'll simply add more bullets sometimes. These bullets only appear if the player has the multishot upgrade.
void act()
{
/* other code */
if(getKey(' ') && shotTimer == 0)
{
/* original shots and timer code */
if(hasMultishot)
{
objects.add(new Playershot(x+0, y, -1.5, -8));
objects.add(new Playershot(x+24, y, 1.5, -8));
}
}
}
✓ Test your program - are you now firing 4 total shots? Are some at an angle? Before moving on, turn multishot off and make sure that it reverts back to normal behavior.
Buying Multishot
To purchase multishot, we use the same approach as we did for our extra life upgrade... with one small change. We need to make sure the user doesn't buy multishot twice, so we add a fourth requirement to our if statement.
void updatePause()
{
/* other code */
if(getKey('2') && credits >= 30 && pauseTimer == 0 && !hasMultishot)
{
credits = credits - 30;
pauseTimer = 15;
hasMultishot = true;
}
}
✓ Can the user purchase multishot? Is it possible to accidentally buy it more than once?
Going Gray
One final and optional step is to change the color of the text once the upgrade has been purchased. When drawing the text for the upgrade, set a different fill color based on whether the upgrade has already been purchased or not.