2D Certification: Powerup Collect

In the last article, I added the ability for the enemy to destroy powerups. Today, I’m going to be continuing the second, and final, phase of the GameDevHQ 2D Game Development Certification track. In this article, I’ll be adding a powerup collect feature! The requirement reads as follows:

Tasks: * When the ‘C’ key is pressed by the Player, Pickups quickly move to the player.

The first step in completing this requirement was to add a new key bind to the input controls. I added a new key bind to the Player Controls section of my key bindings and bound it to the ‘C’ key on the keyboard. Because I prefer to play with a controller I also bound the same action to the east most button on the game controller. With the key bind in place, I regenerated the action map to add the new key bind to the input actions interface. I then hopped over to the Player class and implemented the new OnPowerupCollect method that was generated on the input actions interface. In this method I set a boolean flag based on whether or not the button was pressed or released to control if powerup collection was active or not.

I then created a new method that checked for powerups on screen, and if there were any looped over them and moved the powerup towards the player.

With that in place I created the two methods needed on the powerup class to provide the movement for the objects when collection was active.

Finally, I play tested the functionality and submitted it into source control.

Next Time!

In this article, I added a powerup collect feature. Next time, I'll be adding an enemy type that can avoid player fire! If you enjoyed this article, or want to come along with me as I progress on my journey, follow me at gamedevchris.medium.com.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Christopher West

Christopher West

76 Followers

Unity Game Developer, Software Engineer, Gamer, Musician, and Father. Christopher is a creative that enjoys a challenge and loves coding.