Class CurrencyGeneratorComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.currency.CurrencyGeneratorComponent
Periodically spawns "Scrap Metal" currency at random positions on the screen. The spawn interval,
scrap value, texture path and motion parameters are configurable. Actions registered on the Stage
are removed in
dispose()
to avoid leaks.-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCurrencyGeneratorComponent
(float intervalSec, int scrapValue, String scrapTexturePath, com.badlogic.gdx.math.Vector2 position) Creates a new currency generator component with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Called when the entity is created and registered.void
dispose()
Called when the component is disposed.boolean
isPaused()
Checks if the generator is paused.void
pause()
Pauses the sunlight generationvoid
resume()
Resumes the sunlight generationsetScrapSizePx
(float px) Sets the size of spawned scraps in pixels.void
Spawns a scrap at the specified coordinates.Methods inherited from class com.csse3200.game.components.Component
earlyUpdate, getEntity, getPriority, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
CurrencyGeneratorComponent
public CurrencyGeneratorComponent(float intervalSec, int scrapValue, String scrapTexturePath, com.badlogic.gdx.math.Vector2 position) Creates a new currency generator component with the specified parameters.- Parameters:
intervalSec
- seconds between spawnsscrapValue
- currency granted per scrapscrapTexturePath
- texture path for the scrap image
-
-
Method Details
-
create
public void create()Description copied from class:Component
Called when the entity is created and registered. Initial logic such as calls to GetComponent should be made here, not in the constructor which is called before an entity is finished. -
spawnScrapAt
public void spawnScrapAt()Spawns a scrap at the specified coordinates. -
setScrapSizePx
Sets the size of spawned scraps in pixels.- Parameters:
px
- the size in pixels- Returns:
- this component for method chaining
-
pause
public void pause()Pauses the sunlight generation -
resume
public void resume()Resumes the sunlight generation -
isPaused
public boolean isPaused()Checks if the generator is paused.- Returns:
- true if the generator is paused, false otherwise
-
dispose
public void dispose()Description copied from class:Component
Called when the component is disposed. Dispose of any internal resources here.
-