gittech. site

for different kinds of informations and explorations.

Hilt: A tiny text game engine

Published at
2 days ago

Hilt

Hilt is a very small, very early in development game engine for text adventures.

Creating a game

To start, create a config file with the .hilt extention.

MapSize(5, 5)
GameTitle("Frog Cave")
Cursor(">")
NullText("Nothing Here!")
ExitKey(q)


ShowMap(True)
MapNullText(" % ")
MapPlayerText("[o]")

Here is a breakdown of what each of these do

  • MapSize - Initialises the width and height of your Map
  • GameTitle - This is the title of your game
  • Cursor - Is what appears to the left of your input and is the cursor for selecting things with prompts (Which we will get to later)
  • NullText - This is what the game will display when your character moves to a blank tile.
  • ExitKey - This is the key to exit the game
  • ShowMap - True or False, this will decide whether you show the map to the player after every move
  • MapNullText - What you display on the map in space of a blank tile
  • MapPlayerText - What you display on the map to represent the player
But now, lets create stuff.
MakePlayer(0, 0)

MakeRoom{
    ID = Cave
    Location = 2, 2
    Icon = "[#]"
}

MakeRoom{
    ID = Shop
    Location = 0, 1
    Icon = "[$]"
}

MakeRoom{
    ID = House
    Location = 3, 3
    Icon = "[^]"
}

MakePlayer is integral to actally creating a game, the location is specified and relates to the map. 0, 0 in this case.
MakeRoom has 3 parameters, the ID, which is like the variable name, the location, which is where it is located on the map, and the icon which will represent it on the map
This is what our config file looks like, lets save this as config.hilt for example.
Now, we can make our main file

Making the main file

The main file is where all the magic happens, where you can actually make sequences take place. To start, we need to import our config file. Like this:

@config.hilt

Using @ followed by the config file is how you import it.
Now we can get to writing

@config.hilt

OnEntry.Cave{
    prompt(
        ID = CavePrompt
        Text = "You find yourself in a cave. What do you do?"
        Options = ["Explore", "Run Out", "Dance"]
        Return = ["You found nothing...", "Everyone laughed at you for being such a 'crybaby'.", "Everyone posted you dancing on Instagram Reels. You got bullied."]
    )

}

This is how you can create an event, using OnEntry. followed by the ID we set earlier, in this case using the Cave ID, will allow for actions to happen when the player enters the given area or "Room"
In this case, we will show a prompt, with the ID CavePrompt and text to be displayed followed by options and a return value.
The Text is what will be printed out before the prompt
The Options are the possible options for the user to pick from.
Return is a corresponding return output, It needs to line up with the choice, for example, if the user chooses "Run Out", the game will output the corresponding index (in this case index 1), being "Everyone laughed at you for being such a 'crybaby'."
In the example (which you can find in this repo, the main file looks like this:

@config.hilt



OnEntry.Cave{
    prompt(
        ID = CavePrompt
        Text = "You find yourself in a cave. What do you do?"
        Options = ["Explore", "Run Out", "Dance"]
        Return = ["You found nothing...", "Everyone laughed at you for being such a 'crybaby'.", "Everyone posted you dancing on Instagram Reels. You got bullied."]
    )

}

OnEntry.Shop{
    prompt(
        ID = ShopEntry
        Text = "You entered the busy market, eger for wares."
        Options = ["Buy wares", "Vlog it", "Sell Wares"]
        Return = ["You bought a gram of sheckledust. Probably should throw that away.", "You vlogged it!", "No one wanted to buy your loose paperclips and keycaps."]
    )

}

OnEntry.House{
    prompt(
        ID = House
        Text = "You relax in your lovely home. What do you watch?"
        Options = ["Breaking Bad", "Twin Peaks", "Nothing"]
        Return = ["You enjoyed it. Solid 9/10", "Your life changed! 100/10", "You are lonely"]
    )
}

This is a full example, the config creates 3 rooms and the main file initialises actions to happen on entry.

Playing your game

To play your game, simply run python main.py main.hilt, obviously replacing main.hilt with whatever the name for your main file is

Important

It is important to note THIS IS VERY EARLY STAGE and I plan on expanding it much much more, but wanted to get it up here.
Thank you for reading though!