First, the hotbar:
Woo, hotbar! Now I can kinda sorta see what item I have selected for use. Well, once I get more icons in, at least. The code for this is a little hairy. Specifically for the player's inventory, any time the inventory is updated I split it into two arrays-- one for the hotbar, and one for the rest of the inventory. These two arrays are used solely for updating the GUI, so I don't have to do any weird swapping around when it's time to let the player move things between them. And as the gif shows, everything gets visually updated correctly when you place down or pick up an item.
I've also started on functionality to let the player pick up blocks again once they've placed them. Right now, the player can pick them up by hitting them with the mattock three times. This one I'm kinda proud of-- I added a little "decay" timer for the counter that tracks how many hits a block has received, so they'll have to hit it three times in a 10-second window to actually pick it up. This is in case the player just hits it by accident every now and then, like I am prone to doing in these sorts of games.
My future goals for item dropping involve an intermediary step, where the object is dropped into the world as a floating item the player can choose to pick up by either clicking or walking over it instead of just automatically cramming it into their inventory. I haven't picked which method to use yet, but I'm leaning towards walking over to avoid adding too-specific of controls to the interface. I'll have to sit down and map this feature out before I can really get started on it, regardless.
In addition to these features, I've done some light refactoring and code clean-up during the times when I want to work but can't really get anything big done. I reworked my inventory manager class to hold an array of inventory items instead of just game objects, which improves readability by getting rid of lots and lots of "get component" calls everywhere. I also did a little code review with a good friend who reminded me that lambda expressions are scary but also beautiful, so a few of my functions have been reduced in length by a good 75% or more. There's still a few messy spots left to clean up, but they'll also be affected by the item dropping feature, so I'll wait and scoop them up with the rest of the carnage that will likely leave behind.
In the meantime, my "tech debt and bugs" list on Trello has had a few more cards added to it in the past few days, so I should probably get the more urgent of those knocked out before I really get going on any "big" features.
No comments:
Post a Comment