Class EntityListArray

java.lang.Object
model.EntityListArray
All Implemented Interfaces:
EventListener, EntityListInterface, EntityEventListener
Direct Known Subclasses:
AlienArmyArray

public class EntityListArray extends Object implements EntityListInterface, EntityEventListener
  • Field Details

    • MAX_SIZE

      public static final int MAX_SIZE
      See Also:
    • entities

      protected Entity[] entities
      The entities in the array. Make it protected to allow sub-classes access but noone else.
    • removeEntities

      protected Entity[] removeEntities
      The entities to be removed on next game cycle
    • numEntities

      protected int numEntities
    • numRemoveEntities

      protected int numRemoveEntities
  • Constructor Details

    • EntityListArray

      public EntityListArray()
      Sets up the array entities and removeEntities of MAX_SIZE set numEntities and numRemoveEntities to 0
      Parameters:
      entities -
      removeEntities -
  • Method Details

    • clear

      public void clear()
      Clear the array by creating a new array of entities and removeEntities and reset numEntities and numRemoveEntities
      Specified by:
      clear in interface EntityListInterface
    • add

      public void add(Entity e)
      Add one entity to the entities array
      Specified by:
      add in interface EntityListInterface
      Parameters:
      e - the entity to be added to the array increase the number of entities
    • draw

      public void draw(Graphics2D g)
      draw all entities in the array using draw
      Specified by:
      draw in interface EntityListInterface
      Parameters:
      g - The graphics context to draw to
    • moveAndDraw

      public void moveAndDraw(long delta, Graphics2D g)
      Description copied from interface: EntityListInterface
      Move and draw
      Specified by:
      moveAndDraw in interface EntityListInterface
      Parameters:
      delta - Time passed since last updateState (ms)
      g - The graphics context to draw to
    • addEntityEventListener

      public void addEntityEventListener(EntityEventListener l)
      Manage event listener registration
      Specified by:
      addEntityEventListener in interface EntityListInterface
      Parameters:
      l - the listener to add
    • updateState

      public void updateState(long delta)
      Move all entities in the array according to time passed delta using updateState
      Specified by:
      updateState in interface EntityListInterface
      Parameters:
      delta - Time passed since last updateState (ms)
    • increaseSpeed

      public void increaseSpeed(int percentIncrease)
      Increase the speed of all members of the array by a certain percentage
      Specified by:
      increaseSpeed in interface EntityListInterface
      Parameters:
      percentIncrease - as whole number
    • collidesWith

      public Entity collidesWith(Entity other)
      Check if this entity collides with any entity in this entity array.
      Specified by:
      collidesWith in interface EntityListInterface
      Parameters:
      other - The entity to check collision against
      Returns:
      null if there is no collision, return the entity if there is a collision
    • remove

      public void remove(Entity e)
      Remove an entity from the array
      Specified by:
      remove in interface EntityListInterface
      Parameters:
      e - The entity to remove
    • getNumEntities

      public int getNumEntities()
      Number of entities
      Specified by:
      getNumEntities in interface EntityListInterface
      Returns:
      numEntities
    • getRandom

      public Entity getRandom()
      if there are no entities in the list return null return one of the entities in the array - choosing it randomly
      Specified by:
      getRandom in interface EntityListInterface
      Returns:
      Entity
    • registerEntityForRemoval

      public void registerEntityForRemoval(Entity e)
      Description copied from interface: EntityListInterface
      Registers an entity for removal next time the state of the list is updated
      Specified by:
      registerEntityForRemoval in interface EntityListInterface
      Parameters:
      e - The entity to register for removal next time the upDateState is called on the list
    • collisionHasOccured

      public void collisionHasOccured(EntityHitEvent e)
      Specified by:
      collisionHasOccured in interface EntityEventListener
    • entityMoved

      public void entityMoved(EntityMoveEvent e)
      Specified by:
      entityMoved in interface EntityEventListener
    • entityDied

      public void entityDied(EntityDiedEvent e)
      Specified by:
      entityDied in interface EntityEventListener
    • toString

      public String toString()
      Overrides:
      toString in class Object