AI for Games 1.1.1
Loading...
Searching...
No Matches
game2dai.entities.BaseEntity Class Referenceabstract
Inheritance diagram for game2dai.entities.BaseEntity:

Classes

class  DepthOrder
 

Public Member Functions

 BaseEntity ()
 
 BaseEntity (String name)
 
 BaseEntity (String entityName, Vector2D entityPos, double entityColRadius)
 
int ID ()
 
void updateFSM (double deltaTime, World world)
 
FiniteStateMachine FSM ()
 
boolean hasFSM ()
 
void addFSM ()
 
boolean removeFSM ()
 
int Z ()
 
BaseEntity Z (int z)
 
boolean isVisible ()
 
BaseEntity visible (boolean visible)
 
double colRadius ()
 
BaseEntity colRadius (double colRadius)
 
boolean isOverLapAllowed ()
 
BaseEntity overLapAllowed (boolean overLapAllowed)
 
boolean isInDomain (Domain view)
 
boolean isOver (double px, double py)
 
BaseEntity renderer (Picture renderer)
 
Picture renderer ()
 
void die (World world, double timeToLive)
 
void born (World world, double timeToLive)
 
BaseEntity moveTo (double x, double y)
 
BaseEntity moveTo (Vector2D p)
 
BaseEntity moveBy (double x, double y)
 
BaseEntity moveBy (Vector2D p)
 
Vector2D pos ()
 
BaseEntity name (String name)
 
String name ()
 
boolean isEitherSide (double x0, double y0, double x1, double y1)
 
boolean isEitherSide (Vector2D p0, Vector2D p1)
 
void update (double deltaTime, World world)
 
void draw (World world)
 
void draw (double elapsedTime, World world)
 
int compareTo (BaseEntity o)
 
String toString ()
 

Public Attributes

String tag = ""
 
int tagNo = 0
 

Protected Attributes

Integer entityID
 
String name = ""
 
Picture renderer = null
 
boolean visible = true
 
Vector2D pos = new Vector2D()
 
double colRadius
 

Package Attributes

boolean overlapAllowed = false
 

Private Attributes

FiniteStateMachine fsm = null
 
int z = 0
 

Static Private Attributes

static int nextID = Integer.MIN_VALUE
 

Detailed Description

This is the base class for all game entities.

Author
Peter Lager

Constructor & Destructor Documentation

◆ BaseEntity() [1/3]

game2dai.entities.BaseEntity.BaseEntity ( )

Default constructor

◆ BaseEntity() [2/3]

game2dai.entities.BaseEntity.BaseEntity ( String  name)

Constructor will give the entity a unique ID.

Parameters
namethe name of this entity - default name is used if none provided.

◆ BaseEntity() [3/3]

game2dai.entities.BaseEntity.BaseEntity ( String  entityName,
Vector2D  entityPos,
double  entityColRadius 
)

Constructor will give the entity a unique ID.

Parameters
entityNamethe name of this entity - default name is used if none provided.
entityPosthe world position for this entity
entityColRadiusthe bounding radius for this entity

Member Function Documentation

◆ addFSM()

void game2dai.entities.BaseEntity.addFSM ( )

This is the only way to add a finite state machine to the entity.

◆ born()

void game2dai.entities.BaseEntity.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. It does not add the entity directly but schedules it for addition at the start of the world update() method.
During initialisation (i.e. setup) it is recommended that you use the World add(0 method instead.

Parameters
worldthe world to add this entity to
timeToLivetime left to wait before adding to the world in seconds

◆ colRadius() [1/2]

double game2dai.entities.BaseEntity.colRadius ( )

Get the bounding radius for this object.

Returns
the collision radius

◆ colRadius() [2/2]

BaseEntity game2dai.entities.BaseEntity.colRadius ( double  colRadius)

Set the bounding radius for this object

Parameters
colRadiusthe collision radius to set

◆ compareTo()

int game2dai.entities.BaseEntity.compareTo ( BaseEntity  o)

Compare 2 entities based on their entity ID numbers

◆ die()

void game2dai.entities.BaseEntity.die ( World  world,
double  timeToLive 
)

This is the only safe way to remove an entity from the World object. It does not remove the object directly but schedules it for removal at the start of the world update() method.

Parameters
worldthe world to remove this entity in
timeToLivetime left to stay in the world in seconds

◆ draw() [1/2]

void game2dai.entities.BaseEntity.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.

This should be overridden in child classes

Reimplemented in game2dai.entities.MovingEntity.

◆ draw() [2/2]

void game2dai.entities.BaseEntity.draw ( World  world)

DO NOT CALL THIS METHOD DIRECTLY
This method is left to ensure backward compatibility with library versions prior to 1.0
Use the draw(elapsedTime, world) method instead.

This should be overridden in child classes

Reimplemented in game2dai.entities.MovingEntity.

◆ FSM()

FiniteStateMachine game2dai.entities.BaseEntity.FSM ( )

Returns a reference to the entity's finite state machine or null if there is no FSM

◆ hasFSM()

boolean game2dai.entities.BaseEntity.hasFSM ( )

Does this entity have a finite state machine

Returns
true if the entity has a FSM else false

◆ ID()

int game2dai.entities.BaseEntity.ID ( )

Get the entity's unique ID number

◆ isEitherSide() [1/2]

boolean game2dai.entities.BaseEntity.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.
This should be overridden in child classes.

Parameters
x0x position of first point of interest
y0y position of first point of interest
x1x position of second point of interest
y1y position of second point of interest
Returns
true if the points are either side else false

Reimplemented in game2dai.entities.Building, game2dai.entities.MovingEntity, game2dai.entities.Obstacle, and game2dai.entities.Wall.

◆ isEitherSide() [2/2]

boolean game2dai.entities.BaseEntity.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.
This should be overridden in child classes.

Parameters
p0first point of interest
p1second point of interest
Returns
true if the points are either side else false

◆ isInDomain()

boolean game2dai.entities.BaseEntity.isInDomain ( Domain  view)

Determine whether this entity is inside or part inside the domain. This method is used by the world draw method to see if this entity should be drawn.

Parameters
viewthe world domain
Returns
true if any part of this entity is inside the domain

Reimplemented in game2dai.entities.Artefact, game2dai.entities.Building, game2dai.entities.MovingEntity, game2dai.entities.Obstacle, and game2dai.entities.Wall.

◆ isOver()

boolean game2dai.entities.BaseEntity.isOver ( double  px,
double  py 
)

Determine whether the given world position is over a given entity.

Parameters
pxx position of point of interest
pyy position of point of interest
Returns
true if over this entity

Reimplemented in game2dai.entities.Building, game2dai.entities.MovingEntity, game2dai.entities.Obstacle, and game2dai.entities.Wall.

◆ isOverLapAllowed()

boolean game2dai.entities.BaseEntity.isOverLapAllowed ( )

Should this entity be considered if the world is enforcing the no-overlap rule.

◆ isVisible()

boolean game2dai.entities.BaseEntity.isVisible ( )

Is this entity visible

Returns
the visible

◆ moveBy() [1/2]

BaseEntity game2dai.entities.BaseEntity.moveBy ( double  x,
double  y 
)

Move the current position for this entity by the specified amount.

Parameters
xworld x distance to move
yworld y distance to move

◆ moveBy() [2/2]

BaseEntity game2dai.entities.BaseEntity.moveBy ( Vector2D  p)

Move the current position for this entity by the specified amount.

Parameters
pthe vector to move by

◆ moveTo() [1/2]

BaseEntity game2dai.entities.BaseEntity.moveTo ( double  x,
double  y 
)

Set the current position for this entity.

Parameters
xworld x position
yworld y position

◆ moveTo() [2/2]

BaseEntity game2dai.entities.BaseEntity.moveTo ( Vector2D  p)

Set the current position for this entity.

Parameters
pthe position to set

◆ name() [1/2]

String game2dai.entities.BaseEntity.name ( )

Get the current name of the entity.

◆ name() [2/2]

BaseEntity game2dai.entities.BaseEntity.name ( String  name)

Change the name of this entity

Parameters
namethe new name to use

◆ overLapAllowed()

BaseEntity game2dai.entities.BaseEntity.overLapAllowed ( boolean  overLapAllowed)

Set whether the entity should be considered when (and if) the world is enforcing the no overLap rule.

Parameters
overLapAllowed
Returns
this entity

◆ pos()

Vector2D game2dai.entities.BaseEntity.pos ( )

Get the current position.

Returns
current position

◆ removeFSM()

boolean game2dai.entities.BaseEntity.removeFSM ( )

This is the only way to remove a FSM once added. The FSM is always removed,

Returns
true if the entity had a FSM to remove., else false.

◆ renderer() [1/2]

Picture game2dai.entities.BaseEntity.renderer ( )

Get the render object. This is useful if you want to change how an object is drawn during a game. In most cases you will have to cast it to the appropriate type before using it.

Returns
the render object.

◆ renderer() [2/2]

BaseEntity game2dai.entities.BaseEntity.renderer ( Picture  renderer)

Add a render object to this entity. This is essential if you want to display the entity.
Assumes that if the parameter is not null then you want to see this entity. If you don't then

Parameters
rendererthe renderer to use (it must implement Renderer)

◆ toString()

String game2dai.entities.BaseEntity.toString ( )

Entity ID number and name returned as a String

Reimplemented in game2dai.entities.Building, game2dai.entities.Obstacle, and game2dai.entities.Vehicle.

◆ update()

void game2dai.entities.BaseEntity.update ( double  deltaTime,
World  world 
)

The main update method for an entity. This method will be called by the world update method if the entity has been 'added' to the world.

Parameters
deltaTimeelapsed time since last update
worldthe game world object

Reimplemented in game2dai.entities.MovingEntity, and game2dai.entities.Vehicle.

◆ updateFSM()

void game2dai.entities.BaseEntity.updateFSM ( double  deltaTime,
World  world 
)

If this entity has a state machine then call its update method.

Parameters
deltaTimeelapsed time since last update (seconds)
worldthe game world object

◆ visible()

BaseEntity game2dai.entities.BaseEntity.visible ( boolean  visible)

Set the entity's visibility

Parameters
visibletrue or false

◆ Z() [1/2]

int game2dai.entities.BaseEntity.Z ( )

Get the draw order depth.

Returns
the z

◆ Z() [2/2]

BaseEntity game2dai.entities.BaseEntity.Z ( int  z)

Set the draw order depth. The greater the value of z the closer it is to the viewer.

Parameters
zthe z to set

Member Data Documentation

◆ tag

String game2dai.entities.BaseEntity.tag = ""

The tag attribute is not used by the library code. It is there for the user to use in any way they wish.
When the entity is created it is initialised to

"Entity <i>entityID</i>"

<br<blockquote>‍

Where entityID is the unique id created by the library for this entity.

◆ tagNo

int game2dai.entities.BaseEntity.tagNo = 0

The tagNo attribute is not used by the library code. It is there for the user to use in any way they wish.


The documentation for this class was generated from the following file: