Building a roguelike in F# from scratch - First Problems
Introduction
Further down the roguelike development rabbit hole we go...
If you have been reading so far you will have noticed this it not a traditional tutorial that jumps right in with game loops, controls and render. The reason for that being this is not a traditional tutorial, this is me writing a game and trying to capture my thoughts as I do so. I believe that when using a functional language it is pointless starting at the game loop level. Until you have some idea of the data you are dealing with or you risk a few problems:
- Your game loop drives your thoughts on data structure so you end up with a compromised structure.
- You realise your structure is not solid and it causes a rethink, which means big a refactor or living with the problem.
Neither of these are desirable when you think about it. This is why I want a solid foundation to start and save a mountain of pain down the line.
One of my favorite sayings I discovered during my journey into FP is "Follow the types". For me this is when immutability and function purity clicked, it was my epiphany moment. When you are writing pure functions, they tend to be small and focused. So if you know the input, output and operation you want performed the code tends to write itself. Or if you follow the types, the code becomes obvious.
This situation might be reversed with an OO style development but given we have to REALLY think about immutable state and how it will be manipulated it causes this bottom up flow until we know the foundations built in Building a roguelike in F# from scratch - Repo and Initial Types are solid.
Testing the structure
For the moment I am working on/thinking about the sort of queries and manipulations that are likely to take place on our structure, this will highlight any weaknesses that need to be addressed. So time to start with some obvious operations we need to see how problematic they prove to be.
- Does the tile and contents at a given location block line of sight
- Does the tile and contents at a given location block movement
- Get all items at a given location
- Open, Close and Unlock a door
- Add an actor
- Move an actor
- Remove an actor
- Inflict damage to an actor
- Heal an actor
- Pick up an item
- Drop an item
If you think about it, with just these building blocks we have a large chunk of functionality.
First road block
This is the first indication this is a real world project and not a tutorial, I hit some road blocks last night. Here they are:
- Been a while since I have worked in F# so had to remember how to make types visible in other files in the project, this is more than a one file project.
- Needed to fully implement my vector objects detailed in Roguelike line of sight calculation
. This was actually fairly painless in the end. - Have to throw away some of my day to day OO bad habits, so code it taking slightly longer than expected.
And then the MASSIVE roadblock hit. I sent a transfer for my ETH to LTC via ShapeShift and they have taken my money but not given me any back. As you might imagine, this was a real distraction.
Moving on
So in the next update I hope to have some code for you along with a push to the repo, some days just do not go as planned :(
Happy coding
Woz