Reworking the Codebase - The Starving Tournament Devlog


In order to expand the game with new weapons, to improve the round system and to be able to add a betting system to it we first had to rework some parts of the codebase and inner class structure of the game.

The WeaponController

The old structure of the weapon system grew over time and unfortunately the classes ended up with some spaghetti code and confusing class structure. This is how the old structure worked (simplified):

Anwendungsfalldiagramm 3

Adding a weapon in the old codebase of the starving tournament meant adding some code to the player shooting class that would handle animation etc. and to the weapons or weapons melee class (wether its a melee weapon or not). In order to add as many weapons as we plan the two classes would have exploded sometime.

Another thing we can see, there were two classes that handled the players input: player input - for moving etc. and player shooting - for fighting (melee and range weapons, which is also confusing, when the class is named player shooting). So how can this structure be imrpoved? One idea was to use the type object pattern and load weapon configurations from a file. But we want some weapons with special functions that can't be modeled (at least not that easy) into data but better with funcionality.

So we came up with a new structure with a hierarchical (Inheritance FTW) weapon structure:

Anwendungsfalldiagramm 32

One good thing we see instantly: the player input class now also handles the fighting controls. No more confusion over which input class handles which inputs. The new weapon controller class handles player animation and adding, removing weapons and it holds a list of abstract weapons. They all have methods for primary and secondary attack which will be called by the weapon controller. So all weapons have the same interface but can implement different functionality. We also differ RangeWeapon from MeleeWeapon. RangeWeapons have ammo and Melee Weapons have not.

So adding a new weapon is now as easy as adding a new subclass of RangeWeapon or MeleeWeapon. (+ Adding an inventory item, prefabs for pickup, the weapon model for the player to hold + arrows or something else to shoot for range weapons)

For now we are very happy with the solution and are adding new weapons.

The NetworkManager

Another class that got out of control was the networkmanager. At first it was planned to do the network stuff (using PUN) - connecting, creating rooms, joining. But then more and more stuff was added:

Untitled

Also the spawning of players and bots and the round management (starting rounds ore handling the unlimited mode) was done in this class.

We want to improve the round system and add a betting and sponsoring system to the spectators, but to make that not too complicated and end in more spaghetti code, we had to split up the network manager:

Untitled1

Now there is a class for each topic: Network Manager, Round Manager and Spawn Manager. We will add a Betting Manager that can easily interact with the Round Manager and Statistics Manager (not shown here) to make betting a fun new gameplay element - stay tuned!

Get The Starving Tournament

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.