Jump to content
  • Advertisement
Sign in to follow this  
Sean_Seanston

Weapon Alternate Fire

This topic is 2751 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

I posted this on For Beginners with no success, maybe someone here could help, I'll keep it shorter and more to the point this time.

If you have a game (a Top Down Shooter in this case) with various kinds of weapons defined through XML (giving them a hardcoded basic "type" and defining various values), how might you implement a simple alternate fire mode system?
For example, you have a Double Barrel Shotgun and you want Primary Fire to fire 1 barrel and Secondary Fire to fire 2 barrels.
The differences here are that in the first case, 1 round is fired at a time whereas in the second, 2 are fired together. That's simple enough in theory, but my question is how should that be organized?

I've planned a system where each weapon has an object called WeaponStats. This includes variables such as rate of fire, damage etc. that make 1 gun different from another. However, if I plan to give weapons different ways of firing, it seems to me that perhaps a weapon would need a WeaponStats object for each firing mode.
With a bit of thinking I could probably make that work in XML without too many headaches if I knew that was a good way to go.

Is there maybe a better way or is that way a bit overkill, having the statistics of the entire weapon duplicated (and possibly changed) for every way of firing it? I can't see any other real practical way myself, and I'd just like to hear what some more experienced people think about it, even if it's just to say that it looks passable.

EDIT: Also, would there be any real way of defining only the difference between stats in XML? For instance, naming specific variables that have changed and using that to change the value of only those variables in C++? Without a massive ugly switch statement or something I mean.

Share this post


Link to post
Share on other sites
Advertisement
I would separate that in 2 problems:

- First decide what classes/objects you want in your program. For example each Weapon has a WeaponStats. WeaponStats contains attributes for common properties (like damage per projectile), and a list/map/whatever of FireMode that each say things like: x projectiles per shot, cooldown time = t ...

- Then mirror this structure in XML. This step should be obvious. Finally you have to write or generate a parser that transforms such XML into objects.

Share this post


Link to post
Share on other sites

- First decide what classes/objects you want in your program. For example each Weapon has a WeaponStats. WeaponStats contains attributes for common properties (like damage per projectile), and a list/map/whatever of FireMode that each say things like: x projectiles per shot, cooldown time = t ...


Hmmm... that does sound a bit neater than my previous idea. I hadn't thought about splitting the WeaponStats object like that to avoid duplication of data that (probably) shouldn't change between fire modes and storing all fire mode data within the WeaponStats object itself.

I think I'll go with something like that then. Thanks.

Share this post


Link to post
Share on other sites
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!