Class Actor
java.lang.Object
ActiverseEngine.Actor
- Direct Known Subclasses:
ParticleSystem
The base class for all actors in the world.
- Version:
- 1.4.1
- Author:
- Knivier
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidact()Performs the actor's action.booleanAdds an item to the actor's inventory.voiddelayNext(int ms) Delays the execution of the next action by the specified milliseconds.voidDisables the actor's inventory.voidEnables inventory for the actor.voidEnables precise float positioning for smooth sub-pixel movementdoublegetAngleTo(Actor other) Gets the angle to another actor in radiansGets the bounding box of the actor.doublegetDistanceTo(Actor other) Gets the distance to another actorintGets the height of the actor.getImage()Gets the image of the actor.Gets the inventory of the actor.intGets the maximum size of the actor's inventory.intGets the maximum inventory sizeFinds the intesrsectiuon of the actor with another actor then returns itdoubleGets the precise X positiondoubleGets the precise Y positiondoubleGets the horizontal velocity of the actor.doubleGets the vertical velocity of the actor.intgetWidth()Returns the width of the ActorgetWorld()Gets the world that the actor belongs to.intgetX()Gets the x-coordinate of the actor's location.intgetY()Gets the y-coordinate of the actor's location.booleanChecks if the actor has an inventory.booleanintersects(Actor other) Checks if this actor intersects with another actor.booleanisStatic()Returns the state of the actor on whether it is static or not.booleankeyIsDown(char key) Checks if a specific key is currently pressed.voidknockback(double angle, double force) Applies knockback to this actorvoidmove(int distance) Moves the actor in its current direction by the specified distance.voidDraws the actor on the given graphics context.voidremoveItem(Item item) Removes an item from the actor's inventory.voidsetHeight(int height) Sets the height of the actor.voidsetImage(ActiverseImage image) Sets the image of the actor.voidsetInventorySize(int size) Sets the inventory sizevoidsetLocation(int x, int y) Sets the location of the actor.voidsetPreciseLocation(double x, double y) Sets the precise location using floatsbooleansetStatic(boolean isStatic) Sets the state of the actor to static or not.voidsetVelocityX(double velocityX) Sets the horizontal velocity of the actor.voidsetVelocityY(double velocityY) Sets the vertical velocity of the actor.voidsetWidth(int width) Sets the width of the actor.voidSets the world that the actor belongs to.voidsetX(int x) Sets the x-coordinate of the actor's location.voidsetY(int y) Sets the y-coordinate of the actor's location.voidturn(double angle) Turns the actor by the specified angle.voidGets the direction of the actor.
-
Field Details
-
direction
protected double direction
-
-
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)
-
getMaxInventorySize
public int getMaxInventorySize()Gets the maximum inventory size- Returns:
- The maximum number of items the inventory can hold
-
hasInventory
public boolean hasInventory()Checks if the actor has an inventory.- Returns:
- true if the actor has an inventory, false otherwise.
-
addItem
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
Removes an item from the actor's inventory.- Parameters:
item- The item to remove from the inventory.
-
getInventory
-
enablePrecisePosition
public void enablePrecisePosition()Enables precise float positioning for smooth sub-pixel movement -
setPreciseLocation
public void setPreciseLocation(double x, double y) Sets the precise location using floats- Parameters:
x- The x-coordinatey- The y-coordinate
-
getPreciseX
public double getPreciseX()Gets the precise X position- Returns:
- The precise x-coordinate
-
getPreciseY
public double getPreciseY()Gets the precise Y position- Returns:
- The precise y-coordinate
-
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
Gets the image of the actor.- Returns:
- The image of the actor, or null if no image is set. Returns null if the actor uses shapes instead of images.
-
setImage
Sets the image of the actor.- Parameters:
image- The image to set for the actor.
-
paint
Draws the actor on the given graphics context. If no image is set, this method does nothing. Subclasses should override this method to draw shapes or custom graphics when not using images.- Parameters:
g- The graphics context to draw on.
-
getWorld
Gets the world that the actor belongs to.- Returns:
- The world that the actor belongs to.
-
setWorld
Sets the world that the actor belongs to.- Parameters:
world- The world that the actor belongs to.
-
intersects
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.
-
getBoundingBox
Gets the bounding box of the actor.- Returns:
- The bounding box of the actor.
-
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
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. WARNING: This method creates a new thread for each delay. For frequent delays, consider using ActiverseUtils.Timer instead.- 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
Gets the direction of the actor.- Parameters:
other- The actor to followx- The number of iterations to follow the actor (seconds)
-
getDistanceTo
Gets the distance to another actor- Parameters:
other- The other actor- Returns:
- The distance in pixels
-
getAngleTo
Gets the angle to another actor in radians- Parameters:
other- The other actor- Returns:
- The angle in radians from this actor to the other
-
knockback
public void knockback(double angle, double force) Applies knockback to this actor- Parameters:
angle- The angle of knockback in radiansforce- The force/distance of knockback
-