The Archive

The Dungeon, AKA The Potato Game

A few years ago while on holiday staying with family in Switzerland I started making some kind of dungeon crawler text adventure game in Laravel. I didn't have a solid plan but wanted to make it using Test Driven Development and in such a way that I could build it out bit by bit, adding more complexity and detail as I went. It started as a room with a potato in it. Then you could pick up the potato. Then you could eat the potato... I had some vague idea that it could be a kind of user-generated story, when people got to the end of the dungeon they could literally write their own adventure. Preferably not just about potatoes. Now I'm not sure that would actually work but then again, the game doesn't really work at all this point so...I'm getting ahead of my self.

Relatively recently in the process I started to convert it to use an Entity Component System, or ECS. This provides a bunch of flexibility with the only real downside being that everything is an Entity, in the same way that in WordPress everything is a Post. I'm not a fan of that but there's benefits, so let's keep going.

What am I doing?

This post is me collecting my thoughts and giving a brief introduction into the setup of the game. Because the best way to learn is to teach - or so my teacher told me - and if I can explain it to you then hopefully I can remember what I was doing.

Rooms

I exaggerated a little. Not everything is an entity, or we'd have nowhere to put things. There are a couple of exceptions. The first is rooms. These have a description, so that players can know what it looks like, sounds like... smells like. They also have a width and height so that we know how much stuff we can fit in it. They also have a couple of booleans on then so we can know whether users should spawn there and whether it is a safe room - in which no violence may occur.

Users, Bodies and the Metaphysical

Another non-entity thing is a User. This model represents the real life person who plays the game. This is separate from a Body which is an Entity in the game, in the same way that a table or potato might be. In fact a body is kind of like a crate that's locked - until it dies, at which point it can be looted.

This separation of User and Body can get a little confusing at times - the user gives the command, the body tries to obey but is limited by its surroundings... In fact sometimes in practice it reflects reality strangely well.

Entities

Everything else in the game is represented as an Entity, potentially with some components applied to it. Applying a component to an Entity allows it behave in various ways as defined by that component. For instance an Entity with the Attackable component applied can be attacked by a player.

This means that the logic that defines what it means to be, say, edible can be defined in one place an then applied to any type of Entity. So once I've made a potato that is edible, I can make a pineapple really easily. But I can also make a rock that's edible. Or a door that you might previously have needed a key for...now you could eat your way through it. The key for the lock? Edible. An enemy? Eating is now a form of attack, I guess. The room? Not edible. Rooms aren't entities, remember?

Currently there are 12 types of component:

  1. Attackable - can be attacked with weapons, maybe a destroyable box, a door or even a person
  2. Blocking - prevents a user from going past it
  3. Consumable - can be eaten/drunk
  4. ContainsEntities - other Entities can be put inside it, for example a crate or a dead body
  5. Droppable - can be removed from a player's inventory
  6. Equipable - can be equipped, e.g. armour or clothes
  7. Lockable - can be locked using a key or a secret code
  8. Protects - when equiped provides the user with protection
  9. Takeable - can be picked up by a player with sufficient strength
  10. Teleports - when a user steps onto this Entity they will be teleported to another location. (Note: technically this is how doors work in this game)
  11. Unlocks - can be used to unlock a Lockable. E.g. a key or a piece of paper with a secret code on it
  12. Weapon - can be used to attack an Attackable

Commands

These are things that a User can tell their Body to do. For example look or go. Their body may not be able to do the thing, but they can ask it to. There are a bunch of commands in the game. Most are self-explanatory.

  1. Attack
  2. Drop
  3. Eat
  4. Equip
  5. Give
  6. Go
  7. Inspect
  8. Inventory
  9. Kill - instantly kills an attackable for debugging purposes.
  10. Lock
  11. Look
  12. Respawn - create a new body and take control of it
  13. Say - send a chat message to anyone nearby
  14. Take
  15. Unlock
  16. Whisper - send a chat message to a single person

Actions

These are things that can happen in the game. These are different from the commands above. Once a command has been given, multiple actions may take place. An action may even cause another action to happen. for example if a user uses the Attack command a Hurt action will probably be triggered against an entity. If that entity then dies, an Expire action might also get triggered.

  1. Equip
  2. Drop
  3. Give
  4. Hurt
  5. Take
  6. Eat
  7. Lock
  8. Unlock
  9. Expire
  10. Go
  11. Respawn
  12. Say
  13. Attack

That's it for now. You can look at it at dungeon.deviouschimp.co.uk but it's probably broken.