How To Make a Roguelike

This article is part of a series.

  Next:

This article is a guest post from Hexworks. The original can be read here.

This tutorial series is loosely based on Trystan’s Awesome Roguelike Tutorial. Go check it out if you want to use Java instead.

Table of Contents

Here are the links to all the current tutorial articles if you want to skip the introduction or want to continue where you left off previously.

  1. #1 Project Setup
  2. #2 Views, Screens, Inputs
  3. #3 Generating Random Caves
  4. #4 The Player
  5. #5 Exploring The Cave
  6. #6 Entity Interactions
  7. #7 Stationary Monsters
  8. #8 Combat and Damage
  9. #9 A Multi-level Dungeon
  10. #10 Vision and Fog of War
  11. #11 Wandering Monsters
  12. #12 Items and Inventory
  13. #13 Food and Hunger
  14. #14 Displaying Stats
  15. #15 Weapons and Armor
  16. #16 Aggressive Monsters
  17. #17 Experience and Leveling Up
  18. #18 Help and Examine Dialogs
  19. #19 Win and Lose Conditions
  20. #20 Wrapping Up

Introduction

If you are reading this it means that you are probably planning to write a game of some sort. Writing games is not only fun and useful if you are just starting out as a programmer but even if you have a lot of coding experience under your belt, and you want to learn a new language.

The problem is that if you want to write one you’ll have to learn how to create 3D graphics, how to use a complex game engine, and all sorts of related things…are you not?

Roguelikes to the rescue

If we take a look at the definition of a Roguelike:

Roguelike is a subgenre of role-playing video game characterized by a dungeon crawl through procedurally generated levels, turn-based gameplay, tile-based graphics, and permanent death of the player character.

it turns out that it has some inherent features that make writing one easy and fun! This tutorial series is therefore about writing your own roguelike game from scratch.

Language and library choices

For this tutorial we’ll use the Kotlin programming language. “Why not use C++, Java or Python?” you might ask. The reasons are:

  • Low-level languages like C++ make it much harder to focus on writing actual game mechanisms and you quickly get bogged down with memory management, complex language features and such. For a roguelike raw performance is not nearly as important as if you were writing an AAA title.
  • While Java has tons of libraries for this purpose it is a bit outdated even with the new improvements.
  • Python is a nice language, but its dynamic nature makes it harder do reason about your code as your codebase grows. Apart from that it is also more difficult to write code which runs on a multitude of platforms (including the browser).

Why Kotlin then?

Kotlin is a pragmatic language and its expressive power is on-par with Python. The language in fact feels like as if you were combining the best features of Java and Python: it keeps the static nature, but lets you write code fast with type inference, extension methods and other features.

For example this Python code:

class Tile:
  pass

def write_tile(tile: Tile):
  print("Tile: " + str(tile))

write_tile(Tile())

looks like this in Kotlin:

class Tile

fun writeTile(tile: Tile) =
    println("Tile: $tile")

writeTile(Tile())

pretty similar, huh? You also get multiplatform capabilities with Kotlin, so the code you write can be run on the JVM, in the browser, and on native platforms as a binary.

To top it all off, you can use any Java library, since Kotlin gives you seamless interoperability.

I’ve written about this topic on my blog here. Take a look if you are interested.

Game Libraries

For this game we’re gonna use Zircon, which is a Tile engine, the Amethyst SEA (Systems, Entities, Attributes) library, and some useful features form the Cobalt library, like data binding and the EventBus.

Note that I’ve chosen these libraries because I’m familiar with them, and I also think that they are the best fit for the problem at hand. Disclaimer: I work on those libraries, so I might be biased, but you’ll see if they work out for you or not.

Other things we need

For this tutorial we’re gonna need some basic Git and Gradle knowledge. I’ll explain these on the way, so you needn’t worry about them for now.

As for our development environment I highly recommend the Intellij IDEA Community Edition. It is not only free, but it is the best Kotlin IDE you can get.

Now we are all set, let’s start coding! In the next article we’ll set up our project and start working on our game right away!