Class Actor

java.lang.Object
ActiverseEngine.Actor

public abstract class Actor extends Object
The base class for all actors in the world.
Version:
1.4.0
Author:
Knivier
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    act()
    Performs the actor's action.
    boolean
    addItem(Item item)
    Adds an item to the actor's inventory.
    void
    delayNext(int ms)
    Delays the execution of the next action by the specified milliseconds.
    void
    Disables the actor's inventory.
    void
    Enables inventory for the actor.
    int
    Gets the height of the actor.
    Gets the image of the actor.
    Gets the inventory of the actor.
    int
    Gets the maximum size of the actor's inventory.
    Finds the intesrsectiuon of the actor with another actor then returns it
    double
    Gets the horizontal velocity of the actor.
    double
    Gets the vertical velocity of the actor.
    int
    Returns the width of the Actor
    Gets the world that the actor belongs to.
    int
    Gets the x-coordinate of the actor's location.
    int
    Gets the y-coordinate of the actor's location.
    boolean
    Checks if the actor has an inventory.
    boolean
    Checks if this actor intersects with another actor.
    boolean
    Returns the state of the actor on whether it is static or not.
    boolean
    keyIsDown(char key)
    Checks if a specific key is currently pressed.
    void
    move(int distance)
    Moves the actor in its current direction by the specified distance.
    void
    Draws the actor on the given graphics context.
    void
    Removes an item from the actor's inventory.
    void
    setHeight(int height)
    Sets the height of the actor.
    void
    Sets the image of the actor.
    void
    setInventorySize(int size)
    Sets the inventory size
    void
    setLocation(int x, int y)
    Sets the location of the actor.
    boolean
    setStatic(boolean isStatic)
    Sets the state of the actor to static or not.
    void
    setVelocityX(double velocityX)
    Sets the horizontal velocity of the actor.
    void
    setVelocityY(double velocityY)
    Sets the vertical velocity of the actor.
    void
    setWidth(int width)
    Sets the width of the actor.
    void
    setWorld(World world)
    Sets the world that the actor belongs to.
    void
    setX(int x)
    Sets the x-coordinate of the actor's location.
    void
    setY(int y)
    Sets the y-coordinate of the actor's location.
    void
    turn(double angle)
    Turns the actor by the specified angle.
    void
    useAStar(Actor other, int x)
    Gets the direction of the actor.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Actor

      public Actor()
  • Method Details

    • isStatic

      public boolean isStatic()
      Returns the state of the actor on whether it is static or not. A static actor does not move and is not affected by gravity. It will not be updated in the debug menus
      Returns:
      boolean indicating if the actor is static
    • setStatic

      public boolean setStatic(boolean isStatic)
      Sets the state of the actor to static or not.
      Parameters:
      isStatic -
      Returns:
      boolean indicating if the state was successfully set
    • act

      public abstract void act()
      Performs the actor's action.
    • enableInventory

      public void enableInventory()
      Enables inventory for the actor. By default, it is disabled.
    • disableInventory

      public void disableInventory()
      Disables the actor's inventory. Clears the inventory list and sets it to null.
    • getInventorySize

      public int getInventorySize()
      Gets the maximum size of the actor's inventory.
      Returns:
      The maximum size of the inventory.
    • setInventorySize

      public void setInventorySize(int size)
      Sets the inventory size
      Parameters:
      size - the maximum inventory size (maximum number of type Item)
    • hasInventory

      public boolean hasInventory()
      Checks if the actor has an inventory.
      Returns:
      true if the actor has an inventory, false otherwise.
    • addItem

      public boolean addItem(Item item)
      Adds an item to the actor's inventory.
      Parameters:
      item - The item to add to the inventory.
      Returns:
      Boolean the success of adding the item
    • removeItem

      public void removeItem(Item item)
      Removes an item from the actor's inventory.
      Parameters:
      item - The item to remove from the inventory.
    • getInventory

      public List<Item> getInventory()
      Gets the inventory of the actor.
      Returns:
      The list of items in the actor's inventory, or null if inventory is not enabled.
    • setLocation

      public void setLocation(int x, int y)
      Sets the location of the actor.
      Parameters:
      x - The x-coordinate of the new location.
      y - The y-coordinate of the new location.
    • getX

      public int getX()
      Gets the x-coordinate of the actor's location.
      Returns:
      The x-coordinate of the actor's location.
    • setX

      public void setX(int x)
      Sets the x-coordinate of the actor's location.
      Parameters:
      x - The x-coordinate to set.
    • getY

      public int getY()
      Gets the y-coordinate of the actor's location.
      Returns:
      The y-coordinate of the actor's location.
    • setY

      public void setY(int y)
      Sets the y-coordinate of the actor's location.
      Parameters:
      y - The y-coordinate to set.
    • getWidth

      public int getWidth()
      Returns the width of the Actor
      Returns:
      int Actor width in Activerse Unit (relative)
    • setWidth

      public void setWidth(int width)
      Sets the width of the actor.
      Parameters:
      width - The width to set.
    • getImage

      public ActiverseImage getImage()
      Gets the image of the actor.
      Returns:
      The image of the actor, or null if no image is set.
    • setImage

      public void setImage(ActiverseImage image)
      Sets the image of the actor.
      Parameters:
      image - The image to set for the actor.
    • paint

      public void paint(Graphics g)
      Draws the actor on the given graphics context.
      Parameters:
      g - The graphics context to draw on.
    • getWorld

      public World getWorld()
      Gets the world that the actor belongs to.
      Returns:
      The world that the actor belongs to.
    • setWorld

      public void setWorld(World world)
      Sets the world that the actor belongs to.
      Parameters:
      world - The world that the actor belongs to.
    • intersects

      public boolean intersects(Actor other)
      Checks if this actor intersects with another actor.
      Parameters:
      other - The other actor to check for intersection.
      Returns:
      true if this actor intersects with the other actor, false otherwise.
    • move

      public void move(int distance)
      Moves the actor in its current direction by the specified distance.
      Parameters:
      distance - The distance to move the actor.
    • turn

      public void turn(double angle)
      Turns the actor by the specified angle.
      Parameters:
      angle - The angle to turn the actor (in radians).
    • getOneIntersectingObject

      public Actor getOneIntersectingObject()
      Finds the intesrsectiuon of the actor with another actor then returns it
      Returns:
      The intersecting actor, or null if no intersection is found.
    • delayNext

      public void delayNext(int ms)
      Delays the execution of the next action by the specified milliseconds.
      Parameters:
      ms - The delay in milliseconds.
    • keyIsDown

      public boolean keyIsDown(char key)
      Checks if a specific key is currently pressed.
      Parameters:
      key - The character representing the key to check.
      Returns:
      true if the key is currently pressed, false otherwise.
    • getVelocityX

      public double getVelocityX()
      Gets the horizontal velocity of the actor.
      Returns:
      The horizontal velocity of the actor.
    • setVelocityX

      public void setVelocityX(double velocityX)
      Sets the horizontal velocity of the actor.
      Parameters:
      velocityX - The horizontal velocity to set.
    • getVelocityY

      public double getVelocityY()
      Gets the vertical velocity of the actor.
      Returns:
      The vertical velocity of the actor.
    • setVelocityY

      public void setVelocityY(double velocityY)
      Sets the vertical velocity of the actor.
      Parameters:
      velocityY - The vertical velocity to set.
    • getHeight

      public int getHeight()
      Gets the height of the actor.
      Returns:
      The height of the actor.
    • setHeight

      public void setHeight(int height)
      Sets the height of the actor.
      Parameters:
      height - The height to set.
    • useAStar

      public void useAStar(Actor other, int x)
      Gets the direction of the actor.
      Parameters:
      other - The actor to follow
      x - The number of iterations to follow the actor (seconds)