Buy Somethin’ Will Ya?

Over the past week, I’ve done a lot of code work for the shop system. Using the universal cursor system I made last week, plus the Shopcounter object from the week before, I’ve put together all the menus necessary for the player to speak to the shopkeeper, select an item to buy, confirm that they want to buy it, obtain the item (if they have enough money), and finally decide if they want to purchase anything else, or leave. In this post I’ll go through the current functionality state by state, and explain what’s happening at each step of the way.

Player approaches the Shopcounter.
The class definition of the Shopcounter object with which the player interacts.

First, the player approaches the Shopcounter object and presses the button to interact with it. This functionality was added in a previous update, but the basic summary is this: Player presses Enter, we check if an entity is adjacent to the Player in the direction they’re facing and what type of entity they are, in this case they’re a Shopcounter, so we run the shop() function.

The Shopcounter presents the player with the list of items to buy.
The shop() function, within the Shopcounter class, which begins the shopping process.

After the player presses Enter again to advance beyond the initial dialogue, the shop() function displays their total Teeth count at the top of the screen (Teeth being Goblin Hero’s version of Gold), and a list of items for sale at the vendor, along with their prices. The item names and their prices are stored as two lists. We iterate through the two lists, and use a simple linear equation to tell the function where to display the names and prices on the screen. We then call the buy_an_item() function, which takes it from here.

The buy_an_item() function reminds the player which item they’ve chosen, and its cost.
The buy_an_item() function, which handles this step, and several coming up.

Buy_an_item() calls the cursor_system() function to allow the player to actually choose an item to buy. Buy_an_item() does some work under the hood to retrieve the price of the chosen item, and repeats it to the player. It then calls a new function, which exists outside the Shopcounter class: yes_or_no().

The yes_or_no() function presents a simple “yes or no” prompt to the player.
The function responsible for the “yes or no” prompt.

The yes_or_no() function is a pretty basic, universally-applicable prompt that utilizes the cursor_system() function like any other menu, and returns the selection.

The second “Yes or no” prompt, to choose if the player needs “Anything else.”

If the player chooses “yes,” buy_an_item() checks to make sure they have enough Teeth (Gold) to buy the item. If they do, the item is added to the player’s inventory, the Teeth are subtracted from their total, and then the Shopcounter asks the player if they need anything else. If the player chose “No,” we skip to the “Anything else” prompt.

The “not enough money” response.

If the player chooses an item they can’t afford, we give them a different response, don’t proceed with the purchase, and give them the “Anything else” prompt. If the player chooses “No” to “Anything else,” the Shopcounter thanks them and we return to walking around on the Overworld.

The entire process of buying an item, from start to finish.

This shop system is not finalized, as it still needs functionality to sell items from the player’s inventory, among a few other minor things, and the code needs to be cleaned up in a few ways, but this basic system of buying an item now works, end to end.

One thought on “Buy Somethin’ Will Ya?

Leave a comment

Design a site like this with WordPress.com
Get started