Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a series of guns in my game. I use the Gun class/object like this:

(Just an example)

@interface Gun : NSObject
{
    NSString *name; // Six-shooter
    NSNumber *cost;

    NSNumber *clipPrice; // ie: 700
    NSNumber *clipCapacity; // 6
    NSNumber *ammoCapacity; // 6


    NSNumber *damage;   // 0-10

    NSNumber *accuracy; // 0-10
    NSNumber *fireRate; // 0-10
    NSNumber *range;    // 0-10
    // Not sure if I have all the stats, but this is fine for now        
}

Lets say I want to have 3 upgrades per gun. My problem is I am not sure how to do this.

Examples:

  • increase fire-rate
  • increase range
  • increase accuracy
  • silencer
  • double ammo capacity (ie: Drum)
  • double clip capacity (ie: Taped magazine)

Thus my question is, I'd like to implement an upgrade system to guns but I am not sure how to do it.

Would there be an Upgrade object which is a child to the Gun class, or would it be seperate class altogether.

Thanks for your time.

share|improve this question

1 Answer

up vote 2 down vote accepted

Not knowing much about your particular game, telling you what numbers to increase with an upgrade (or by how much) is a bit useless. You'll have to decide on that yourself, I'm afraid.

As to how to handle upgrades, The simplest way I can think of to do this is to turn every NSNumber into an array, and add a new attribute "UpgradeLevel". Then, whenever you need to get an attribute from your Gun, you go to, for instance:

id damageValue = [damage objectAtIndex:UpgradeLevel];

To handle things that simply add new features, you can make an array of bools that will then return true or false depending on the upgrade.

share|improve this answer
This seems reasonable and very simple. I have accepted your answer. Thanks – zardon Jul 9 '12 at 5:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.