Roguelike AoC – part 26

In the twenty-sixth lesson of a roguelike game tutorial (the last one) we started with inventory. Unfortunately there’s no more lessons – the author dropped the project, however it still does not allow me to skip it. Last march of the BareMetalDev Advent of Code 😉

New folder structure

Yup, the files were moved and new ones created. However, it’s a trivial task and what is more – due to the CMake plus CLion being used I don’t need to do a thing in the project config.

Where’s my stuff? Items I mean

Adding Item struct was pretty straightforward – as usual I’ve made some changes. Location is used instead of Position – also not as a pointer but as a value. I’m not so convinced by using a union in this struct, and the name is too long. My structure is below.

typedef struct Item {

    char name[32];
    ItemType type;
    Location location;

    union {
        Weapon *weapon;
    } object;

} Item;

Printing them out

In the original lesson the author modified a main loop to listen for key i being pressed to show the inventory. I have already designed specific function for this called handleInput so what I had to do is to add a logic there:

// show inventory
case 'i':
case 'I':

I had to add playerDraw function here in order for the cursor to be moved back to the place where player is. Could do that in a low-level way (just calling curses method) but that’s what wrappers are for. However, usually inventory is being shown in a separate window, but here we’re keeping it simple.


Here is the direct link to the GitHub repo.

You Might Also Like

Leave a Reply

Back to top