Class ItemTimerComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.items.ItemTimerComponent
- Direct Known Subclasses:
ChopIngredientComponent
,CookIngredientComponent
TimerComponent.java
Timer component used for item cooking and chopping. Able to be set with a
time started, stopped, and paused etc. This will modify the current
impletmentation of item cooking
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected long
protected final GameTime
Class member variables.protected boolean
protected long
-
Constructor Summary
ConstructorsConstructorDescriptionTimerComponent initialiser creates a timer which has the legnth set to Float.MAX_VALUE, the time length must be set manually. -
Method Summary
Modifier and TypeMethodDescriptionfloat
Gets the percentage completion of the timer.protected boolean
Determines if the timer is finished.protected void
Method to call when rage mode is deactivated by the user.protected void
Method to call when rage mode is activated by the user.protected void
setLength
(long length) Set the length of the timer.protected void
Sets the timer to start running.protected void
Set the timer to stop running.void
update()
Function to run each frameprotected abstract void
Method to update an item to a new state depending on the item type.Methods inherited from class com.csse3200.game.components.Component
create, dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate
-
Field Details
-
gameTime
Class member variables. - gameTime the global gametime service - length finishing time of the timer - elapsed the current ammount of time elapsed - isRunning if the timer is running starts as false when item created - multiplier the current multiplier of the station if cooking -
length
protected long length -
elapsed
protected long elapsed -
isRunning
protected boolean isRunning
-
-
Constructor Details
-
ItemTimerComponent
public ItemTimerComponent()TimerComponent initialiser creates a timer which has the legnth set to Float.MAX_VALUE, the time length must be set manually. This is so that timings depending on upgrades and such are not prevented in the future.
-
-
Method Details
-
update
public void update()Function to run each frame -
setLength
protected void setLength(long length) Set the length of the timer. This should be used before the timer has started running, but is not prevented from being used while it is running however, if used the completion status of the timer could change.- Parameters:
length
- of time the timer should run for requires length > 0
-
startTimer
protected void startTimer()Sets the timer to start running. -
stopTimer
protected void stopTimer()Set the timer to stop running. -
isFinished
protected boolean isFinished()Determines if the timer is finished.- Returns:
- true if the time elapsed is greater than the length, false otherwise
-
getCompletionPercent
public float getCompletionPercent()Gets the percentage completion of the timer. e.g. if the length is 10s and 3s has passed 30f will be returned.- Returns:
- The percentage completion of the timer.
-
updateItem
protected abstract void updateItem()Method to update an item to a new state depending on the item type. Abtract since cooking and chopping will have different implementations. -
rageModeOn
protected void rageModeOn()Method to call when rage mode is activated by the user. Reduces the time that the item will take to cook -
rageModeOff
protected void rageModeOff()Method to call when rage mode is deactivated by the user. Changes back the time that the item takes to cook back to normal.
-