Daily progress: Day 2, Extra Life.

With GameDevHQ, we have been set a task to make this 2D space shooter. At this point in the journey, we have to research how to do a list of tasks to add to this game.

Extra Life Pickup:

This one I think I made things a bit harder on myself, not on purpose though. Since I already had a Damage method for the character using a switch statement, I was thinking I could just use that again. In the end, it works, and there haven’t been any problems so far.

Way back when I added in the visual damage to the player, I had changed how lives were done from if and else if statements to a switch. This ended up making things a bit easier, that part of the damage method didn’t need changing anymore.

Starting with a Public method that would be called for the player when we get the pick up was the starting point.

Why it has the bool there will make sense soon.

By limiting it to when lives are under 3, makes it so it doesn’t get a null reference when lives are 4 and it’s trying to look for a 4th element in the sprites for lives.

Now the fun part…. Adding to the Damage method to be able to use it for both damage and health. By putting a bool Damage in the brackets for the method, this will give the option to limit all of the damaging parts within an if statement and keeping the rest separate. Since we still want to update the lives and the sprites we won’t want to use an else though.

Since the If statement finishes just after the “_lives — ;” we can now use this damage method as a healing method too. First, we will have to fix the methods that just got broken though.

You can click on them to bring you to the line that broke.

After adding True to the damaging methods and False to the Healing methods, remembering to jump over to the enemy’s script to fix that one too. Lastly, jump over to the Powerup Script and add in the new case for the extra life and link it to the extra life method we made. With that, the scripting side of things is done.

Now to set up the Visual side of things. Create an empty and add on the usual, 2D Rigidbody (Set Gravity Scale to 0), 2D Box Collider (Set is Trigger), Powerup script (Set ID and put in the Sound clip), and Sprite Renderer. With the Sprite Renderer, we can use the sprite for the UI’s life. Cutting down to 1 from any of the sprites (apart from the 0 lives one) will give you a useable Sprite for the Renderer.

Lastly, turn it into a prefab and put it into the Spawn Manager. Which you might have already seen in the last article.

Here it is again for those that missed it!
Looking good and working as intended!

And with that, another feature is added. Next time I will be adding a Screen Shake Effect when the player takes damage and since there are so many people that don’t like screen shake I will also add the option to turn it off. See you there!

Game Developer in the making~

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Migration, Security and Compliance Take Center Stage at AWS Summit NYC, 2017

Easy As Insights — Part 6: Improving Power BI User Experience — Dynamic Filtering Using URL…

Functional completeness and local hermeticity

How To Use An IP Location Lookup API

WordPress.com Vs WordPress.org

So I’ve been making web stuff for a quarter of a century now

7-Point Checklist to Hire a Strong Back end Developer

My Money Problem

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
Rose Owen

Rose Owen

Game Developer in the making~

More from Medium

[ SDL2 — Part 8] Rotating textures

Targeting Reticle

Saving & Loading Data in Unity