• Register

Combining Lego like bricks with Minecraft mechanics

Post news Report RSS Devblog 8 - Crafting system

Another important part of this type of game is being able to combine multiple items to create new ones and Brickcraft will not be less. Unfortunately this update is more of a hassle, since there is little calculation and a lot of code, although I have tried to show the minimum.

Posted by on


Another important part of this type of game is being able to combine multiple items to create new ones and Brickcraft will not be less. Unfortunately this update is more of a hassle, since there is little calculation and a lot of code, although I have tried to show the minimum.
Starting with the UI I'll do something super creative again and never seen before:


With the easy part done, it's time to go to the code.
We have to create the data structure of the recipes, which should contain the id of the item to be created, the amount of and the necessary ingredients. For the ingredients we will have another structure, since we cannot recycle any existing one, as at first we would think that it is only the item and the quantity, but we are forgetting the slot, since to craft objects we will force to put them in a certain order/position.

No sooner said than done.
We will also have to write down the recipes somewhere of course.


The first recipe of the game will be to combine 2 bricks of 2x2 to generate one of 2x4.
Now we need to get back to the UI. The 4 crafting slots will be different from the inventory ones. Player must be able to put items there but not get them back into inventory. To discard them, you can drag them out of inventory.
Every time you drag an item into a crafting slot, we will have to iterate over all the recipes to see if you can craft any of them.
Here we can do some tricks to go faster, such as looking to see if the total of items that have been put, fits with the total of ingredients in the recipe.

When we find a recipe that you can craft, we will present it to you visually and in case you drag the item into your inventory, we will proceed to remove all the ingredients and add the new object.

We will also update the UI, to reflect if it has run out of some material or at least show how much they have gone down.
Outcome:


I should also block the camera because it is a bit wtf to see it moving while you are looking at the inventory xD

Post comment Comments
Guest
Guest

This comment is currently awaiting admin approval, join now to view.

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: