Class Entity
- java.lang.Object
-
- net.egartley.beyondorigins.core.abstracts.Renderable
-
- net.egartley.beyondorigins.core.abstracts.Entity
-
- All Implemented Interfaces:
Tickable
- Direct Known Subclasses:
AnimatedEntity
,StaticEntity
public abstract class Entity extends Renderable implements Tickable
Anything that is rendered with aSprite
at a specified location- See Also:
AnimatedEntity
,StaticEntity
-
-
Field Summary
Fields Modifier and Type Field Description java.util.ArrayList<EntityBoundary>
boundaries
Collection of the entity's boundariesboolean
canCollide
Whether or not the entity is "allowed" to collide with othersprivate static org.newdawn.slick.Font
debugFont
EntityBoundary
defaultBoundary
The boundary to use if not specifieddouble
deltaX
Less-than-one change in the x-coordinate, used for non-integer speedsdouble
deltaY
Less-than-one change in the y-coordinate, used for non-integer speedsstatic byte
DIRECTION_DOWN
static byte
DIRECTION_LEFT
static byte
DIRECTION_RIGHT
static byte
DIRECTION_UP
protected org.newdawn.slick.Image
firstLayer
IfisDualRendered
is true, render this before the player ("below")int
health
Amount of damage the entity can take before dyingprivate static org.newdawn.slick.Color
healthBarColor
private int
healthBarWidth
protected org.newdawn.slick.Image
image
The buffered image to use when rendering (default)java.util.ArrayList<EntityEntityInteraction>
interactions
Collection of the entity's interactionsEntityInventory
inventory
boolean
isAllowedToMoveDownwards
Whether or not the entity is allowed to move downwardsboolean
isAllowedToMoveLeftwards
Whether or not the entity is allowed to move leftwardsboolean
isAllowedToMoveRightwards
Whether or not the entity is allowed to move rightwardsboolean
isAllowedToMoveUpwards
Whether or not the entity is allowed to move upwardsboolean
isAnimated
Whether or not the entity is animatedboolean
isCollided
Whether or not the entity is currently collided with another entityboolean
isDualRendered
Whether or not the entity has two different "layers" that are rendered before and after the playerprotected boolean
isMovingDownwards
Whether or not the entity is currently moving downwardsprotected boolean
isMovingLeftwards
Whether or not the entity is currently moving leftwardsprotected boolean
isMovingRightwards
Whether or not the entity is currently moving rightwardsprotected boolean
isMovingUpwards
Whether or not the entity is currently moving upwardsboolean
isSectorSpecific
Whether or not the entity is "bound" to, or only exists in, a specific map sectorboolean
isTraversable
Whether or not other entities, mainly the player, can walk over it or notEntityEntityCollision
lastCollision
The most recent collision that has occurred for the entity.EntityEntityCollisionEvent
lastCollisionEvent
The most recent collision event to have occurred.int
maximumHealth
Maximum amount of health the entity can havejava.lang.String
name
Human-readable identifier for the entity (not unique)private static org.newdawn.slick.Color
nameTagBackgroundColor
private int
nameTagWidth
protected org.newdawn.slick.Image
secondLayer
IfisDualRendered
is true, render this after the player ("above")private boolean
setFontMetrics
Whether or not font metrics have been initialized.protected java.util.ArrayList<SpriteSheet>
sheets
The entity's sprite sheetsdouble
speed
The entity's speed (magnitude of its location change when moving)Sprite
sprite
The sprite to use while renderingprotected java.util.ArrayList<Sprite>
sprites
The entity's spritesint
uuid
The entity's unique identification number.
-
Constructor Summary
Constructors Constructor Description Entity(java.lang.String name)
Entity(java.lang.String name, Sprite sprite)
Entity(java.lang.String name, SpriteSheet sheet)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
allowAllMovement()
Allows the entity to move in all directionsprivate void
drawBoundaries(org.newdawn.slick.Graphics graphics)
Draws all of the entity's boundariesvoid
drawDebug(org.newdawn.slick.Graphics graphics)
Renders debug information, such as the entity's boundaries and "name tag"void
drawFirstLayer(org.newdawn.slick.Graphics graphics)
Draws the first "layer", assumingisDualRendered
is true (below the player)private void
drawHealthBar(org.newdawn.slick.Graphics graphics)
Shows the entity's health above themprivate void
drawNameTag(org.newdawn.slick.Graphics graphics)
Draws the entity's "name tag", which istoString()
void
drawSecondLayer(org.newdawn.slick.Graphics graphics)
Draws the second "layer", assumingisDualRendered
is true (above the player)private boolean
isAbove(Entity e)
Returns whether or not the entity is "above" the other entityprivate boolean
isBelow(Entity e)
Returns whether or not the entity is "below" the other entityprivate boolean
isLeftOf(Entity e)
Returns whether or not the entity is to the "left" of the other entityprivate boolean
isRightOf(Entity e)
Returns whether or not the entity is to the "right" of the other entityprotected void
move(byte direction)
private void
move(byte direction, EntityBoundary boundary)
Updates the entity's location byspeed
, unless the specified boundary is outside of the game's windowprotected void
onMove(byte direction)
Called whenever the entity movesvoid
onSectorEnter(MapSector entering)
void
onSectorLeave(MapSector leaving)
private void
onSpriteChanged()
void
render(org.newdawn.slick.Graphics graphics)
protected abstract void
setBoundaries()
Sets the entity's boundariesabstract void
setCollisions()
Sets the entity's collisionsprotected abstract void
setInteractions()
Sets the entity's interactionsvoid
setPosition(int x, int y)
Sets the entity's x and y coordinates, as well as updating the coordinate deltasvoid
setSprite(int index, boolean update)
Sets the current spritevoid
setSprite(Sprite sprite)
void
setSprites(int index)
void
tick()
Ticks boundaries and interactionsjava.lang.String
toString()
void
x(int x)
void
x(int x, boolean setDelta)
void
y(int y)
void
y(int y, boolean setDelta)
-
Methods inherited from class net.egartley.beyondorigins.core.abstracts.Renderable
x, y
-
-
-
-
Field Detail
-
DIRECTION_UP
public static final byte DIRECTION_UP
- See Also:
- Constant Field Values
-
DIRECTION_DOWN
public static final byte DIRECTION_DOWN
- See Also:
- Constant Field Values
-
DIRECTION_LEFT
public static final byte DIRECTION_LEFT
- See Also:
- Constant Field Values
-
DIRECTION_RIGHT
public static final byte DIRECTION_RIGHT
- See Also:
- Constant Field Values
-
sprites
protected java.util.ArrayList<Sprite> sprites
The entity's sprites
-
sheets
protected java.util.ArrayList<SpriteSheet> sheets
The entity's sprite sheets
-
boundaries
public java.util.ArrayList<EntityBoundary> boundaries
Collection of the entity's boundaries
-
interactions
public java.util.ArrayList<EntityEntityInteraction> interactions
Collection of the entity's interactions
-
inventory
public EntityInventory inventory
-
sprite
public Sprite sprite
The sprite to use while rendering
-
image
protected org.newdawn.slick.Image image
The buffered image to use when rendering (default)
-
firstLayer
protected org.newdawn.slick.Image firstLayer
IfisDualRendered
is true, render this before the player ("below")
-
secondLayer
protected org.newdawn.slick.Image secondLayer
IfisDualRendered
is true, render this after the player ("above")
-
lastCollision
public EntityEntityCollision lastCollision
The most recent collision that has occurred for the entity. If no collisions have occurred within the entity's lifetime, this will be null
-
lastCollisionEvent
public EntityEntityCollisionEvent lastCollisionEvent
The most recent collision event to have occurred. This will be null if no collision event has yet to take place
-
defaultBoundary
public EntityBoundary defaultBoundary
The boundary to use if not specified
-
deltaX
public double deltaX
Less-than-one change in the x-coordinate, used for non-integer speeds
-
deltaY
public double deltaY
Less-than-one change in the y-coordinate, used for non-integer speeds
-
speed
public double speed
The entity's speed (magnitude of its location change when moving)
-
uuid
public int uuid
The entity's unique identification number. Usename
for user-friendly identification
-
health
public int health
Amount of damage the entity can take before dying
-
maximumHealth
public int maximumHealth
Maximum amount of health the entity can have
-
isAnimated
public boolean isAnimated
Whether or not the entity is animated
-
isTraversable
public boolean isTraversable
Whether or not other entities, mainly the player, can walk over it or not
-
isCollided
public boolean isCollided
Whether or not the entity is currently collided with another entity
-
canCollide
public boolean canCollide
Whether or not the entity is "allowed" to collide with others
-
isMovingUpwards
protected boolean isMovingUpwards
Whether or not the entity is currently moving upwards
-
isMovingDownwards
protected boolean isMovingDownwards
Whether or not the entity is currently moving downwards
-
isMovingLeftwards
protected boolean isMovingLeftwards
Whether or not the entity is currently moving leftwards
-
isMovingRightwards
protected boolean isMovingRightwards
Whether or not the entity is currently moving rightwards
-
isAllowedToMoveUpwards
public boolean isAllowedToMoveUpwards
Whether or not the entity is allowed to move upwards
-
isAllowedToMoveDownwards
public boolean isAllowedToMoveDownwards
Whether or not the entity is allowed to move downwards
-
isAllowedToMoveLeftwards
public boolean isAllowedToMoveLeftwards
Whether or not the entity is allowed to move leftwards
-
isAllowedToMoveRightwards
public boolean isAllowedToMoveRightwards
Whether or not the entity is allowed to move rightwards
-
isDualRendered
public boolean isDualRendered
Whether or not the entity has two different "layers" that are rendered before and after the player
-
isSectorSpecific
public boolean isSectorSpecific
Whether or not the entity is "bound" to, or only exists in, a specific map sector
-
name
public java.lang.String name
Human-readable identifier for the entity (not unique)
-
debugFont
private static final org.newdawn.slick.Font debugFont
-
nameTagBackgroundColor
private static final org.newdawn.slick.Color nameTagBackgroundColor
-
healthBarColor
private static final org.newdawn.slick.Color healthBarColor
-
healthBarWidth
private final int healthBarWidth
- See Also:
- Constant Field Values
-
nameTagWidth
private int nameTagWidth
-
setFontMetrics
private boolean setFontMetrics
Whether or not font metrics have been initialized. Sincerender(Graphics)
is called about 60 times a second, and the resulting font metrics object will always be the same, there is no need to keep re-computing it each timerender(Graphics)
is called
-
-
Constructor Detail
-
Entity
Entity(java.lang.String name)
-
Entity
Entity(java.lang.String name, Sprite sprite)
-
Entity
Entity(java.lang.String name, SpriteSheet sheet)
-
-
Method Detail
-
render
public void render(org.newdawn.slick.Graphics graphics)
- Specified by:
render
in classRenderable
-
drawFirstLayer
public void drawFirstLayer(org.newdawn.slick.Graphics graphics)
Draws the first "layer", assumingisDualRendered
is true (below the player)
-
drawSecondLayer
public void drawSecondLayer(org.newdawn.slick.Graphics graphics)
Draws the second "layer", assumingisDualRendered
is true (above the player)
-
drawDebug
public void drawDebug(org.newdawn.slick.Graphics graphics)
Renders debug information, such as the entity's boundaries and "name tag"
-
drawNameTag
private void drawNameTag(org.newdawn.slick.Graphics graphics)
Draws the entity's "name tag", which istoString()
-
drawHealthBar
private void drawHealthBar(org.newdawn.slick.Graphics graphics)
Shows the entity's health above them
-
drawBoundaries
private void drawBoundaries(org.newdawn.slick.Graphics graphics)
Draws all of the entity's boundaries
-
tick
public void tick()
Ticks boundaries and interactions- Specified by:
tick
in interfaceTickable
- See Also:
boundaries
-
setPosition
public void setPosition(int x, int y)
Sets the entity's x and y coordinates, as well as updating the coordinate deltas- Overrides:
setPosition
in classRenderable
- Parameters:
x
- The new x-coordinatey
- The new y-coordinate- See Also:
deltaX
,deltaY
-
x
public void x(int x)
- Overrides:
x
in classRenderable
-
y
public void y(int y)
- Overrides:
y
in classRenderable
-
x
public void x(int x, boolean setDelta)
-
y
public void y(int y, boolean setDelta)
-
onSectorEnter
public void onSectorEnter(MapSector entering)
-
onSectorLeave
public void onSectorLeave(MapSector leaving)
-
move
private void move(byte direction, EntityBoundary boundary)
Updates the entity's location byspeed
, unless the specified boundary is outside of the game's window
-
allowAllMovement
protected void allowAllMovement()
Allows the entity to move in all directions
-
onMove
protected void onMove(byte direction)
Called whenever the entity moves- Parameters:
direction
- Which direction the entity moved in- See Also:
DIRECTION_UP
,DIRECTION_DOWN
,DIRECTION_LEFT
,DIRECTION_RIGHT
,move(byte)
-
move
protected void move(byte direction)
Changes the entity's location (Renderable.x()
andRenderable.y()
) at a rate ofspeed
per call. Since there is no boundary parameter, the entity'sdefaultBoundary
will be used
-
isRightOf
private boolean isRightOf(Entity e)
Returns whether or not the entity is to the "right" of the other entity
-
isLeftOf
private boolean isLeftOf(Entity e)
Returns whether or not the entity is to the "left" of the other entity
-
isAbove
private boolean isAbove(Entity e)
Returns whether or not the entity is "above" the other entity
-
isBelow
private boolean isBelow(Entity e)
Returns whether or not the entity is "below" the other entity
-
setBoundaries
protected abstract void setBoundaries()
Sets the entity's boundaries- See Also:
boundaries
-
setCollisions
public abstract void setCollisions()
Sets the entity's collisions- See Also:
boundaries
-
setInteractions
protected abstract void setInteractions()
Sets the entity's interactions- See Also:
interactions
-
onSpriteChanged
private void onSpriteChanged()
-
setSprite
public void setSprite(int index, boolean update)
Sets the current sprite
-
setSprite
public void setSprite(Sprite sprite)
-
setSprites
public void setSprites(int index)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-