2D Rogue-Like Tutorial (part 1)

If I’m being completely honest, I can’t say that the Roll a Ball tutorial on Unity’s website was the best. The instructions were sometimes vague and the presenter would rush through a lot of the instruction to the point the video had to be paused at length just so the user could catch up. That being said, the tutorial still reinforced what we had been learning in class.

Therefore, I thought I’d give another one of their tutorials a try. Wishing to know both sides of Unity, I wasn’t sure if we would end up looking at creating 2D games in Ant’s class. I’m hoping that much of the coding will be interchangeable and learning something new is never a waste, so I picked the guide on how to create a 2D rogue-like game.





This is the first level, where the randomisation of the tiles can be seen, along with the generated walls on the map, player character and the exit.





The details of the game are simple:

  1. The player is exploring a caves system and needs to make it from a starting point to an end point (likely on opposite ends of the board); this is working off a grid-based floor, where you can move one square at a time.
  2. The game is centered around your hunger rather than energy, although this can always be altered afterwards with a clearer understanding of how the game is set up. Each square moved consumes one hunger point. You need to see how many days you can survive.
  3. Hunger game be replenished by in-game objects. You can move over squares that contain food or drink and reduce the threat of starving to death.
  4. There are NPC monsters that live in the caves, who will attempt to whittle down your hunger faster as they try to attack you. You can engage them or keep moving away from them. You do not have to beat them to progress to the next level of the caves.

Much like other posts I have and will make about tutorials, I’m not going to go into the step-by-step process in which I made the game, but rather my overall opinions about the way the game has been put together and what I’ve learned from my endeavours (or where I need to improve).

Setups and Assets

The tutorial will go through setting up all the assets of the game, how to script the randomised level generation, the various mechanics needed for gameplay, and much more. However, they do ask you to download files that have already been made for you, which I wasn’t too keen on. It felt like a lot of the work was already done for me. So while I’ve done this tutorial, I would actually like to try making another rogue-like from scratch instead.

These are just some of the prefabs we were asked to create/import out of the ones that were provided from Unity’s store, specifically made for this tutorial.

It was interesting to learn about sprites and how to create animations for your 2D game. It was also useful to be shown how the tags and layers will influence the sprites, as well as how they can be called on in the scripts.

Learning about the Sprite Renderer and Animator may have been a bit premature, but the tutorial was actually fairly clear about the two component; it also used components on the Player that we’d already learned about in 3D – namely Box Collider and Rigidbody. These are still important in a 2D game.

Level Generation

It was interesting to think that the game board was actually compiled using script, rather than laying it out. This meant that you could add randomisation to the levels as the player goes down deeper in the caves. This randomisation also included how many walls would be in the level (an 8×8 board grid), as well as how much food spawned, where the enemies would appear, where power ups would be placed, and basically anything to do with the sprite we made in the setup.

Mapping out the board via code felt complicated, but it made sense for a more dynamic game. Otherwise, you would just be playing the same map over and over again. The interesting part they did include was omitting the outtermost tiles in their randomisation, planning ahead that (if they hadn’t done this) the random tile choosing could result in an impassable board.

I hadn’t realised you could actually lock the inspector and so that you didn’t accidentally click out of it while adding parts to your arrays. I also didn’t realise you could add several items to an array at a time (I thought it was a drag and drop method that was done one at a time).

I also learned the use of coding something as a “singleton”, which is where there can only be one instance of that object in the game at any time. This will mean that you don’t have several instances of the GameManager (and thus objects, levels, etc.) going at the same time by using Destroy. This is something I never really thought about before, when moving through levels in a cave-crawler or rogue-like game.

Unit Mechanics

This part of the tutorial was far more difficult and mathematical than I thought it would be. I suppose I thought things could be done a little more simplistically, but to bring in any of the movement scripts does seem very complex. Unfortunately, I don’t think I understand nearly as much as I had initially hoped, so I’ll have to revisit the code that was made in this game and try to break it down further than the video guide did. Perhaps as I continue making things in class and trying other tutorials, the code will become clearer.

In this part alone, I can see why this is an intermediate tutorial if only for this section.

Some of the other mechanics taught in this section were a little more straightforward, such as the script to set up the wall sprites so they will change as they take damage or updating the player animation states in the Animator, seen here:


However, looking at some of the code outside of the videos, the annotations actually do make learning the scripts a little easier. This, for example, is part of the BoardManager script with the annotations included:

//SetupScene initializes our level and calls the previous functions to lay out the game board
public void SetupScene (int level)
//Creates the outer walls and floor.
BoardSetup ();

//Reset our list of gridpositions.
InitialiseList ();

//Instantiate a random number of wall tiles based on minimum and maximum, at randomized positions.
LayoutObjectAtRandom (wallTiles, wallCount.minimum, wallCount.maximum);

//Instantiate a random number of food tiles based on minimum and maximum, at randomized positions.
LayoutObjectAtRandom (foodTiles, foodCount.minimum, foodCount.maximum);

//Determine number of enemies based on current level number, based on a logarithmic progression
int enemyCount = (int)Mathf.Log(level, 2f);

//Instantiate a random number of enemies based on minimum and maximum, at randomized positions.
LayoutObjectAtRandom (enemyTiles, enemyCount, enemyCount);

//Instantiate the exit tile in the upper right hand corner of our game board
Instantiate (exit, new Vector3 (columns – 1, rows – 1, 0f), Quaternion.identity);

To Be Continued

I’m still working on this game and going through the tutorial videos. Unfortunately, my Unity on my home computer has become corrupted (?) and will not launch. I’ll have to fix it as soon as possible. Until then, this will have to wait a little bit longer!



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s