Skip to content

Player Weapons

Daniel-vanNiekerk0 edited this page Oct 19, 2023 · 6 revisions

Overview:

Player Weapons allow the player to deal damage, the player uses weapons be pressing mouse 1 (left click). Each weapon has a type either Melee or ranged and this determines which slot the weapon is used in. Each slot has its own ammo with melee having a maximum of 30 and ranged a maximum of 10 these can be reloaded by pressing Q.

Weapons Testing is done according to the weapon test plan.

Implementation

Config implementation:

Weapons are configured through a config file which holds:

  • appearance file paths such as holding sprite and animation atlas and animation type
  • movement variables such as weapon speed and number of projectile
  • usage variables such as ammo consumption and cooldown

Movement implementation:

Weapons are implemented as entities and generated using an associated values in a config file along with a specified weapon controller component. WeaponControllerComponenent is an abstract class that implements common function shared between all weapons such as base variables, a create function, an update loop, an add animations function and a despawn function. Along with this are six abstract functions that control the weapon. Three are called to initiate the weapons: rotation, position, animation. And another three are called every tick to update the weapons: rotation, position and animation.

Concrete weapon controllers inherit the base class and override these methods to implement weapon specific behavior. Additionally child classes can implement additional variables to control the weapons movement, this can be to implement features such as gradually rotation or acceleration, or a player tracker variable to have the weapon follow the players movement.

Other Components Functionality:

Along with the control component each weapon makes use of combat stats component to deal damage and a sound component to play sounds defined in the config file (currently no sounds implemented). If a weapon specific component is required this is to be added in the create function of the controller component to prevent the attack factory having any weapon specific code except the definition of the controller component.

Usage implementation:

Each time the player attacks an array of Entity integer pairs are generated from the attack factory, each entity is an attack entity and each integer is a time delay for the attack to be spawned. This allows for sequence attacks to be made such as a swarm of missiles that fires multiple missiles over a few seconds all in one attack. Each attack is given a sequence number, this allows for sequence attacks to have well defined behavior.

Weapon ammo is implemented in the players inventory component which holds a max ammo, current ammo and a cooldown for each slot. With ammo usage for an attack being defined in a config file. The player is unable to use an attack if it would make their ammo negative or if their cool down has not fully reset for the current weapon. A cool down for a slot is only decreased if the player has that slot equipped.

Weapons in the Game:

There are currently 5 functional melee weapons implemented, this consists of three swing attacks a multi sword throw attack and a nuke. This first melee weapon given to the player is the Wrench which the player swings. The wrench doesn't use ammo but has a medium length cooldown.

image

The Next available is the katana which is similar to the wrench but does more damage and has a shorter cooldown.

image

The player then has two options, this first is the bee string weapon which is a burst of swords in the attack direction.

image image

And the second option is a laser sword which has a short charging animation before a quick swing

image image

After the laser sword the player than has access to a nuke, the player can press anywhere on the screen and after a short delay a nuke will be dropped, it takes a couple of seconds to land and then explodes making use of a particle effect that expands to cover the screen.

image image image

There are currently 7 Ranged weapons: This consists of two boomerangs, a slingshot, a sniper rifle, a grenade, a swarm missile launch and a mouse homing missile launcher. The first boomerange has a short arc that wraps back around to the player

image

The second boomerang fires two at once each going a different direction around the arc. The arc is also much larger.

image

The next weapon is a slingshot that fires a small rock in a straight line with little range.

image

After the slingshot is a sniper rifle that fires a fast moving bullet towards the mouse but has a longer cooldown.

image

On the other side of the tree are the explosive ranged weapons, the first is a grenade which the player lobs

image image

After the grenade the player has the option of two explosive launchers, the first is a swarm missile which fires lots of small rockets in the general direction of the mouse click that explode.

image image

The other option is the homing rocket which fires a single more powerful rocket that tracks the players mouse

image

Clone this wiki locally