Announcement

Collapse
No announcement yet.

Thoughts on setting up multiple types of weapons (melee, ranged, throwables)?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Thoughts on setting up multiple types of weapons (melee, ranged, throwables)?

    I've only done one so far. I have a weapon class. Now I wonder, how to handle different types of weapons? Do I subclass the main weapon class, or do I create another class entirely?
    I think, It's no use subclassing the base weapon class (which has code to accommodate ranged weapons) for a melee weapon. It would be a lot of code duplication that wouldn't be used at all by the melee weapon. Same goes for throwables and remote explosives etc.

    Also the character should be able to switch between different types of weapons, eg switching between melee axe, ranged rifle 1, machine gun ranged, melee hammer, grenade, remote explosives etc.

    What would be a smarter way to go about this?

    #2
    Split your weapons. WeaponBase should only have common functionality between all weapons (Like ActivateWeapon, DeactivateWeapon, setowner, attach to player) that kinda stuff. Then you have Weapon_Ranged, Weapon_Melee, Weapon_Tossable, etc. which override functions inside the WeaponBase, like override ActivateWeapon to do something different if its a Ranged weapon or a melee weapon for example.
    Game Programmer - Working for a Indie Studio.

    Visit my blog: TheGamesDev

    InterKaos Games

    PC Specs:

    Comment


      #3
      I see. Yes, it is important then for all of them to have the same base class. Of course if you could elaborate more it would be great as well. Thank you. I'm having a hard time implementing this properly right now, and I can't find tutorials either, so any help is quite appreciated at this juncture. Progress is slow, but it's getting there (eventually).

      Comment


        #4
        Originally posted by KeyC0de View Post
        I see. Yes, it is important then for all of them to have the same base class. Of course if you could elaborate more it would be great as well. Thank you. I'm having a hard time implementing this properly right now, and I can't find tutorials either, so any help is quite appreciated at this juncture. Progress is slow, but it's getting there (eventually).
        This is where experience in creating project and work specifications is key.

        Not everyone has that though, and that's okay.

        Start by brainstorming everything you want every weapon to be able to do, write it all down, for everything, no matter how small.

        Then start grouping things into common features that can be put into parent classes.

        You might want to make use of certain programming patterns (look up Game Programming Patterns (the book)), which will have an impact.

        From there, it's going to be about obfuscating your system requirements into OOP hierarchies. You have to trust your programmer instinct, but above all else, KISS!

        Keep It Simple Stupid.

        For weapons, a good place to start is going to be
        • WeaponBase
          • RangedWeapon
          • MeleeWeapon
          • WeaponTossable
        From there, you need to figure out if you need to create additional abstract classes.

        If you do not, you may be able to put all of your weapons under just this hierarchy, if not, keep going, separating out groups of weapons you have left, perhaps this (where bold classes are not abstract):

        melee axe, ranged rifle 1, machine gun ranged, melee hammer, grenade, remote explosives etc
        • WeaponBase
          • RangedWeapon
            • ProjecticleWeapon
              • MachineGunRanged
            • HitScanWeapon
              • RangedRifle1
          • MeleeWeapon
            • OneHanded
              • MeleeAxe
            • TwoHanded
              • MeleeHammer
          • WeaponTossable
            • Grenade
            • RemoteExplosive

        Comment

        Working...
        X