Class TroopContainerComponent

java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.components.friendly.TroopContainerComponent

public class TroopContainerComponent extends Component
Allows us to make use of an entity that contains other entities

i.e. an in-game 'unit'. Does so by binding them within a range of one another and propagating updates to its sub-entities.

This implementation does not assume that all Units are homogenous

Also, this slightly acts as a disgusting entity/component blend, unsure if it should just be an extension of the entity.
  • Constructor Details

    • TroopContainerComponent

      public TroopContainerComponent(ArrayList<Entity> troops, float permissibleRange)
  • Method Details

    • create

      public void create()
      Called when the corresponding entity is created. Used to create all of the sub-entities, so that they do not need to be individually created. Note that this fails if the sub-entities are created on their own.
      Overrides:
      create in class Component
    • earlyUpdate

      public void earlyUpdate()
      Description copied from class: Component
      Early update called once per frame of the game, before update(). Use this only for logic that must run before other updates, such as physics. Not called if component is disabled.
      Overrides:
      earlyUpdate in class Component
    • update

      public void update()
      updates the components of troops, and pulls them back in line if they have managed to move too far from the center of the unit
      Overrides:
      update in class Component
    • dispose

      public void dispose()
      Description copied from class: Component
      Called when the component is disposed. Dispose of any internal resources here.
      Overrides:
      dispose in class Component
    • getFormation

      public static ArrayList<com.badlogic.gdx.math.Vector2> getFormation(com.badlogic.gdx.math.Vector2 centrePos, float boundingRadius, int n)
      Finds the formation of the troops around a point
      Parameters:
      centrePos - the position the unit is/will be centred on
      n - the number of troops to form in the unit
      Returns:
      the positions of the resultant troops