Weapon System in Top-Down Shooter

Started by
10 comments, last by Sean_Seanston 13 years, 1 month ago
I know this is from months ago but I'm getting into the actual implementation now so I have a few questions...


I would only like to point out, melee and projectile based weapons are not necessary distinct. You may for example attach a bayonet to a rifle and you then have a projectile based weapon with a secondary melee attack. So, the best solution is probably to have several hard-coded basic weapon behavior and you then simply attach them to your weapon.
To make it a little more flexible you can build behaviors in terms of events. The projectile weapon may for example have a shot event (probably triggered with the primary or alternate fire button) and a reload event. Your C4 explosive may have detonate event which may be triggered using a timer or alternate fire and so on.


Behaviours (e.g. ProjectileWeapon) have events,,, but should these be reusable components such that ProjectileWeapon would be "assigned" the Shoot or Reload events from some external pool of events, or should they merely be hard-coded functions within the hard-coded ProjectileWeapon class?

I'm thinking the latter, especially since no other classes would likely have a use for Shoot by its very nature.

The nature of a remote explosive like C4 somewhat confuses me too. Hand Grenades or even Mines are essentially just Projectile Weapons with very specialized projectiles but C4 has something in common with Projectile Weapons (spawning a "projectile" to place) and also the special remote detonation ability. So should it perhaps be given its own RemoteExplosive class or some such OR... on the other hand, it is essentially a ProjectileWeapon where a message can be sent to the projectile. What the projectile does with that message is its own business separate from the weapon itself, so perhaps it could be implemented much more generically?

Or perhaps a RemoteWeapon class would be good... though there would still be overlap with ProjectileWeapon, but maybe that's ok though it might make me question whether or not they'd both be necessary...

Anyone have any thoughts?
Advertisement
I've solved the previous problems I mentioned but I'm wondering about one thing relating to this:


So, in this way, you have a single generic weapon code object that simply reads and acts on data from the XML, like so:
<weapon type="shotgun">
<projectile type="bullet" relative_start_position="-1 0 1">
<projectile type="bullet" relative_start_position="0 0 1">
<projectile type="bullet" relative_start_position="1 0 1">
</weapon>

That system makes sense but what happens if you need to spawn some certain projectiles depending on the circumstances?
What I mean is... imagine a Double Barrel Shotgun. One barrel fires first, then the other one slightly to the right. So the first time, we fire one group of projectiles and the next time the other group and alternate that way.

You could also imagine some kind of spaceship weapon where it fires in some similar pattern.

How might I implement that?

The most obvious thing seems some sort of "group" variable. Maybe like:

<projectile type="bullet" xpos="0" ypos="0" group="0"/>
<projectile type="bullet" xpos="1" ypos="0" group="1"/>


In which case... I suppose that would entail some kind of 2-dimensional container inside the weapon like:

ProjectileData[group][ProjectileSpawnInfo];

struct ProjectileSpawnInfo
{
ProjectileType type;
int group;
int xPos, yPos;
}


That seem ok? I just hope I don't overlook anything.

This topic is closed to new replies.

Advertisement