Lets make a Commodore 64 Text Adventure Game!

A simple tutorial by John Christian Lonningdal

Part 1 - Lets create the story!

If you are anything like me, you want to see results quickly! You can plan something to death and never really see the fruits of it because you've played through it on your paper-prototype a hundred times and are quite bored with it before you have written a line of code. Well, lets just jump into it and do some quick and dirty prototyping just to get a starting point. Note that many of the code samples here are not showing the "correct" way of doing things, but just samples to get started in the discussion of what we can improve upon to make the final product. It will take some time, and eventually you have a well designed system that can hopefully be reused for many text adventure games.

Ok, lets whip up a story and some elements. The evil Wizard of Chaos has stolen the magical Golden Mask that will give him immensive powers. You have been chosen as the only hope to kill the wizard and retrieve the golden mask. Lets write some basic code for the introduction:

There is really nothing to special here, clear screen, light grey background and an indented title and credits along with a storyline description. Actually many adventures didnt even have this since the actual story was printed on the box/inlay, and naturally saving precious memory. I will discuss memory usage problems in the C64 as we go along, but to give you a note of warning early on: Basic is exceptionally memory inefficient! While the opcodes themselves are short, there is no notion of a memory pointer for anything, meaning that whenever you assign a string variable a string the actual string is then stored twice in the memory. Once in the basic listing, and another on the variable stack! Think carefully about that and you will see that you should think about memory issues early on in your program and with some simple coding tricks your adventure can be twice as big! As a fun little bonus I have added the calculated size of our adventure in the title (many games liked to advertise how big their adventure was). It is wise to keep track of how much memory you have available so that you can adjust your expectations of what you can fit in your epic adventure. Naturally, programming the thing in basic limits you to 38909 bytes of memory (actually 2 bytes less than what the boot screen says). If you had done it in assembly you naturally have access to the rest of the memory and could basically turn off Basic, Kernal and IO rom if you dont use those for anything. Still even in Basic it is possible to load 4kb of information into address range 49152-53247 ($c000-$cfff) if you later read it with peeks. That is 4 full screens of text for you right there although you would benefit speedwise from an assembly routine to read it and displaying it.

Ok, now that the story is established you can start planning your locations and puzzles. A good practice here is to start at the end. Yes, start with the climax! By figuring out how it all ends you can create the story backwards and figure out the necessary puzzles, required objects and the locations where you find these objects. Of course you probably already have a setting for the story in your head and some idea of what locations you want in it. For our story I wanted to have a twist where the battle at the end depends on whether you believe in the powers of the mask or not, and depening on your beliefs the the mask has an effect on you or not, I guess partially inspired by Terry Pratchetts elaborations on religion and its effect on people on the Discworld.

So naturally we need a location for the end battle, the wizards palace which we will place on top of a mountain. To actually kill the wizard we will need some sort of weapon, and in our case we will just add a good old pointy stick in the form of a sword. On our way to the castle we will go up a narrow path which will have a blocking boulder. This blocking boulder can only be moved if you believe in the power of the mask. Leading to this narrow path is a crossroad with a handy merchant that just happens to sell swords. The crossroads then also lead to your cabin where you start the game and the church which has the Altar of the Golden Mask where you will pray. Depending on what you answer when you pray to the altar, you will gain strength from the power of the mask or be spared from the fires of the mask that the wizard will cast at you. So basically you will have to pray at this altar twice, once to get strength to move the boulder and then another to renounce your beliefs so that the light from the mask has no effect on you. To buy the sword from the merchant you will have to bring a gold coin from your cabin where you start. So there it is, our whole adventure in details and here is a quick map to connect all the rooms:

So with this in mind we have established some basic requirements as well that is fairly typical for all text adventures:

  • Introduction text
  • Room descriptions with directions you can go and objects you can see.
  • Text command input
  • Navigation commands for going NORTH, SOUTH, EAST and WEST
  • LOOK command for showing room description again
  • TAKE command for picking up objects
  • EXAMINE command for examining objects
  • INVENTORY command for listing what you are currently carrying.
  • Other commands for interacting with objects and NPCs (BUY, PRAY, PUSH, KILL)
  • Game end descriptions (success or failure)
There are naturally many more you can add, most notably the ability to DROP items although to keep this first sample simple I will avoid that altogether. Indeed, my code will use a fairly brute force way of solving the bare minimum requirements with no thought whatsoever on reusable code and structure. This is just to establish the foundation for discussion and see what ways we can improve on the framework as we extend it and rewrite it. Hopefully during this time we will introduce new rooms and puzzles to make the adventure last longer.

Part 2 - Main loop and code structure
Back to index
 
 
All images and text are Copyrighted by John Christian Lønningdal 2007-2015 unless indicated.
Until Microsoft bothers to implement the standards this site will look best on Firefox, Opera or Chrome.