Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  RPG inventory  (Read 866 times)
0 Members and 1 Guest are viewing this topic.
Offline Christopher

Full Member
**

Posts: 108
Medals: 2



« on: 2012-02-03 05:07:29 »

How would one go about implementing this?

Think wow style loot window full of boxes and an inventory full of boxes. When you click an item it hovers below your cursor until you drop it in a slot again.

Thanks guys!

Offline theagentd

JGO Wizard
****

Posts: 1392
Medals: 88



« Reply #1 on: 2012-02-03 05:25:56 »

Keep an array of Items. The mouse also has a single Item slot. When an Item in the bag is clicked swap it with the mouse Item slot. Done! =D

There is no god.
Offline Christopher

Full Member
**

Posts: 108
Medals: 2



« Reply #2 on: 2012-02-03 06:41:44 »

Would each item be an object and the array an object array?

Games published by our own members! Go get 'em!
Offline theagentd

JGO Wizard
****

Posts: 1392
Medals: 88



« Reply #3 on: 2012-02-03 08:04:17 »

You would make an Item class, and have all other items subclass that class. Then you can define your Item array as simply
1  
Item[] inventory = new Item[INVENTORY_SLOTS];

There is no god.
Offline Christopher

Full Member
**

Posts: 108
Medals: 2



« Reply #4 on: 2012-02-03 08:31:02 »

You would make an Item class, and have all other items subclass that class. Then you can define your Item array as simply
1  
Item[] inventory = new Item[INVENTORY_SLOTS];


Thank you! This seems like a solid plan of attack.

Offline gerard_pp

JGO n00b
*

Posts: 31
Medals: 1



« Reply #5 on: 2012-02-03 13:32:47 »

Hello

You can assign each item with an unique id, and make an item array. Visually make all the elements of your inventory draggable, and with the "snap to its box container" ability. Make sure you have a thumbnail for each of your elements in a library, and name them with the id assigned. That way, you can make a "for" loop to place all the pieces of elements on each container, just as your array is organized.

Good luck.

Warning: Plz, excuse my bad english...
Offline theagentd

JGO Wizard
****

Posts: 1392
Medals: 88



« Reply #6 on: 2012-02-03 15:13:49 »

Hello

You can assign each item with an unique id, and make an item array. Visually make all the elements of your inventory draggable, and with the "snap to its box container" ability. Make sure you have a thumbnail for each of your elements in a library, and name them with the id assigned. That way, you can make a "for" loop to place all the pieces of elements on each container, just as your array is organized.

Good luck.
Why would he need an ID for each item? If he wants to draw all the Item icons, just do something like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
private static final int INVENTORY_SLOTS= 30;

private static final int INVENTORY_COLUMNS = 6;

private Item[] inventory = new Item[INVENTORY_SLOTS];

...

for(int i = 0; i < INVENTORY_SLOTS; i++){
    if(item[i] == null){
        continue;
    }
    int slotX = i % INVENTORY_COLUMNS;
    int slotY = i / INVENTORY_COLUMNS;
    drawImageWithSomeLibrary(
            items[i].getIcon(), //Image to draw
           inventoryWindowPositionX + slotX * SLOT_WIDTH, //x coordinate
           inventoryWindowPositionY + slotY * SLOT_HEIGHT //y coordinate
   );
}

There is no god.
Offline Matthias

Jr. Member
**

Posts: 71
Medals: 2


TWL - Themable Widget Library


« Reply #7 on: 2012-02-03 18:02:09 »

I have a Inventory Demo which shows 4 gems which you can drag around. The source code is available on my site.
Offline UprightPath

Full Member
**

Posts: 214
Medals: 9



« Reply #8 on: 2012-02-03 18:15:05 »

Well, it depends on where the item is getting stored, etc. An Item ID can make storing things on  DB easier, or if the item IDs are semi-permanent, could make the save foot print a bit smaller by just needing item_id x number_of_items to describe each slot.

I am filled with despair... About how far people think about ideas they propose, about the state of my teams in classes when people do not understand what an assumption is...
Offline SwampChicken

Full Member
**

Posts: 199
Medals: 1



« Reply #9 on: 2012-02-05 23:29:39 »

ps: Don't forget that mission quests can be done by making then 'invisible' items in your inventory.
Games published by our own members! Go get 'em!
Offline pitbuller

Sr. Member
**

Posts: 340
Medals: 9



« Reply #10 on: 2012-02-06 01:49:54 »

Item Interface would be better than Item abstract class. Then you can have Super class like Sword, Potion, Scroll.

Offline Christopher

Full Member
**

Posts: 108
Medals: 2



« Reply #11 on: 2012-02-06 08:12:01 »

Thank you for the amazing example and code Mathius this will definitely help in creation!

One thing i didnt mention is that items will have various random statistics and abilities (think diablo). This would render an item ID fairly redundant as each item is unique.

Im still fleshing out a flow chart but what I have in mind so far is,

abstract class Item
subclass Weapon
subclass Armour
subclass Ammo
subclass Bag
subclass Scroll or Book
subclass Resource
subclass General

Each subclass contains a rightClickAction method and various other methods and variables unique to its type. All the items will feature two constructors one with arguments dropLevel and dropQuality for generating the item randomly then another constructor that sets all the stats of the weapon so objects may be recalled from a saved game. Inventory will be an item array that stores these items and the GUI will simply move these around within the array.

Now, good in theory...

Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.128 seconds with 21 queries.