I've Built a Hoarder's Paradise (Inventory & Collection) | BYOND Game Development #2

< Missed the first part of the series? Catch up here!

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.

inventoryandinfo.png

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:

additemscode.png

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:

inventory.png


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.

resources.png

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:

getanddrop.png

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.

crabgrasscode.png

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.


Staying informed.

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.

infowindow.png

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.

Thanks for reading!

Advertisement:
1607931559_lnq5YxO1.webp

followsweeney2021 (1).gif

sirsweeneysolutionsbanner (1).png

Sort:  

I do enjoy hording things in games. Can never have big enough inventory and bank space.

!PIZZA

Connect

Trade


@thatsweeneyguy! I sent you a slice of $PIZZA on behalf of @enjar.

Learn more about $PIZZA Token at hive.pizza (1/20)

This game will definitely have limits on inventory space and how much weight a player can carry, but that's what chests are for! 🤣

Nice job, looks good :)

!PIZZA

Connect

Trade


@thatsweeneyguy! I sent you a slice of $PIZZA on behalf of @dksart.

Learn more about $PIZZA Token at hive.pizza (7/10)

Thanks! I've even still got this fancy thing from the first time I was building this 😁

2FFvzA2zeqoVPgRCnRzbu79fYh1Svf3mN2MBPH8MkpyugYcJ8ZSQEqvSnQtpNtmynK6yw2YXGz3M8GF4cVSwFYEz4HiHzuRGaFEzxVVcJWdzhMe6Cp66U9VKkskop.png

Nice! If you need other artwork just let me know :)

!PIZZA

Connect

Trade


@thatsweeneyguy! I sent you a slice of $PIZZA on behalf of @dksart.

Learn more about $PIZZA Token at hive.pizza (8/10)

Awesome! Appreciate the time and effort you put into your game project, earn more when you post on our platform simply by using the recommended tags #build-it #buidl.

Let's keep building and adding value to the world :)


The rewards earned on this comment will go directly to the person sharing the post on Twitter as long as they are registered with @poshtoken. Sign up at https://hiveposh.com.

Your content has been voted as a part of Encouragement program. Keep up the good work!

Use Ecency daily to boost your growth on platform!

Support Ecency
Vote for Proposal
Delegate HP and earn more

Congratulations @thatsweeneyguy! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You distributed more than 100000 upvotes.
Your next target is to reach 105000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out the last post from @hivebuzz:

Hive Power Up Day - August 1st 2021 - Hive Power Delegation