Skip to content

Resources

McArthur edited this page Sep 14, 2023 · 4 revisions

Resources are an abstract idea in the game, represented in different ways in different locations. See Accessing Game State, if you want to use stored resources specifically.

This page covers resources before being sent to the global game state.

Resources

Resources are represented by the Resource enum. Presently there is only one variant, Unobtanium which is a placeholder resource so that they can be used and tested. The enum implements toString() and valueOf() which can be useful for converting them when communicating with the GameState (which stores them as strings).

Production Component

The ProductionComponent class can be added on to any entity which needs to produce resources at a constant rate. It was designed for extractors, but will work on any entity. The component sends an amount of a specific resource to the gamestate each tick of some amount of time. In order to account for inconsistent framerates, it measures the delta time and applies catchup and slowdown as appropriate to ensure the resources produced are never out of sync with their expected rate.

If the component is in an entity with a CombatStatsComponent, it will only produce resources when health is above 0.

Anything with a production component will generate popups for the respective resource each tick. It is required that an icon is associated with each resource, and added to the poup class. Tests exist to enforce this requirement.

Construction

A production component is constructed with the following args:

  • Produces: The Resource enum variant this component produces.
  • Tickrate: The amount of seconds between ticks.
  • Ticksize: The amount of resources to produce on each tick.

Resource Display

The ResourceDisplay class is useful for quickly creating various resource bars, depending on what resources the user will need in a level. It can be initialized with no arguments, and utilizes the builder pattern to quickly add resources. For example:

ResourceDisplay resourceDisplayComponent = new ResourceDisplay()
    .withResource(Resource.Durasteel)
    .withResource(Resource.Solstite)
    .withResource(Resource.Nebulite);

will produce a resource bar in the bottom right corner with the three resources, durasteel, solstite, and nebulite.

Each resource bar also has 4 lights atop it. These are tied to the number of functional extractors producing that specific resource at the given time. These can not be configured, besides depending on the resource type of the extractor bar.

Clone this wiki locally