Unity 2d Random Dungeon Generator For A Roguelike Video Game

A simple approach to programming a top down 2D random dungeon generator for roguelike video games using C# in Unity

Last updated 2022-01-10 | 4.7

- Solving Problems with C# Programming
- Procedural Random Dungeon Generation
- Working with 2D Bitwise Tilemap Systems

What you'll learn

Solving Problems with C# Programming
Procedural Random Dungeon Generation
Working with 2D Bitwise Tilemap Systems
Simplified Solution for Enemy Pathfinding

* Requirements

* Basic Computing Experience
* 2D Graphics Editing Experience
* Experience with Unity Game Engine
* Experience in Photoshop is Helpful But Not Required
* Experience Programming in C#

Description

This is a course intended for beginner to intermediate Unity / C# video game developers who have an interest in the classic rogue-like video game genre. We'll be borrowing old familiar pixel art graphics to generate our 2D grid-based environments, characters and enemies.  

This course is not a complete game. It's purpose is to explore a couple of simple random dungeon generation tactics and get you started in the world of procedural level generation.  You'll also learn how to apply a rounded edge around all of the walls of your random dungeon to break up the repeating patterns and give the environment a more organic look.

As an added bonus, I've included a section to demonstrate a simplified method for enemy path finding.  This method uses a flood fill approach to find the shortest path between an enemy and the player. Your enemies will be able to patrol in random directions, chase the player using a flood fill path finding approach as well as engage with the player to begin attacking.

Who this course is for:

  • Beginner to Intermediate Unity Game Developers
  • 2D Roguelike Game Enthusiasts
  • Beginner to Intermediate C# Programmers

Course content

6 sections • 28 lectures

What's Included in This Course? Preview 01:29

Hello and welcome to “Unity 2D Random Dungeon Generator for a Roguelike Video Game”.

In this course we’ll start by creating a basic controller for the player’s movement. We’ll create prefabs for Floors & Walls and then learn how to automatically place them into the game using a Tile Spawner script.

From there, we’ll quickly dive into Procedural Generation using the Random Walker Method. This method will produce a cave-like environment ensuring that all areas of the world are reachable by the player.

We’ll continue to enhance our dungeon generator by adding an Exit Doorway as well as placing random items and enemies in strategic locations throughout the level.

I’ve devoted an entire section to creating rounded edges. In that section we’ll be manipulating existing pixel art. I’ll show you how to count in binary, which will be used for organizing and naming the tile set. Then we’ll write a script that automatically places the tiles as each random dungeon is generated.

We’ll extend upon the Random Walker Method to produce other types of dungeons, such as Rooms & Halls or Winding Hallways.

As a bonus, we’ll write an enemy movement script, including a patrol routine and a simplified path finding solution allowing enemies to chase the player and line up for an attack.

So if you’re ready to start learning how to create procedurally generated random dungeons for your own video games in Unity… Then welcome aboard! I hope to see you in the next lecture!

Software Used in This Course Preview 00:33

I am using Unity v2018.2.19 in this course. I realize there are newer versions of Unity available, but I actually prefer this version as it seems to be the most stable from my own experience. Of course you are welcome to use any version of Unity you see fit, but I cannot guarantee that the scripts will work exactly the same from version to version. If you have any questions, please don't hesitate to ask.

Although Photoshop is not required in order to edit images for your game, I do use Photoshop to demonstrate some of the editing techniques used in this course.  However, if you have any previous experience with 2D image editing in any other software, you should be able to follow along since most of the editing techniques are relatively simple.

Setup Unity 2D Project Preview 02:52

We'll setup a 2D Unity Project which will  be used throughout this course.

Graphic Tilesets Preview 12:50

Learn about one of the original Roguelike video games featuring 32x32 pixel graphics by David Gervais who allows you to use his graphics in your own projects.  We'll look at the Creative Commons License and learn how to access these graphics by downloading the Angband game. We'll be using these graphics throughout the course.  Please note, the contents of this course should work with any graphic tilesets. You are not limited to using the Angband tiles.

Player Movement (Flip X) Preview 20:48

Learn how to move the player's head to the left or right based on directional input from either the keyboard or game controller.

Player Movement (Move) Preview 18:15

Learn how to move your player around the scene with directional input from either the keyboard or game controller.

Floors & Walls Preview 10:32

Learn how to create Floor & Wall prefabs to manually build areas where your player can walk around. These same Floors & Walls will be used in your random dungeon generator a bit later in the course.

Tile Spawner Preview 23:40

Learn how to create a tile spawner prefab which allows you to focus on only building the floor areas of your dungeon. This tile spawner will automatically generate wall prefabs that surround all of the floors.

Random Walker Method Preview 20:13

Learn how to create a randomly generated dungeon by sending a virtual walker in random directions around the map space leaving floor tiles until enough floor tiles have been created.

Exit Doorway Preview 17:18

Learn some useful tips on how and where to place an exit doorway in your randomly generated level.

Random Item Spawning Preview 23:00

Learn how to spawn random items into the randomly generated dungeon in locations next to walls and not within narrow corridors.

Random Enemy Spawning Preview 10:26

Learn how to spawn random enemies into the randomly generated dungeon in open spaces away from walls and corridors.

Creating a Template Preview 08:47

Learn how to use existing pixel art graphics to form rounded edges to the wall tiles. In this lecture you'll learn how to separate the graphics and setup a template which will be used to create new tile sets later in the course.

Binary Tile Names Preview 13:05

Learn the basics of counting in binary and discover the resourcefulness of using binary numbers to organize and store your tilesets.

Graphic Tileset Preview 20:10

Learn how to construct your binary influenced graphic tile set using the template created in the previous lecture.

Tileset Array Preview 12:23

Learn how to transfer the tile set created in the previous lecture into a grid-based texture atlas where each of the 4x4 grid arrays are arranged in the appropriate order for making use of binary.

Scripting Rounded Edges Preview 16:58

Learn how to program the rounded edge tiles created in this section to completely surround all of the wall tiles within the randomly generated dungeon.

Reusable Code Preview 11:03

Learn how to break down your scripts into smaller segments for the purpose of reusing them as functions for other scripting purposes.

Random Halls Preview 13:47

Learn how to create a series of randomly generated hallways by reusing the random walker script used earlier in this course.

Random Rooms Preview 10:16

Learn how to add random rooms of various sizes and shapes to the random series of hallways created in the previous lecture.

Winding Halls Preview 13:59

Learn how to add corners to some of your randomly generated hallways to further enhance the look and feel of your randomly generated dungeons.

Enemy Patrol Preview 18:31

Learn how to get an enemy to patrol around in random directions through C# scripting.

Enemy Chase Preview 15:05

Learn how to organize your movement script to handle different types of movement related scenarios, including basic patrolling, attacking and chasing the player.

Find Next Step Preview 28:59

Learn basic pathfinding techniques to allow the enemies to chase the player while walking around obstacles in the environment.

Inset Exit Doorway Preview 14:37

In this lecture you'll learn how to place an exit doorway in a position that is guaranteed to be surrounded by 3 adjacent walls.

Fog of War / FOV Preview 38:24

In this lecture, you'll learn how to create a system to black out unexplored regions of the map with the Fog of War system. Additionally, the system will handle the player's Field of View displaying tiles immediately surrounding the player with less Fog coverage, areas of the map that have already been explored shown with 50% opacity and unexplored areas with 100% opacity.

Fog of War (Part 2) Preview 18:16

In this video I'll show you how to make your Fog of War look a bit more foggy with a curvy trim that separates the fully opaque black fog from the explored semi-transparent fog.

BONUS LECTURE: Other Courses by Billy McDaniel Preview 00:39

Bonus Lecture