Class Entity<S extends Observable<S>>

java.lang.Object
nz.ac.vuw.ecs.swen225.gp22.domain.Observable<S>
nz.ac.vuw.ecs.swen225.gp22.domain.Entity<S>
Direct Known Subclasses:
EnemyEntity, Player

public abstract class Entity<S extends Observable<S>> extends Observable<S>
Template for entities in a level, including the player. Any entities are observable.
Author:
Abdul
  • Field Details

    • action

      public Entity.Action action
      The action which the entity has taken, used for recorder.
  • Constructor Details

    • Entity

      public Entity(Maze.Point entityPos, Entity.Direction facingDir)
      Default constructor, sets the position and direction of the entity.
      Parameters:
      entityPos - Point to set the position field to.
      facingDir - Direction to set the direction field to.
  • Method Details

    • ping

      public abstract void ping()
      Non-player entities will act based on how often this is called.
    • unping

      public abstract void unping()
      Undoes the effects of ping().
    • hasAction

      public boolean hasAction()
      Returns:
      Whether or not this entity has done an action since the last call of getChangeMap().
    • pollAction

      public Entity.Action pollAction()
      Returns:
      The current action and set the field to null.
    • move

      public void move(Entity.Direction direction)
      Moves the entity in a given direction.
      Parameters:
      direction - Direction to move the entity in.
    • move

      public void move(Maze.Point moveVector)
      Overloaded method for move(), takes in a point.
      Parameters:
      moveVector - Amount to move by.
    • move

      public void move(int moveX, int moveY)
      Overloaded method for move(), that accepts two individual numbers that represent X and Y, respectively.
      Parameters:
      moveX - The amount to change X by.
      moveY - The amount to change Y by.
    • move

      public void move()
      Overloaded method for move(), assumes the chosen direction is the direction the entity is facing.
    • moveAndTurn

      public void moveAndTurn(Entity.Direction dir)
      Combines methods setDir() and move().
      Parameters:
      dir - The new direction of the entity.
    • getPos

      public Maze.Point getPos()
      Returns:
      The position of the entity.
    • getDir

      public Entity.Direction getDir()
      Returns:
      The direction the entity is facing.
    • id

      public int id()
      Returns:
      The ID of the entity.
    • setPos

      public void setPos(Maze.Point pos)
      Sets the position of the entity.
      Parameters:
      pos - Point that represents the entity's new position.
    • setDir

      public void setDir(Entity.Direction dir)
      Sets the direction the entity is facing.
      Parameters:
      dir - The new direction of the entity.
    • deleteEntity

      public void deleteEntity()
      Called when an entity is removed. This method is not abstract because not all entities will need special code to run on deletion.