Minimal prototype released


So I made a simple game in Guile.

I had this idea a long time ago, but I didn’t have the energy to make it. I decided to join the jam to force myself to do it.

I didn’t have all the days of the jam available so I only really worked on this for few hours during 2 or 3 days, but we got something at least.

It’s the first time I make a project makes this too aggressive use of functions in scheme. I wanted to make the game logic as separate as possible from the core so I could re-write the core (to show nice graphics instead of the command line, for example) in the future.

Games like this are just a state machine you have to define, so you can think about it as functions that call each other. Even in a mutually recursive way. We have proper tail calls in scheme so this is perfectly possible:

(define (start-game)
    ...
    (morning))

(define (morning)
    ...
    (if (too-tired?)
        (stay-in-bed)
        (wake-up)))
...
(define (night)
    ...
    (morning))

I tried to do this, but I made a weird state representation. My state is a way to generate functions that follow a pattern but as I am sending the next states as parameters, the mutual recursion doesn’t work. Why? I think this happens because the states are generating closures where the states that are declared later are not yet available, so they arrive as undefined and the game crashes when it reaches that point (it tries to call an undefined value).

Instead of fixing the game representation, I just pushed further with the ugliest hack I could think of: make a hash-map of the states, and read them from there. The hash-map is defined since the early beginning and the states register themselves in the hash-map as I write them.

Some ugly define-macros (register-state and to-state) are needed for this mechanism to work.

In the end, I just shoot myself in the foot for using this kind of representation so I’ll probably write all this again properly in the future.

The representation I managed to do was not flexible enough and it was really hard to add, for example, random state transitions or parametric states that are defined as a template but are instatiated as the game goes.

All this happened because I felt I had no time to think, and I don’t know scheme macros properly.

With some macro magic and some planning the state definition would be better and flexible enough for my purposes.

Next time.

At least we have something working. I didn’t expect to be able to submit anything in the few hours I had available.

I hope you find it interesting.

Files

game.tar.gz 3 kB
Nov 06, 2022

Get Wake up

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.