Creating a Roguelike in Kotlin, KTerminal, and LibGDX
June 17, 2026 ยท View on GitHub
Part 2 - The generic Entity, the render functions, and the map
In this portion of the tutorial, we're going to create a representation for a game map, some generic entities, and pulling code outside of our MyGdxGame.render function into other functions.
Creating the Entity class
First, we're going to create a way to represent entities in our game. For the purposes of this tutorial, I assume that an entity is anything that has a graphical and logical representation in the game. That means that an entity must have a glyph to draw and a location where to draw it.
To get started, let's create a new package under our com.mygdx.game package called entities.

Under the new entities package, create a new kotlin file/class and name it Entity. We're going to make this a very simple class that has the above mentioned properties we need to keep track of. Here's what it should look like. I've also added an additional property called name so that we can give a name to these entities.
package com.mygdx.game.entities
import com.halfdeadgames.kterminal.KTerminalGlyph
open class Entity(var x: Int, var y: Int, var glyph: KTerminalGlyph, val name: String) {
fun move(dx: Int, dy: Int) {
x += dx
y += dy
}
}
The code should be relatively straight forward. In Kotlin, anytime we define a var or val in the arguments for the class
constructor, it automatically sets those arguments to be a property of the class. In Java, you would normally do this
with setting this.x = x or in Python, self.x = x. Kotlin allows you to skip over that boilerplate code. We also have a simple
move method for the class that updates the position by a given x and y value. We just add the dx and dy because they can be negative to indicate
movement in any direction.
Extending the entity class with an actor class
While it may not make a lot of sense at the moment, there are going to be entities down the road that we want to create that have the properties of an entity, but they will either be static or dynamic entities - entities that take a turn every move or don't. For example, a ladder or door is an entity that has a glyph and a location, but it doesn't do anything every turn of the game like a goblin, rat, or the player.
For this purpose, we're going to create an Actor class, which extends the Entity class and enforces actors to have
an act method to be called for each turn so that they can properly make a move when it's their turn. Here's the boilerplate
code for an actor that we will be using:
package com.mygdx.game.entities
import com.halfdeadgames.kterminal.KTerminalGlyph
import com.mygdx.game.MyGdxGame
/* All entities that take a turn and perform an action every tick have an act method */
open class Actor(x: Int, y: Int, glyph: KTerminalGlyph, name: String) : Entity(x, y, glyph, name) {
open fun act(game: MyGdxGame) {
game.nextTurn()
}
}
The actor has an act method which accepts the game as an argument so that it can call methods that the game has and so that it has access
to the game data. An actor needs this so that later on we can check whether or not we can perform certain actions or read
other data from the game's properties.
Creating a player class
Now that we have some semblance of what an Entity and an Actor are, we're ready to create a representation of the Player.
package com.mygdx.game.entities
import com.badlogic.gdx.Input
import com.halfdeadgames.kterminal.KTerminalGlyph
import com.mygdx.game.MyGdxGame
class Player(x: Int, y: Int, glyph: KTerminalGlyph, name: String) : Actor(x, y, glyph, name) {
override fun act(game: MyGdxGame) {}
}
Right now, our player class doesn't currently do anything that the actor class doesn't do. We'll add to it later.
Adding and drawing entities in the game
Previously, we were tracking the location of the player as a vector and drawing a glyph at its location.
Our InputHandler was simply updating the location of the player location by mutating the game's vector, playerPosition.
Now that we've got a notion of storing them in objects, we can update our Game class to render the player's object and update our
input handler to properly update the player's coordinates.