Package com.csse3200.game.components
Class MagazineComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.MagazineComponent
Stores and manages a given weapon's magazine information
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
Returns current amount of ammo in magazineboolean
Reloads the magazine from player's current ammo supplyboolean
Determines if the weapon is currently reloadingvoid
setCurrentAmmo
(int newAmmo) Sets the current ammo to a new valuevoid
setTimeSinceLastReload
(float timeSinceLastReload) Sets the time since last reload, used for testing purposesvoid
update()
Updates the reload cooldownMethods inherited from class com.csse3200.game.components.Component
create, dispose, earlyUpdate, getEntity, getPrio, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate
-
Constructor Details
-
MagazineComponent
public MagazineComponent(int maxAmmo) Constructs an magazine component- Parameters:
maxAmmo
- the maximum amount of ammunition that can be held by the weapon
-
-
Method Details
-
update
public void update()Updates the reload cooldown -
getCurrentAmmo
public int getCurrentAmmo()Returns current amount of ammo in magazine- Returns:
- ammo in magazine
-
setCurrentAmmo
public void setCurrentAmmo(int newAmmo) Sets the current ammo to a new value- Parameters:
newAmmo
- ammunition to be stored in the magazine
-
reload
Reloads the magazine from player's current ammo supply- Returns:
- true if reload is successful and adds ammunition to the magazine, false otherwise
-
reloading
public boolean reloading()Determines if the weapon is currently reloading- Returns:
- true if the weapon is undergoing a reload, false otherwise
-
setTimeSinceLastReload
public void setTimeSinceLastReload(float timeSinceLastReload) Sets the time since last reload, used for testing purposes- Parameters:
timeSinceLastReload
- designated time since last reload
-