Jump to content
  • Advertisement
Sign in to follow this  
Sean_Seanston

Implementing Different Weapon Firing Modes?

This topic is 2754 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Right now I'm wondering about how to implement different firing modes for weapons in my top down shooter.

Currently, I've tried to design a flexible way to implement various kinds of weapons.
There's a common Weapon class which contains a list of WeaponBehaviour objects which represent actual hard coded behaviours such as ProjectileWeapon or MeleeWeapon. The idea being that any weapon which uses projectiles (almost all of them) can use the ProjectileWeapon class and whatever projectile type it requires without hard coding anything more than ProjectileWeapon and the projectile type.
Also, I can add both a ProjectileWeapon and MeleeWeapon to a Weapon to create something like a gun that can be used in melee. Also, 2 ProjectileWeapons could create a rifle with a grenade launcher or some such, or at least that's the plan.

Now, I've come to a problem. How do I create a weapon with a primary and secondary fire? By which I mean a single weapon (ProjectileWeapon for example) with 2 ways of firing, rather than something like a Weapon that can use either its ProjectileWeapon or MeleeWeapon. For instance, a Double-Barrel Shotgun where primary fire fires 1 shot and secondary fires 2. Or also, an AssaultRifle where the mode of fire can be changed to create semi-auto, burst or full-auto modes through the use of a key.

For the shotgun, the difference between the 2 modes is that 1 vs 2 rounds are fired with each press of fire with no gap in between. The Assault Rifle also has the same idea with 1, 3 or infinite bullets being fired before the fire button has to be repeated. So we need some way of using different values for different fire modes.

My current idea for weapon variables involves a WeaponStats object which would be a member of every WeaponBehaviour object and would tell it what damage to do, how many shots to fire in succession etc.
So what if, for every firing mode, there was a different WeaponStats object? Would that be overkill? I want to make it so weapons and their firing modes can be defined through XML with as little hardcoding in C++ as possible. So I could maybe have a list of firing modes defined through XML and either cycle through them in the case of an Assault Rifle or use them for different mouse buttons if I don't want to have to explicitly switch modes.

Does that sound like it would be a good idea? Or is there something more obvious that would work just as well?
I really want to be able to just have generic classes like ProjectileWeapon and define the differences between a burst fire Assault Rifle and a Double-Barrel Shotgun through XML alone.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!