A step-by-step log of how I made a basic Unity/C# game: “Slash’n’crack”!
This article is also available on Medium.
Last December, I wrote a series of blog posts on how I programmed a simple Unity/C# game: The Escape! In this basic arcade game, you control a little ship and you have to avoid the randomly generated walls and other obstacles.
In the upcoming weeks, I’ll publish a new gamedev log for another game: Slash’n’crack 🙂
Just like last time, I’ll regularly show new progress on the game as I develop it and add new features, visuals, sounds, etc. I’ll also explain briefly how I did it and share some coding or Unity tricks.
But this time, my time constraint will be way heavier: I’ll only have 8 hours to make the entire game, from start to finish!
I hope you’ll like it – and with that said, let’s dive in directly with a quick description of the game, and the first features from hour #1 🙂
About the game
It’s been too long since I haven’t done app development, so I will make Slash’n’crack a simple mobile game, an Android app. The goal is straight-forward: you need to slash the incoming asteroids so that they don’t crash on the planet below! The gameplay is very basic: you just swipe the screen to strike the obstacles and they will start to crack and crumble under your fingers 🙂
The game draws inspiration from Fruit Ninja. In this app, you need to swipe the screen of a tablet or a phone to cut fruits and gain points… but make sure not to touch the bombs! Here, given I don’t have much time, I will be making a pretty stripped out version and focus on the actual slashing part – I won’t be implementing all the upgrades, shop and RPG-inspired mechanics from Fruit Ninja.
Slash’n’crack is an arcade game: it plays endlessly, faster and faster, until the player eventually tires out and loses!
In terms of visuals, I will be going for a low-poly and retro-vibe: I will use 2.5D (i.e. 3D objects but with a 2D behaviour) and I will have rough shapes to depict my asteroids, and my UI will use pixel-styled buttons or fonts.
Since the game is meant for mobile phones in portrait mode, I will be working on a vertical-oriented screen with a 0.45 ratio (like on my Android A12 test device), so things will be pretty “stretched” compared to usual screen sizes. This is a nice challenge that will force me to work a bit on UI design so that I make something readable and intuitive for the players…
Just like with The Escape, I don’t plan on making a long-run AAA – this project aims at creating a prototype/small game to brush up my Unity skills and finalise something in a given limited time-frame 😉
And also: I might re-use some handy assets from The Escape, since both games will use pixel-art/low-poly styles and are set in a sci-fi universe; this will allow me to concentrate on the features and fixes and not spend too much time on making additional stuff… even if I’ll obviously still need some custom props for this new game!
Hour #1: Making an infinite scrolling background
Features & demo
For this first log, I’ll share how I prepared the core elements of my game: the infinite scrolling star field in the back and the falling asteroids in front of it! Note that, at the moment, those asteroids will be shown with primitive cubes.
Talking about the background might seem secondary and a bit silly, but this star field is actually key to making the game work… since it’s how I give the player this feeling of movement.
Because, in Slash’n’crack, I wanted to make it as if asteroids were coming towards “you”, meaning down to the planet that you’re trying to protect. But with this camera frame you don’t have a lot of reference points to give players an understanding of speed. Simply moving asteroids (or cubes, for now) from the top to the bottom of the screen is quite… well, underwhelming, to say the least.
Here, the asteroids are moved thanks to a super-short C# script that translates them to the bottom of the screen and remove themselves from the scene when they have exited the camera frame.
But so – I decided I would add some stars in the background moving at a matching speed, and that I would make them scroll through the screen to better convey this overall movement. Of course, you can’t really have an “infinite” background – that’s why, similarly to what I did in The Escape for the obstacles, I used the trick of object pooling to loop my background endlessly and have it repeat again and again behind the asteroids 🙂
I’ll give more details on how I implemented this in the “tips & tricks” section below, but here is the result after this first hour of dev:
For now, I’ve added the asteroids by hand to the scene – the next step will be to auto-generate them thanks to a game manager!
A few details, tips & tricks
The idea to make the infinite scrolling background is basically to make a Unity UI canvas that contains 3 image elements, that each display the exact same repeating PNG file:
The images are added as children of a vertical layout – this way, they’ll automatically get sorted depending on their sibling index. Then, I make the entire parent container move downwards and, when one of the image elements leaves the frame, I just push it back to the top so that it can re-enter the screen on the opposite side.
Here is a debug of the process with tinted images and some offsets so that we can see the loop:
All of this works because movement is relative: translating the background and the asteroids gives the player the feeling of movement, but it makes it easier to handle positions.
And, of course, object pooling is a great technique to optimise your game: rather than continuously destroying and re-creating new objects, which leads to memory fragmentation, it allows you to “reserve” a chunk of storage at the beginning of your process and then re-use it until the end 🙂
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’ll like this new series of Gamedev Logs, and I’ll see you in a few days for the next one 🙂