public abstract class BaseEntity extends java.lang.Object implements java.lang.Comparable<BaseEntity>
Modifier and Type | Class and Description |
---|---|
static class |
BaseEntity.DepthOrder
This comparator is used to control the order the entities are drawn to the screen.
|
Modifier and Type | Field and Description |
---|---|
java.lang.String |
tag
The tag attribute is not used by the library code.
|
int |
tagNo
The tagNo attribute is not used by the library code.
|
Constructor and Description |
---|
BaseEntity()
Default constructor
|
BaseEntity(java.lang.String name)
Constructor will give the entity a unique ID.
|
BaseEntity(java.lang.String entityName,
Vector2D entityPos,
double entityColRadius)
Constructor will give the entity a unique ID.
|
Modifier and Type | Method and Description |
---|---|
void |
addFSM()
This is the only way to add a finite state machine to the entity.
|
void |
born(World world,
double timeToLive)
This is the only safe way to add an entity to the World object once initialisation has
finished and the game/simulation is in play.
|
double |
colRadius()
Get the bounding radius for this object.
|
BaseEntity |
colRadius(double colRadius)
Set the bounding radius for this object
|
int |
compareTo(BaseEntity o)
Compare 2 entities based on their entity ID numbers
|
void |
die(World world,
double timeToLive)
This is the only safe way to remove an entity from the World object.
|
void |
draw(double elapsedTime,
World world)
DO NOT CALL THIS METHOD DIRECTLY
If this shape has a renderer and is visible call the renderer's draw method passing all appropriate information. |
void |
draw(World world)
Deprecated.
|
FiniteStateMachine |
FSM()
Returns a reference to the entity's finite state machine or
null if there is no FSM
|
boolean |
hasFSM()
Does this entity have a finite state machine
|
int |
ID()
Get the entity's unique ID number
|
boolean |
isEitherSide(double x0,
double y0,
double x1,
double y1)
Determines whether the two points given are 'either side of the object' if true then
the two positions are not visible to each other.
|
boolean |
isEitherSide(Vector2D p0,
Vector2D p1)
Determines whether the two points given are 'either side of the object' if true then
the two positions are not visible to each other.
|
boolean |
isInDomain(Domain view)
Determine whether this entity is inside or part inside the domain.
|
boolean |
isOver(double px,
double py)
Determine whether the given world position is over a given entity.
|
boolean |
isOverLapAllowed()
Should this entity be considered if the world is enforcing
the no-overlap rule.
|
boolean |
isVisible()
Is this entity visible
|
BaseEntity |
moveBy(double x,
double y)
Move the current position for this entity by the specified amount.
|
BaseEntity |
moveBy(Vector2D p)
Move the current position for this entity by the specified amount.
|
BaseEntity |
moveTo(double x,
double y)
Set the current position for this entity.
|
BaseEntity |
moveTo(Vector2D p)
Set the current position for this entity.
|
java.lang.String |
name()
Get the current name of the entity.
|
BaseEntity |
name(java.lang.String name)
Change the name of this entity
|
BaseEntity |
overLapAllowed(boolean overLapAllowed)
Set whether the entity should be considered when (and if) the
world is enforcing the no overLap rule.
|
Vector2D |
pos()
Get the current position.
|
boolean |
removeFSM()
This is the only way to remove a FSM once added.
|
Picture |
renderer()
Get the render object.
|
BaseEntity |
renderer(Picture renderer)
Add a render object to this entity.
|
java.lang.String |
toString()
Entity ID number and name returned as a String
|
void |
update(double deltaTime,
World world)
The main update method for an entity.
|
void |
updateFSM(double deltaTime,
World world)
If this entity has a state machine then call its update method.
|
BaseEntity |
visible(boolean visible)
Set the entity's visibility
|
int |
Z()
Get the draw order depth.
|
BaseEntity |
Z(int z)
Set the draw order depth.
|
public java.lang.String tag
"Entity entityID"
public int tagNo
public BaseEntity()
public BaseEntity(java.lang.String name)
name
- the name of this entity - default name is used if none provided.public BaseEntity(java.lang.String entityName, Vector2D entityPos, double entityColRadius)
entityName
- the name of this entity - default name is used if none provided.entityPos
- the world position for this entityentityColRadius
- the bounding radius for this entitypublic int ID()
public void updateFSM(double deltaTime, World world)
deltaTime
- elapsed time since last update (seconds)world
- the game world objectpublic FiniteStateMachine FSM()
public boolean hasFSM()
public void addFSM()
public boolean removeFSM()
public int Z()
public BaseEntity Z(int z)
z
- the z to setpublic boolean isVisible()
public BaseEntity visible(boolean visible)
visible
- true or falsepublic double colRadius()
public BaseEntity colRadius(double colRadius)
colRadius
- the collision radius to setpublic boolean isOverLapAllowed()
public BaseEntity overLapAllowed(boolean overLapAllowed)
overLapAllowed
- public boolean isInDomain(Domain view)
view
- the world domainpublic boolean isOver(double px, double py)
px
- x position of point of interestpy
- y position of point of interestpublic BaseEntity renderer(Picture renderer)
renderer
- the renderer to use (it must implement Renderer)public Picture renderer()
public void die(World world, double timeToLive)
world
- the world to remove this entity intimeToLive
- time left to stay in the world in secondspublic void born(World world, double timeToLive)
world
- the world to add this entity totimeToLive
- time left to wait before adding to the world in secondspublic BaseEntity moveTo(double x, double y)
x
- world x positiony
- world y positionpublic BaseEntity moveTo(Vector2D p)
p
- the position to setpublic BaseEntity moveBy(double x, double y)
x
- world x distance to movey
- world y distance to movepublic BaseEntity moveBy(Vector2D p)
p
- the vector to move bypublic Vector2D pos()
public BaseEntity name(java.lang.String name)
name
- the new name to usepublic java.lang.String name()
public boolean isEitherSide(double x0, double y0, double x1, double y1)
x0
- x position of first point of interesty0
- y position of first point of interestx1
- x position of second point of interesty1
- y position of second point of interestpublic boolean isEitherSide(Vector2D p0, Vector2D p1)
p0
- first point of interestp1
- second point of interestpublic void update(double deltaTime, World world)
deltaTime
- elapsed time since last updateworld
- the game world object@Deprecated public void draw(World world)
public void draw(double elapsedTime, World world)
public int compareTo(BaseEntity o)
compareTo
in interface java.lang.Comparable<BaseEntity>
public java.lang.String toString()
toString
in class java.lang.Object
Processing library AI_for_2D_Games by Peter Lager. (C) 2013