My game is starting to look like a... game!
You still can't do much, but you can do something, and that's a start.
I've been fleshing out more of my new game project and have put together systems for collecting items from the game map and keeping track of them in a separate inventory window. I've also put in place the first "static" element to the GUI which is a simple output box for notifying the player of certain events like when they collect an item.
It's all very rudimentary for now but I'm a firm believer in the KISS (Keep It Simple Stupid) philosophy. I'd rather build slowly and make sure something works right than to create a bunch of intricate and unnecessary details upfront and have to weed through piles of bugs later to get them all working together. I feel like programming is a lot like a game of chess - If you're not constantly looking at least a few steps ahead, you'll end up digging yourself into a hole you may not be able to easily work your way back out of. I did break this rule a couple times so far which I'll point out when the time comes, but they're pretty simple and harmless "extras" that won't conflict with anything else later.
In this post I'll explain what I've added to my "game" and go over some of the code to show you how I made it work. For any aspiring developers who may stumble across this, I've written comments explaining what each line of code does. While BYOND uses a native programming language called DM, it's similar in many ways to languages like C+ and Python.
Somewhere to put things.
BYOND comes with built-in variables for holding information about what a player possesses, but without a way to display the "contents" of a player, the data in that variable doesn't do us much good. I've set up a separate window that will hover over the game map containing a grid to display items. The window is "hidden" when the player starts the game, but I've created a shortcut so that it can be opened/closed using the 'E' key.
Now that I've got the infrastructure for the inventory set up, I have to write some code so that the different elements get updated when items are added to the inventory:
The above code only gets run when the inventory window is open and needs to be refreshed. If the inventory window is closed while the player is collecting items, there's no need to update the contents of a window you can't see. I'll simply call this code when the inventory window is first opened, or when it's open and something inside needs updated. In its current state, the inventory window looks like this:
Something to collect.
I've defined a couple items that players will be able to gather when they start the game, branches and plant fiber. One can simply be picked up from the ground, but the other must be collected from the environment.
In the image above, you might notice that the two tufts of Crabgrass look different. This is the first time I broke the KISS rule. Just like the trees that get generated in the forests, when a new Crabgrass object is created, I generate a random number and use it to define how each one looks when it appears.
For items that can be collected directly from the ground, I'll need to write some code to allow the player to pick up and drop items:
Making some items "stackable" is the second time I broke the KISS rule. I could have simply made it so that each item you pick up gets added to a new cell in the inventory, but I know I'll have to add this feature in before I can write the crafting system (which comes next), so it was easier to go ahead and implement stackable items.
I have to make sure that every time an item is added or removed from the inventory, I check to see whether the inventory window is currently open and if it is, it needs to be updated to reflect the changes.
Branches can spawn around trees in forests and are generated at runtime. These can just be picked up but in order to get plant fiber, you'll need to gather it from the Crabgrass that spawns in the grasslands.
When the player is close enough to a tuft of Crabgrass, they can click it to gather some plant fiber. Just like picking up items, I'll need to make sure I'm checking for an existing plant fiber item in the player's inventory and update the window. From here, the Get() and Drop() verbs will work on the newly created plant fiber item and the Crabgrass on the ground gets deleted from the map.
Looking back over the code, you might see that whenever an item is gathered, a message is sent to the player letting them know what happened. That's nice and all, but where are those messages supposed to be displayed? The final step for now was creating a simple 'output control' to handle messages sent to the player. This exists as a small rectangle in the bottom-left corner of the screen.
Adding the little stone frame around it was the third way I broke the KISS rule. I didn't just want a static grey box floating on the screen looking weird so I made it pretty. This simple little box will display messages any time the player needs to be informed of something like picking up an item.
Writing this post and looking at that screenshot, I notice I need to go back and reword those messages to be more uniform and informative, but I'll let future Sweeney deal with that.
If you enjoy hoarding grass and sticks, I've got the perfect game for you!
I said this a few times in the last post, but I'm still having a ton of fun developing a game again! It may not be much of a game, but even to have what I do makes me excited that I'm still able to turn a few words and numbers in the right order into something people can interact with and be entertained by.
My next goal is to flesh out the start of a crafting system that will let players combine the items the collect in the world into tools and other useful items. Once I have all that set up, it'll be time to start adding some challenge to the game with a simple battle system, pitting the player against wild animals that will spawn in the different biomes I laid out in the beginning.