Gamedev Log: “Slash’n’crack” #5 (Unity/C#)

A step-by-step log of how I made a basic Unity/C# game: “Slash’n’crack”!

This article is also available on Medium.

For the past few days, I’ve been posting a new series of gamedev logs about the simple Unity/C# mobile game I’m currently working on: Slash’n’crack!

For this dev challenge, I have a tight time constraint: I only have 8 hours to make the entire game, from start to finish!

In this new episode, I’m going to tackle a bunch of important features so that I have all the heart of my game done, namely the score, the player hitpoints and the game over

Hour #5: Adding the score & the lives, and implementing the game over logic

Features & demo

With my work from last week and the new asteroid model I made on Monday, I now have a somewhat “okay” game, in the sense that I have cool low-poly obstacles coming at me that I can slash to destroy, with a nice cracking animation:

But, for now, there isn’t much of a challenge because I don’t gain any point when I split asteroids, and there is no real consequence to them slipping through my fingers and exiting the bottom edge of the screen 😉

It’s time to fix this: in this 5th hour, I’m going to add some UI to show the score of the player and the remaining lives.

  • the score logic is really basic: you start with 0 points and you gain 1 score point each time you destroy an asteroid.
  • for the health system, there are bit more rules: I will assume that you start with 4 lives and that you lose 1 life each time an asteroid exits the screen. I also want to implement a very basic “invulnerability frame” logic so that if a bunch of asteroids get passed the threshold at the same time, you only lose 1 life and not 1 per asteroid.
  • when you reach 0 lives, it’s game over, and you should be presented with a “Game Over!” panel that lets you replay a new game, or quit the game.

For the UI, I’m going for pixel art and retro-styled panels; this matches the low-poly cartoony look of the asteroids, I find it nice for a mobile prototype game and, to be honest, it also allows me to re-use some of the assets I made for my previous gamedev log on The Escape 🙂

So here is a demo of Slash’n’crack at the end of this new hour of dev, with the UI and systems in place:

Note: if you watch carefully, you’ll can see that when asteroids exit the screen, there is a one second timeframe – ignoring the speed x3 – during which the new ones don’t hurt me anymore 🙂

At that point, I’ve finished all the core logic of my game, I have all the base mechanics I wanted. So next time, I’ll work on the organisation of my project and prepare a main menu scene so that the player doesn’t just appear in this scene instantly!

A few details, tips & tricks

For my UI, I’m once again using the PixelArt font to fit with my “retro-vibe”; and I’m using some assets I’d done previously like the pixel-styled buttons:

Just like in The Escape, I’m taking advantage of Unity’s feature of 9-slicing sprites to easily “stretch” my button texture to the right size with actually it being deformed. The idea is to define “borders” on your imported image so that Unity knows which parts are “on the edge” and which parts are “in the middle”, and it can properly reposition everything.

Here’s an example image from the Unity docs:

Here, zones A, B, C, D, F, G, H and I are borders while the zone E is the inner content. So I could use this sprite by pasting the border zones as-is, and stretching the middle one to fit my UI element size 🙂

Still about UI elements, another trick I used here is that because my star field is also part of my UI but that it needs to be behind my asteroids, I’ve actually set up my Unity UI canvas to be in “Screen Space – Camera” mode, and I’ve used the Z-coordinate to push the stars in the background:

This way, I can have UI elements both in front of and behind my 3D game objects 🙂

Also, for the red screen that briefly pops when you lose a life, i.e. an asteroid (or a group of asteroids close to each other) gets out of the screen, I’m relying on coroutines. This allows me to control the colour of the red screen over time and have it go from a semi-transparent red to a fully transparent one in one second, without blocking the main thread.

In parallel, for the “invulnerability” feature, I just have a flag in my game manager that is toggled on when an asteroid hits, and then I use Unity’s Invoke built-in function to toggle it back off when the one second of invulnerability has elapsed.

And of course, the “replay” part meant that I needed to reset the state of my scene to go back to the initial one; so I had to make sure to update the score back to 0 and the lives to their starting count, and also to empty the screen of any remaining asteroid.

Conclusion

Although I have figured out most of what I want to do for this game (in terms of features, gameplay, art style, etc.), I might come up with unexpected ideas along the way… and, of course, I’d be really happy if you’d participate, too, so feel free to leave comments with cool ideas for Slash’n’crack!

I hope you like this series of Gamedev Logs, and I’ll see you in a couple of days for the next one 🙂

Leave a Reply

Your email address will not be published.