Storing Items with different size (Inventory)

1 favourites
  • 9 posts
From the Asset Store
220 Food Sprites in 16x16 pixel size. Perfect for items for a retro style game.
  • Well, I've made an inventory system like this image and my code is just like the inventory example on construct 3 start page

    Right now, I want to make an inventory which can store items with different size (like the below image), but I have no idea what should I do and how can I handle this with arrays?!

    I would be thankful if you guys explain what should I do or share an example file

    Tagged:

  • The way I would do it would be to know the size of the object and if it's 1x1 then it goes into the co-ords that you click but if it's 5x2 like the rifle there then you could get the starting co-ord and make sure they're all blank 5 across and 2 down from the starting point, then if so you would fill in all those array slots with the rifle item.

  • The way I would do it would be to know the size of the object and if it's 1x1 then it goes into the co-ords that you click but if it's 5x2 like the rifle there then you could get the starting co-ord and make sure they're all blank 5 across and 2 down from the starting point, then if so you would fill in all those array slots with the rifle item.

    Thanks for your response

    I worked on it for a few hours but it seems it's little bit much harder than I thought

    I would be appreciated if someone could share an example file

  • Did you understand the first file you copied and how arrays work though? The problem with copy and pasting from files is you might not know what's going on so you need to understand it for when you encounter bugs.

  • Did you understand the first file you copied and how arrays work though? The problem with copy and pasting from files is you might not know what's going on so you need to understand it for when you encounter bugs.

    Yes totally

    This is my project you can take a look if you don't mind

    MY_INV.c3p

    my project also has an array which reads data from json then spawn the item sprite in the SLOT (if you check project file you can easily understand) but I also don't know how I can say spawn an item which fills several elements in correct postion like this picture

  • Here's one possible solution.

    For each of your items you'll want to store a "mask" of what squares it occupies within it's rectangle. So for a gun it could be:

    1111
    1000

    So when you drop an item into an inventory you'd only need to see if the 1 places were unoccupied as well as inside the array. If all the 1 were then you could then place the object in the inventory.

    Here is an example without arrays, although you could certainly use arrays instead. I'm just using "is overlapping point" instead of an array lookup. It handles placing and removing items, as well as throwing them out if they are placed in an invalid spot. Perhaps some of the ideas here are useful.

    dropbox.com/s/tpwx74fq1c43auc/Fit_shapes_into_slots.capx

  • Here's one possible solution.

    For each of your items you'll want to store a "mask" of what squares it occupies within it's rectangle. So for a gun it could be:

    1111
    1000

    So when you drop an item into an inventory you'd only need to see if the 1 places were unoccupied as well as inside the array. If all the 1 were then you could then place the object in the inventory.

    Here is an example without arrays, although you could certainly use arrays instead. I'm just using "is overlapping point" instead of an array lookup. It handles placing and removing items, as well as throwing them out if they are placed in an invalid spot. Perhaps some of the ideas here are useful.

    https://www.dropbox.com/s/tpwx74fq1c43auc/Fit_shapes_into_slots.capx?dl=1

    THX, I'm going to see if I can implement it with array or not

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Try and download this it may help you

    https://www.construct.net/en/free-online-games/tetris-inventory-41808/play?via=c18

    Awesome!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)