How would you store the data of different types of weapons?

A place for people with an interest in developing new shmups.
Post Reply
User avatar
J_C
Posts: 18
Joined: Tue Feb 13, 2018 6:20 pm

How would you store the data of different types of weapons?

Post by J_C »

Hi.

I'm slowly advancing with the development of my shmup, and I got to a point where I would start to implement the weapons. I'm curious about how you people would store the data of each weapon? Obviously each weapon has a sprite, they have a damage property, rate of fire, maybe direction and other special stuff.

Would you store every weapon in one big array (or other similar data structure), and during game you refernce different cells of the array to get the weapons effect and behaviour? Or maybe store them individually, each weapon being a separate object?
User avatar
M.Knight
Posts: 1246
Joined: Thu Dec 12, 2013 4:54 pm
Location: France

Re: How would you store the data of different types of weapo

Post by M.Knight »

I think it can depend on the types of weapons you have in your game.
Shot objects can be stored in an array or a stack for example, but if you have a weapon where only one instance of it is on screen at the same time -such as a sword-, you would only have to handle a single object.

For my shots, I store them in a stack and each of them has scripts that make them move forward when popped from the stack and activated. I don't have to set their velocity, damage, sprite or anything else at runtime, as everything has already been programmed beforehand. The stack itself has a fixed size of 4 because I wanted to set a specific number of shots that can be on-screen at the same time.

If you have a variety of shots with slightly different properties, it could be interesting to have an array or a stack of bland and modulable shot objects with a method called when the shot is fired to assign them all the properties you listed. I could see it work if assigning sprites and hitboxes on runtime like that isn't expensive. The advantage would be that instead of storing [shot objects for a single weapon] * [number of weapons], you would only store [shot objects for a single weapon] objects in your array, and edit them when the game is running. On the other hand, the rate of fire property is one I feel may be trickier to handle with this kind of approach because it comes into play before the shot is even fired, unlike the others.

If enemies may react to weapons in very different ways, it might be better to separate the weapons. It is not mandatory though, I suppose, because if you have a "bullet type" field on each of your bullets, an enemy can determine what kind of bullet just hit it and react accordingly.

If other devs have their own suggestions and more advanced techniques, feel free to butt in. :)
RegalSin wrote: I think I have downloaded so much I am bored with downloading. No really I bored with downloading stuff I might consider moving to Canada or the pacific.
Remote Weapon GunFencer - My shmup project
User avatar
J_C
Posts: 18
Joined: Tue Feb 13, 2018 6:20 pm

Re: How would you store the data of different types of weapo

Post by J_C »

M.Knight wrote:I think it can depend on the types of weapons you have in your game.
Shot objects can be stored in an array or a stack for example, but if you have a weapon where only one instance of it is on screen at the same time -such as a sword-, you would only have to handle a single object.

For my shots, I store them in a stack and each of them has scripts that make them move forward when popped from the stack and activated. I don't have to set their velocity, damage, sprite or anything else at runtime, as everything has already been programmed beforehand. The stack itself has a fixed size of 4 because I wanted to set a specific number of shots that can be on-screen at the same time.

If you have a variety of shots with slightly different properties, it could be interesting to have an array or a stack of bland and modulable shot objects with a method called when the shot is fired to assign them all the properties you listed. I could see it work if assigning sprites and hitboxes on runtime like that isn't expensive. The advantage would be that instead of storing [shot objects for a single weapon] * [number of weapons], you would only store [shot objects for a single weapon] objects in your array, and edit them when the game is running. On the other hand, the rate of fire property is one I feel may be trickier to handle with this kind of approach because it comes into play before the shot is even fired, unlike the others.

If enemies may react to weapons in very different ways, it might be better to separate the weapons. It is not mandatory though, I suppose, because if you have a "bullet type" field on each of your bullets, an enemy can determine what kind of bullet just hit it and react accordingly.

If other devs have their own suggestions and more advanced techniques, feel free to butt in. :)
Thanks. I am actually planning to have different types of weapons. Some shoot bullets, but there is a beam weapon, and some are like bombs. What I'm thinking is building a grid, where every row is a weapon, and the colomns contain the properties. I don't know if this is the easiest way to do this, but I think I can do something with this. As for the shot objects, I was thinking about programming all of them beforehand, setting all their variables (velocity, direction, damage). So when I spawn them, they will just do their stuff which I programmed.
User avatar
Sai'ke
Posts: 46
Joined: Tue Feb 06, 2018 10:20 am

Re: How would you store the data of different types of weapo

Post by Sai'ke »

What language are you working in? Different languages have different facilities for storing data.

How many bullets are you planning to fire? How complicated/specialized do you expect the weapons will be? Are there relatively large clumps of bullet types that behave more or less the same?
User avatar
J_C
Posts: 18
Joined: Tue Feb 13, 2018 6:20 pm

Re: How would you store the data of different types of weapo

Post by J_C »

Sai'ke wrote:What language are you working in? Different languages have different facilities for storing data.
I'm not using a regular programming language. I build the game with Gamemaker Studio 2. So I use Gamemaker language I guess.
How many bullets are you planning to fire?
I don't know yet. I guess the fastest firing player weapons will shoot around 6 bullets / second.
How complicated/specialized do you expect the weapons will be?
I wouldn't say they will be complicated, but they are quite specialized. Regular bullet firing cannon, laser beam, some kind of shotgun style weapon firing lots of small bullets, plasma gun which fires individual bullets but at a slower rate than a cannon, missile launcher which might shoot tracking missiles, and a railgun, which acts similarly to a laser beam.
Are there relatively large clumps of bullet types that behave more or less the same?
I think so, yes.
User avatar
Sai'ke
Posts: 46
Joined: Tue Feb 06, 2018 10:20 am

Re: How would you store the data of different types of weapo

Post by Sai'ke »

I've never used Game Maker, so I don't know what the language allows. But here's my 10 cents.

Personally, I would separate bullet spawning (orientation w.r.t. turret object) from bullet behavior (orientation adjustments, damage, particle FX etc).

For the bullets, I would probably write some sort of function for each bullet behavior type that uses parameters from some internal list of parameters.

Then I would make a table which has as key a name for each unique bullet type (not bullet behavior) and as result the name of the bullet behavior type function (or the enumerator, depending on the language) and the parameters for that specific bullet type (damage, speed, number of potatoes in its payload), so that lookup is easy.

I would derive bullets from a similar structure and store the information from that master table into the bullet when you spawn it. I would then attach the function into some update thing.

Then in the end, when you're tweaking the difficulty, you only have this one sheet to worry about.
User avatar
J_C
Posts: 18
Joined: Tue Feb 13, 2018 6:20 pm

Re: How would you store the data of different types of weapo

Post by J_C »

Sai'ke wrote:I've never used Game Maker, so I don't know what the language allows. But here's my 10 cents.

Personally, I would separate bullet spawning (orientation w.r.t. turret object) from bullet behavior (orientation adjustments, damage, particle FX etc).

For the bullets, I would probably write some sort of function for each bullet behavior type that uses parameters from some internal list of parameters.

Then I would make a table which has as key a name for each unique bullet type (not bullet behavior) and as result the name of the bullet behavior type function (or the enumerator, depending on the language) and the parameters for that specific bullet type (damage, speed, number of potatoes in its payload), so that lookup is easy.

I would derive bullets from a similar structure and store the information from that master table into the bullet when you spawn it. I would then attach the function into some update thing.

Then in the end, when you're tweaking the difficulty, you only have this one sheet to worry about.
I think I got it. Thanks, I will look into using something like this.
Post Reply