Thread: Weapon Organization

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    10

    Weapon Organization

    I am creating a game with several others and am putting myself on a crash course on C++ game design. I made a post in the Project forums. I have most of the basic skills and a very simple idea of AI. I want to know the best way to hold data about different items of the same general type. Would a class or a structure be best?

  2. #2
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    If you are not going to use functions, use a structure method. But as you are using C++ you really should shy from structs and implement a class. Remeber to make the data members private or protected if you are going to use inheritence, and the member functions public

  3. #3
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Yes, use classes! For weapons, I would have a base class of sorts. For example, a possible class hierarchy may be:

    Code:
    CItem 
    
    CWeapon   CPowerUp
                             
    CBow      CHealth
    
    CSword
    All items inherit from CItem base class, CWeapon and CPowerUp inherit from this base class. Each type of weapon will inherit from CWeapon. Each type of power up inherits from CPowerUp. This is just a possible hierarchy. Take some time to plan this part, because it will save you lots of code writing. Plus, try to organize these such classes into header files, for MAXIMUM organization!

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Using class hierarchies for the different items and characters works for small projects. Larger projects should use an entirely data-based approach, i.e. there is an Item class, and all info about it (is it a weapon, shield, armor, ...) is stored in data files and loaded at runtime. This calls for a very flexible interaction system, especially if you want some special items, which is why only large projects do it this way.

    Blizzard's Diablo games are a wonderful example: they can define almost any kind of item using only data files.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    10
    Thanks for your input! Classes seem the better choice. I am in the process of implementing some classes now

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    903
    Would a class or a structure be best?
    I am surprised no one noticed this question... They are *exactly* the same except that classes default to private and structures default to public.

  7. #7
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    I believe the OP meant if a class or a struct would be best when compared to other options. At least that's how I read it back then
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Using class hierarchies for the different items and characters works for small projects. Larger projects should use an entirely data-based approach, i.e. there is an Item class, and all info about it (is it a weapon, shield, armor, ...) is stored in data files and loaded at runtime. This calls for a very flexible interaction system, especially if you want some special items, which is why only large projects do it this way.
    The solution I would use.

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by swgh
    But as you are using C++ you really should shy from structs and implement a class. Remeber to make the data members private or protected if you are going to use inheritence, and the member functions public
    Structs and Classes are identical in C++ except for their default access. Structs default to public; classes to private. Other than that they're exactly the same.

    Well, except for spelling.

    [edit]
    Quote Originally Posted by Desolation
    I am surprised no one noticed this question... They are *exactly* the same except that classes default to private and structures default to public.
    I suppose I could always read the entire thread before posting.

    Nah.
    [/edit]


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generalising methods to handle multiple weapon types
    By Swarvy in forum Game Programming
    Replies: 2
    Last Post: 05-22-2009, 02:52 AM
  2. Weapon combo selection
    By Hunter2 in forum Game Programming
    Replies: 19
    Last Post: 08-21-2002, 03:25 PM
  3. Recruiting members for game development organization
    By Ruflano in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-18-2002, 07:20 AM
  4. Recruiting members for C++ organization
    By Ruflano in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2002, 09:44 AM
  5. Recruiting members for game development organization
    By Ruflano in forum Game Programming
    Replies: 1
    Last Post: 02-16-2002, 04:53 AM