Package model

Class Actor

java.lang.Object
model.Actor
Direct Known Subclasses:
Ghost, PacMann

public abstract class Actor extends Object
A character in the game, which can store and update its location on the game graph and interact with the game model based on its location. Subclasses are responsible for that actor's vertex visitation behavior and navigation.
  • Nested Class Summary Link icon

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    A record class that represents ordered pairs of doubles
    static final record 
     
  • Field Summary Link icon

    Fields
    Modifier and Type
    Field
    Description
    protected Actor.Location
    The current location of this actor, modeled as a record of the edge that they are currently traversing and their relative progress along this edge.
    protected final GameModel
    The game model with which this actor is associated.
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    Construct a new actor associated with the given `model`.
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    abstract double
    Return the current base speed of this actor, before factoring in the weight of the edge they are traversing.
    Return the current edge that this actor is traversing.
    protected double
    Return the speed of this actor, which is primarily a function of its `currentEdge`'s weight.
    Return the upper left corner of this actor's bounding box.
    Return the list of Edges in this actor's current planned path through the maze (if any).
    Return Location object summarizing this actor's current location.
    double
    Return the amount of game time (in ms) that this actor is able to travel at its current speed before reaching a vertex or changing state.
    Return the closest vertex to this actor's current position, which will be either `currentEdge.src()` or `currentEdge.dst()`, depending on `distanceAlongEdge`.
    Returns the next edge that this actor will traverse in the game graph.
    void
    propagate(double dt)
    Update this actor's location and state by propagating its current motion along its edge by `dt` ms of game time.
    abstract void
    Resets this actor to its state at the start of a life.
    void
    Set this actor's location to the start of `newEdge`.
    abstract void
    Update the model based on this actor's arrival at vertex v.

    Methods inherited from class java.lang.Object Link icon

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details Link icon

    • model Link icon

      protected final GameModel model
      The game model with which this actor is associated.
    • location Link icon

      protected Actor.Location location
      The current location of this actor, modeled as a record of the edge that they are currently traversing and their relative progress along this edge.
  • Constructor Details Link icon

    • Actor Link icon

      public Actor(GameModel model)
      Construct a new actor associated with the given `model`.
  • Method Details Link icon

    • visitVertex Link icon

      public abstract void visitVertex(MazeGraph.MazeVertex v)
      Update the model based on this actor's arrival at vertex v.
    • nextEdge Link icon

      public abstract MazeGraph.MazeEdge nextEdge()
      Returns the next edge that this actor will traverse in the game graph. Navigation strategy is delegated to the subclass. Will only be called when this actor is standing on a vertex, which must equal the returned edge's starting vertex.
    • guidancePath Link icon

      public abstract List<MazeGraph.MazeEdge> guidancePath()
      Return the list of Edges in this actor's current planned path through the maze (if any). This is intended to be used for visualizing actors' intended behavior. Sequence of edges must form a continuous path (e.g., `ans.get(i).dst().equals(ans.get(i+1).src())`).
    • reset Link icon

      public abstract void reset()
      Resets this actor to its state at the start of a life.
    • baseSpeed Link icon

      public abstract double baseSpeed()
      Return the current base speed of this actor, before factoring in the weight of the edge they are traversing.
    • location Link icon

      public Actor.Location location()
      Return Location object summarizing this actor's current location.
    • currentEdge Link icon

      public MazeGraph.MazeEdge currentEdge()
      Return the current edge that this actor is traversing.
    • nearestVertex Link icon

      public MazeGraph.MazeVertex nearestVertex()
      Return the closest vertex to this actor's current position, which will be either `currentEdge.src()` or `currentEdge.dst()`, depending on `distanceAlongEdge`.
    • maxPropagationTime Link icon

      public double maxPropagationTime()
      Return the amount of game time (in ms) that this actor is able to travel at its current speed before reaching a vertex or changing state. Return POSITIVE_INFINITY if this actor is standing still and has no anticipated state changes.
    • propagate Link icon

      public void propagate(double dt)
      Update this actor's location and state by propagating its current motion along its edge by `dt` ms of game time. If `dt` is sufficient for the actor to traverse the remainder of its edge, it will stop at that edge's destination vertex.
    • traverseEdge Link icon

      public void traverseEdge(MazeGraph.MazeEdge newEdge)
      Set this actor's location to the start of `newEdge`. May only be called when this actor is standing on a vertex, which must equal `newEdge`'s source.
    • edgeSpeed Link icon

      protected double edgeSpeed()
      Return the speed of this actor, which is primarily a function of its `currentEdge`'s weight.
    • getBoundingBoxUL Link icon

      public Actor.DPair getBoundingBoxUL()
      Return the upper left corner of this actor's bounding box. When an actor is positioned directly atop a vertex (i.e., `distanceAlongEdge` is 0 or 1), this is 0.25 tiles NW (northwest) of the NW corner of that vertex's tile. Otherwise, `distanceAlongEdge` is used to linearly interpolate the bounding box position between `currentEdge.src()` and `currentEdge.dst()` (accounting for tunnels).