Published in

Kiki’s Corner

# Lives, Energy, and HP in MakeCode Arcade

It’s super easy to make exceptional games in Microsoft MakeCode Arcade! The problem is, it’s also really easy to make them too short!

This article will teach you how to use lives, energy bars, and hit point mechanics to enrich your user’s gaming experience.

(Pair this with my story on adding levels, and you’ll have a full-length game in no time!)

# The Relationship Between Lives, Energy, and Hit Points

You may be familiar with one or more of these ideas already, but let’s start with some common definitions to keep us on the same page.

Lives are generally used to give the main character a “redo” after they’ve fallen into a tragic situation. Perhaps they’ve stumbled off a cliff, run into a carnivorous alien, or tripped into a pit of poison spikes. Any one of these things is enough to end a game, but adding extra lives allows the player to have a longer, more satisfying experience.

Energy is a more abstract concept for something that waxes and wanes with gameplay. Maybe a character gets hungry, causing the energy to deplete…then you feed it, so the energy refills. A total loss of energy could result in the loss of a life, or it could result in some other penalty (inability to fire, inability to move, decrease in score.) It’s completely up to you.

Hit Points, or HP, are like a mix of the two. Usually, hit points are a form of energy bar that results in the loss of a life when the bar reaches 0 — although, it’s also common for hit points to behave in the same way as lives, removing one at a time until they’re gone and the game ends in a loss.

Changing the number of lives in MakeCode Arcade is one of the most simple mechanics we have. The ability to add and subtract lives is controlled by one default block…and you don’t even have to initialize it first!

Of course, you can initialize the variable manually if you don’t want to start with three lives.

# The Best Extensions for Lives, Energy, and HP

For the best experience in this topic, you’ll need to load a couple of extensions into your project. You can find them by visiting the toolbar under Extensions.

Here are the three that I recommend:

This extension adds a visual bar that will demonstrate the quantity of some variable. This can be used for lives, energy, HP, time, or any other percentage you can imagine.

While arcade-sprite-data may be harder to understand at first, it allows you to keep multiple stats on multiple sprites, so you could potentially have a handful of powers that vary during a game, or create hit points for enemies.

Also known as text-sprite, this lets you treat text as a sprite inside of your game, allowing you to move and transform it the same way you could any other sprite.

# Putting it Into Practice

Now that your toolbox is set with everything you need, you can start making a game that takes advantage of lives, energy, and hit points!

For my game, I’m going to start with the Space Explorer skillmap and make a few changes.

To do that, I’ll finish the map through the last level, then when I receive the trophy, I’ll come out to the side panel and select `Save to My Projects`.

My project will be opened in the full editor with my complete toolbox available.

Before adding anything else, I have a counter for lives (which deplete when I collide with enemy ships) and a status bar for fuel (energy.)

Now I just need to use hit points. For this, I’m going to create an alien saucer that stays on screen and tries to attack me.

I’ll give it a limited number of hit points…like 5…which means I have to fire on it 5 times before it goes away.

Then I’ll duplicate the code for when Player overlaps Enemy and when Projectile overlaps Enemy and make a couple of changes…

This makes sure that the alien is destroyed after 5 hits…but it doesn’t show you how many hits are left! That’s why we need the text sprite.

Now we have a counter that will decrease each time the alien is hit, and disappear when the alien is vanquished!

And there you have it! That’s all you need to get started adding lives, energy, and hit points to your game!

--

--

## More from Kiki’s Corner

Whether you’re a student or a teacher, a beginner or expert, drop by weekly to find new tips, suggestions, and challenges!

## Get the Medium app

Kiki is an author, educator, and the Director of Education for Microsoft MakeCode