RPG inventory HowTo

Posts: 6
Joined: 2011.05
Post: #1
I'm in the midst of designing an RPG more specifically the inventory portion. I'm not quite sure how I should design the system and how to create the items. Should I make a separate class for every item or should I create some sort of type system and value system? I am programming this in objective-c for the iPhone using cocos2d as an engine.
Quote this message in a reply
Posts: 472
Joined: 2008.04
Post: #2
Good question, shadowgate. I've gone both ways in my games, and I've tried mixes of the systems as well.

The disadvantages and advantages of each depend on your specific situation and your game.

If you want the user to be able to create new items, edit existing ones, or expect to have external editing tools, you'll probably be forced to create a single Item class, and define all the behaviors using various flags and values set on instances of items.

If your items have a lot of diversity in their actions- where you expect to have each unique item have a block of code associated with it, the one-class-per-item approach might be easier.

People who are really gung-ho about object oriented development and overengineering systems usually favor the separate class per item, cause you can have nice deep inheritance hierarchies: Item > PickupableItem > Food > CookedFood > Bacon. Sometimes this can save you some coding, since a lot of non-specific details can be inherited. I find it a bit overkill though.

If you're expecting a lot of similar items, you'll probably do pretty well just with an itemType flag and a few values to control what happens with each type of item.

Especially for an iOS game, you'll want to do whatever's simpler in your solution. Scott and I have found that hardcoding game specifics is a big time saver over writing our own loading systems. No one other than us will touch the code anyway, and it's easier to be expressive in code than in a flatfile.

Howling Moon Software - CrayonBall for Mac and iPhone, Contract Game Dev Work
Quote this message in a reply
Posts: 6
Joined: 2011.05
Post: #3
awesome. Thank you for the quick response. I will hopefully start that tonight or tomorrow. First I need a saving function using NSCoder. I think I might take the object-orientated path since I think better that way because I first learned programming through java.
Quote this message in a reply
Posts: 39
Joined: 2002.04
Post: #4
Why not let every item be a dictionary of features where each feature deals with some kind of aspect of items e.g. their use as; weapon, key, food, carrying properties like weight/size/"does it float on water" ... etc. Each feature could be implement by one or more classes.

This avoids having a single big inheritance graph where a item -> weapon -> sword can't have features of item -> food - making it impossible to e.g. create edible swords.
Quote this message in a reply
Posts: 916
Joined: 2002.10
Post: #5
(May 26, 2011 03:48 PM)hokan Wrote:  making it impossible to e.g. create edible swords.


Anyways, your methodology is what I personally have done for my RPG
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  A Crafting/Inventory System [Terraria?] jwei92 6 12,962 Jul 30, 2012 03:18 PM
Last Post: jwei92