Grid Based Inventory System

I’m trying to create a grid based inventory system similar to Resident Evil 1-4 (picture seen here).

I honestly have no idea how to go about doing this. I’m not very good with tile based games in general (haven’t dabbled with them much), so that may be part of the problem.

I’ve started off by thinking about creating a bi-dimensional array the size of my inventory (8x5), but from there I’m pretty clueless. I don’t know how to get my “items” to lock into the spots and I’m only a little sure on how to let the array know which spots are being held up by items and which are free.

I don’t expect full code for this, that would be asking a lot. Maybe some theory pointers, tutorial resources, or a little code snippet to get me started would help a ton. Thanks in advance and I hope you all can help me =). I hate being a noob!

Here’s a couple of ideas to get you started.

First, maintain a dynamic container (e.g. List) that stores the items in the inventory. (The type of the items themselves could be a custom data-driven class, a class derived from a base ‘item’ class, a class derived from MonoBehaviour, etc.)

Then, you have your 2-d array. The element type for the array is the same as that of the inventory list; in other words, each cell in the array stores a reference to an item. If the cell is unoccupied, the reference is null.

When an item occupies more than one cell, each occupied cell points to that item. For rendering purposes, you could (for example) render the image representing the item from the top left, starting at the top-left corner of the top-left-most cell that references the item. Implementation-wise, you could iterate over the cells top-to-bottom and left-to-right in a nested loop, and at each cell, render the associated item, but only if it has not already been rendered. (You could use this method, for example, if you were using the built-in GUI system.)

There’s more to it than that, of course, and if bin-packing is involved, the implementation could get a little involved. But, the above should at least give you a basic idea of how such a system might work.