The Path of the Game Dev — Day 8

Gabrielle Igarta
2 min readDec 2, 2020

--

Saving progress…

— —

A breakthrough!

Ever since starting Phase 1 of the 2D Game Development I felt a sense of dread as I was left to my own devices to implement the features this section required. But through persistence I have completed the basics — the sprites and behaviors are all done! I’ll share a few of them below:

Additional power ups and deteriorating shield

The two features I had yet to work on — the alternate firing mode and the thruster system — have proven to be the most difficult challenges yet. I focused today on building a thruster charge bar and the related code on the Player’s movement. Sounds simple enough, right? Not really.

This feature threw me for a loop for the longest time. It required the UI to communicate with the Player to get information about when the Left Shift key was pressed, thus activating the thrusters and increasing speed for the duration. The UI would then update a visual that represents the charge for the thruster’s speed boost in real time. To do this, I created a slider in the UI that would decrease in value at a constant rate when the Player was using thrust (holding down the Left Shift key) and recharge at a slower rate when the Player was not using it.

The last piece of this puzzle was to stop the increased speed from the thruster when the slider value was 0. Here’s the code for that:

void Update()
{
if (Input.GetKey(KeyCode.LeftShift))
{
if (curCharge <= minCharge)
{
return;
}

DepleteCharge(0.6f);
}

else
{
RestoreCharge(0.25f);
}
}

This demonstrates that if the Left Shift key is being held down, AND if the current charge of the thruster (or value of the slider) is greater than or equal to the minimum charge of zero, it will not decrease lower than that. I also have similar code in the Player’s movement method that returns the speed to normal when Left Shift is not held down.

Biggest takeaways from the day: Writing things out is extremely helpful when organizing your thoughts or planning out how you will code.

— —

Progress saved!

--

--

No responses yet