Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  RPG inventory  (Read 3021 times)
0 Members and 1 Guest are viewing this topic.
Offline Christopher

Senior Member


Medals: 2
Projects: 1



« Posted 2012-02-03 10: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
« Reply #1 - Posted 2012-02-03 10: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

Myomyomyo.
Offline Christopher

Senior Member


Medals: 2
Projects: 1



« Reply #2 - Posted 2012-02-03 11:41:44 »

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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2012-02-03 13: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];

Myomyomyo.
Offline Christopher

Senior Member


Medals: 2
Projects: 1



« Reply #4 - Posted 2012-02-03 13: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

Junior Member


Medals: 1



« Reply #5 - Posted 2012-02-03 18: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
« Reply #6 - Posted 2012-02-03 20: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
   );
}

Myomyomyo.
Offline Matthias

Senior Member


Medals: 3
Projects: 1


TWL - Themable Widget Library


« Reply #7 - Posted 2012-02-03 23: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
« Reply #8 - Posted 2012-02-03 23: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.

Offline SwampChicken
« Reply #9 - Posted 2012-02-06 04: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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pitbuller
« Reply #10 - Posted 2012-02-06 06:49:54 »

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

Senior Member


Medals: 2
Projects: 1



« Reply #11 - Posted 2012-02-06 13: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]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (18 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (70 views)
2014-08-11 02:49:23

BurntPizza (47 views)
2014-08-09 21:09:32

BurntPizza (37 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!