Custom Weapons
Code
Try it yourself
About
Ever thought that a game lacked enough guns? That the guns in the game lacked customization? Well with this program you can create your own! No limits, you can add any weapon you want and edit it however you like.
This was a four-week project school project made in our schools own TenGine.
What I worked on
Weapon Classes
There a four base classes of weapons:
Single shot - Can only shoot once before reloading
Bolt action - Needs to be cocked after each shot
Semi-automatic - Needs to click for every shot
Automatic - Hold and spray
These base classes handle how the weapon shoots and reloads, and it also handles the components. However, each instance of a weapon can be individually tweaked and edited to the user's preference in the editor.
This was of course what I spent most of my time doing. I thought it was extremely fun and I learned a great deal about how to code modular systems which are reusable.
Just like the weapons I created base classes for the components:
Muzzles - These modify the recoil and damage
Handles - Modifies the weight and recoil
Scopes - Can be used to add zoom
Magazines - Holds additional ammo
Stocks - Modifies the weight and recoil
Ammo - Different ammo types with damage effects
All the components were created just like the weapons and are set up to be very modular and reusable. All the components can be added to every weapon, but the user can toggle which it should use.
Components
Ammo
The different types of ammo are:
Fire - Sets an enemy on fire
Explosion - Explodes and damages an enemy in range
Velocity - Travels faster than a regular bullet
Editor
The editor was made using ImGui and it is used to edit the weapons and components base values, its model, rotation and position.
In the editor you can also add or remove weapons which furthermore can be saved so you and will be to continue modifying it at a later time.
The editor was made so it should be easy to use, and you can also see the changes be updated in real time. The bars on the right changes color depending on how a component is acting on the weapon.
Saving
As an addition to this project, I made the user being able to save a weapon or a component for later use. This meant I got to work with file saving and reading. I used the engine own file printing system, but I wrote my own reading system as I found it really complicated and it missed some functions I needed.
To save an item I create a new file in the corresponding folder naming after the item. Then all its values are copied and labeled. When loading the files, it takes reads the label and ads the read value to the matching parameter.