Inventory, how to make cells 'bigger'.

Hi there JGO,

currently I am working on the Inventory. I had an idea to make some items bigger then 1 cell:


http://img571.imageshack.us/img571/6001/0af8.png

But if you can see it is only rendering a bit of the item. I had some ideas to make a few variables, and then just try things out. But it doesn’t seem to work that good. The only part that was good is the selection of multiple Cells:

   public List<Integer> biggerCell() {
		List<Integer> cells = new ArrayList<>();
		for(int x = 0 ; x < item[0].getWidth(); x++){
			for(int y = 0 ; y < item[0].getHeight(); y++){
				cells.add(this.x + x + (this.y + y) * maxWidth);
			}
		}
		return cells;
	}

So my question is: Are there any tutorials on how to make cells that are ‘bigger’ than 1 cell?
Or if you have any ideas, just post them and I will do something with it! (Please do not post any codes, I am still learning and it is not learning if I am copying stuff).

Thanks already!
-RoseSlayer

So basically you want to make some “cells” bigger than the rest? I kinda don’t really understand what you want to achieve. You want to keep some cells at size x, and make some others of size 2x ?

I don’t want to make the cells bigger, but the items in the cell are bigger then the cell, so it needs to look like the cells has become bigger example:

As you can see here, some items are bigger then 1 cell.

-RoseSlayer

I’m not entirely sure about your code, but in my RPG attempts the items have a “inventory size” in cells. They can cover e.g. 1x1, 2x1 or 2x6 or whatever amount of cells.

Your code must take care of the item size, and display the items correctly in/over the inventory grid.

First a bit of abstractcion:

-you have a collection of Items,
-these Items have different “sizes”
-you have an Invetory with a dimension (grids)
-each item has a position in this grid.

I would first define for each item-class what size it is (1x1,1x2,2x2 etc)

the inventory should have:
-a list of items it contains
-a grid (2-dimensional int matrix)
now when dropping the stuff into the inventory GRID, you give each item a position,
best is to use the upper left corner as the “ancor”.

when dropping an item into the inventory:
-> search trough the inventory-grid if there is for example a 2x2 space free,
-if yes, position the item there,
-let the inventory-list remember the ancor x,y position and item id,
-mark in the grid the used 2x2 space also with the item-id.

the item-ids on the Grid also are useful to check wich item is beeing clicked by the mouse-click …

when removing the item,
remove it from the list, and empty the grid (put a 0 there for example)


also offer a function to “sort” the inventory (removing all items, then adding fist the large, then the smaller items)
I hated that about Diablo, that it was missing such a function.


for then rendering:
when displaying the items, you just need to go though the list of items and start rendering at the ancor position (top left)

Thats how I would approch it

Thanks, going to work on it!
-RoseSlayer

Thanks for the help, as always!

This is the finished product:


http://img20.imageshack.us/img20/4829/so8d.png

-RoseSlayer

+1 For working it out yourself :wink:

Just an idea. Do not remove the horizontal line for the 1x2. I think it looks better by keeping the lines. More consistent.

I personally think it would look very weird with the line still there because it just doesn’t fit in the spot. The other thing you could do is create a miniature version of the texture and just use that instead. I think that would work better mechanics wise.

What do you mean with the miniature version, the items that you can see in the inventory are already size *2
& thank you for the +1 8)

-RoseSlayer

I meant reduce the textures down so that they fit in a single inventory slot. It just looks odd when your items span multiple slots, but that’s just my opinion!

I think the idea is larger items use more slots - so a little bag of coins takes one slot, but a double-handed broadsword might take three.

It’s a very old way of representing the weight/bulk of items - I recall seeing it as far back as the original UFO games in 1994. It’s probably older.

Yeah, that is actually an interesting way of dealing with limitations on the inventory size, it just really makes me crazy because its not all uniform! I feel like I have to fix it and make everything the same size :stuck_out_tongue:

If you look at it as an arbitrary choice, then equal size items make sense. If you look at it as a form of resource (space) management, it adds an extra level of strategy/complexity to a game.

Oh, don’t get me wrong I like the idea of it to limit the number of items you can carry, its just I like things because uniform sizes!