Pages

Thursday, June 9, 2011

Have a happy inventory!

Do you like inventories? Oh, I know you do. Because everybody does. It's a shame though that in the last few years, probably in a misguided attempt to make RPGs more accessible to console players, many games feature bothersome lists of objects you have to endlessly scroll through to find the desired item. Better take a look at the awesome inventory from Deus Ex:


My absolutely favorite kind of inventory: a grid of cells, with bigger objects eventually taking up more space than just one cell. It just feels right to me. Now you might not share my preference on this, but let me roll a bit with it as I try to talk briefly about including such a feature in a Construct project.

Obviously when you think of a grid of cells, you might as well think of an array. The above picture represents an array of 5 x 6 cells. To make this perfectly clear take a look at the following image:

You can see the array properties and a visual representation of that array. All cells have the value 0 by default and it's the same size as the example inventory from Deus Ex. Now how does this help creating the actual inventory?

Think of the array object as the logical construct behind your actual visible inventory the player will interact with. You could create your inventory grid by means of a tiled background sprite and resizing it according to the inventory size.


This event example uses a cell size of 32, simply multiplied by the X and Y dimensions of the array result in a properly sized grid. In case the image of your tiled background object is an actual grid cell, of course.

When you think further the array has a 'For each element'-condition, which loops through every cell. This is perfect to automatically place items in the inventory. You could simply check for an overlap to test if the current cell is already occupied. And keep placing the item within the loop until it doesn't overlap.

I already posted a cap example of this basic but yet effective functionality on the official scirra forums a while ago (link). In the meantime I made an improved version of this, with stackable items, better drag and drop and worked out some minor quirks. With no game project to actually use it in, the thing kind of rests dormant on my hard drive.


Just recently my mind feels overwhelmed by a little inventory madness again, creating one by the means of more advanced methods and plugins. To set myself a bit at ease I had to write this blog article up, which mainly goes along as a little explanatory text to my original example.

In case you expected this to be an indepth inventory tutorial I do apologize. Hopefully this will still prove worth reading to some Construct users, especially those who struggle to make any constructive use of the array object.

3 comments:

  1. Pretty handy! Still trying to figure out the events. I thought it would be much more complicated than what the cap contained. Matter of fact, I have no idea how it's working in your cap. It seems TOO easy, if that makes sense. I just imagined it having a lot more math when I work it out in my head.

    ReplyDelete
  2. Someone seems to be Deus Ex fan :P Waitin for the new one?

    ReplyDelete
  3. Really,it's very impressive and you have great idea.
    Waveguide Adapter

    ReplyDelete