AI for Games 1.1.1
Loading...
Searching...
No Matches
game2dai.entities.MovingEntity Class Reference
Inheritance diagram for game2dai.entities.MovingEntity:

Public Member Functions

 MovingEntity (Vector2D position, double radius, Vector2D velocity, double max_speed, Vector2D heading, double mass, double max_turn_rate, double max_force)
 
 MovingEntity (String name, Vector2D position, double radius, Vector2D velocity, double max_speed, Vector2D heading, double mass, double max_turn_rate, double max_force)
 
Vector2D prevPos ()
 
Vector2D velocity ()
 
MovingEntity velocity (Vector2D newVel)
 
MovingEntity velocity (double vx, double vy)
 
MovingEntity heading (Vector2D h)
 
MovingEntity heading (double x, double y)
 
Vector2D heading ()
 
Vector2D headingAtRest ()
 
MovingEntity headingAtRest (Vector2D restHeading)
 
void mass (double mass)
 
double mass ()
 
Vector2D side ()
 
double maxSpeed ()
 
MovingEntity maxSpeed (double maxSpeed)
 
double maxForce ()
 
MovingEntity maxForce (double mf)
 
boolean isSpeedMaxedOut ()
 
double speed ()
 
double speedSq ()
 
double maxTurnRate ()
 
MovingEntity maxTurnRate (double maxTurnRate)
 
double turnRate ()
 
MovingEntity turnRate (double turnRate)
 
double viewDistance ()
 
MovingEntity viewDistance (double viewDistance)
 
double viewFOV ()
 
MovingEntity viewFOV (double viewFOV)
 
MovingEntity viewFactors (double viewDistance, double viewFOV)
 
MovingEntity worldDomain (Domain wd)
 
MovingEntity worldDomain (Domain wd, int constraint)
 
MovingEntity worldDomainConstraint (int constraint)
 
Domain worldDomain ()
 
int worldDomainConstraint ()
 
boolean isEitherSide (double x0, double y0, double x1, double y1)
 
boolean canSee (World world, double x0, double y0)
 
boolean canSee (World world, Vector2D pos)
 
boolean rotateHeadingToFacePosition (double deltaTime, Vector2D faceTarget)
 
boolean rotateHeadingToAlignWith (double deltaTime, final Vector2D allignTo)
 
boolean isInDomain (Domain view)
 
boolean isOver (double px, double py)
 
void update (double deltaTime, World world)
 
void draw (double elapsedTime, World world)
 
void draw (World world)
 
- Public Member Functions inherited from game2dai.entities.BaseEntity
 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 ()
 

Protected Member Functions

void applyDomainConstraint ()
 

Protected Attributes

Domain wd = null
 
int domainConstraint = SBF.WRAP
 
Vector2D prevPos = new Vector2D()
 
Vector2D velocity = new Vector2D()
 
Vector2D heading = new Vector2D()
 
Vector2D side = new Vector2D()
 
double mass
 
double maxSpeed
 
double maxForce
 
double maxTurnRate
 
double currTurnRate
 
double prevTurnRate
 
double viewDistance = 50
 
double viewFOV = 1.047
 
- Protected Attributes inherited from game2dai.entities.BaseEntity
Integer entityID
 
String name = ""
 
Picture renderer = null
 
boolean visible = true
 
Vector2D pos = new Vector2D()
 
double colRadius
 

Private Attributes

Vector2D headingAtRest = null
 

Additional Inherited Members

- Public Attributes inherited from game2dai.entities.BaseEntity
String tag = ""
 
int tagNo = 0
 
- Package Attributes inherited from game2dai.entities.BaseEntity
boolean overlapAllowed = false
 

Detailed Description

This class that models the behaviour of a moving entity that is not acting under the influence of a steering behaviour.

Author
Peter Lager

Constructor & Destructor Documentation

◆ MovingEntity() [1/2]

game2dai.entities.MovingEntity.MovingEntity ( Vector2D  position,
double  radius,
Vector2D  velocity,
double  max_speed,
Vector2D  heading,
double  mass,
double  max_turn_rate,
double  max_force 
)

This is the constructor that should be used when creating an unnamed MovingEntity

Parameters
positioninitial world position
radiusbounding radius
velocityinitial velocity
max_speedmaximum speed
headinginitial heading
massinitial mass
max_turn_ratehow fast the entity can turn (radians / second)
max_forcethe maximum force that can be applied by a steering behaviour

◆ MovingEntity() [2/2]

game2dai.entities.MovingEntity.MovingEntity ( String  name,
Vector2D  position,
double  radius,
Vector2D  velocity,
double  max_speed,
Vector2D  heading,
double  mass,
double  max_turn_rate,
double  max_force 
)

This is the constructor that should be used when creating a named MovingEntity

Parameters
namethe name of the entity
positioninitial world position
radiusbounding radius
velocityinitial velocity
max_speedmaximum speed
headinginitial heading
massinitial mass
max_turn_ratehow fast the entity can turn (radians / second)
max_forcethe maximum force that can be applied by a steering behaviour

Member Function Documentation

◆ applyDomainConstraint()

void game2dai.entities.MovingEntity.applyDomainConstraint ( )
protected

After calculating the entity's position it is then constrained by the domain constraint WRAP or REBOUND

◆ canSee() [1/2]

boolean game2dai.entities.MovingEntity.canSee ( World  world,
double  x0,
double  y0 
)

This method determines whether this entity can see a particular location in the world.
It first checks to see if it is within this entity's view distance and field of view (FOV). If it is then it checks to see if there are any walls or obstacles between them.

Parameters
worldthe world responsible for this entity
x0the x position of the location to test
y0the y position of the location to test
Returns
true if the entity can see the location

◆ canSee() [2/2]

boolean game2dai.entities.MovingEntity.canSee ( World  world,
Vector2D  pos 
)

This method determines whether this entity can see a particular location in the world.
It first checks to see if it is within this entity's view distance and field of view (FOV). If it is then it checks to see if there are any walls or obstacles between them.

Parameters
worldthe world responsible for this entity
posthe location to test
Returns
true if the entity can see the location

◆ draw() [1/2]

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

◆ draw() [2/2]

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

◆ heading() [1/3]

Vector2D game2dai.entities.MovingEntity.heading ( )

Get the current heading for this entity

Returns
the entity's heading

◆ heading() [2/3]

MovingEntity game2dai.entities.MovingEntity.heading ( double  x,
double  y 
)

/** Sets the direction the entity is facing. This is not the same as the but will rotate towards the velocity vector at a speed dependent on the turn-rate.

Parameters
x
y

◆ heading() [3/3]

MovingEntity game2dai.entities.MovingEntity.heading ( Vector2D  h)

Sets the direction the entity is facing. This is not the same as the but will rotate towards the velocity vector at a speed dependent on the turn-rate.

Parameters
h

◆ headingAtRest() [1/2]

Vector2D game2dai.entities.MovingEntity.headingAtRest ( )

get the default heading for this entity.

Returns
the headingAtRest

◆ headingAtRest() [2/2]

MovingEntity game2dai.entities.MovingEntity.headingAtRest ( Vector2D  restHeading)

Set the default heading for this entity. If the parameter is

null

then the default heading is cancelled. The default heading will be normalised.

Parameters
restHeadingthe headingAtRest to set

◆ isEitherSide()

boolean game2dai.entities.MovingEntity.isEitherSide ( double  x0,
double  y0,
double  x1,
double  y1 
)

Determines whether two points are either side of this moving entity. If they are then they cannot 'see' each other.

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

◆ isInDomain()

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

Determine whether this moving 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 from game2dai.entities.BaseEntity.

◆ isOver()

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

Determines whether a point is over this entity's collision circle

Reimplemented from game2dai.entities.BaseEntity.

◆ isSpeedMaxedOut()

boolean game2dai.entities.MovingEntity.isSpeedMaxedOut ( )

See if the current speed exceeds the maximum speed permitted.

Returns
true if the speed is greater or equal to the max speed.

◆ mass() [1/2]

double game2dai.entities.MovingEntity.mass ( )

Get the mass of this entity.

Returns
the entity's mass

◆ mass() [2/2]

void game2dai.entities.MovingEntity.mass ( double  mass)

Change the mass of the entity. The heavier the mass the more force is needed to move it.
The new mass must be greater than zero otherwise the current mass will be unchanged..

Parameters
massthe new mass

◆ maxForce() [1/2]

double game2dai.entities.MovingEntity.maxForce ( )

Gets the maximum force that can be applied to this entity.

Returns
max force allowed

Reimplemented in game2dai.entities.Vehicle.

◆ maxForce() [2/2]

MovingEntity game2dai.entities.MovingEntity.maxForce ( double  mf)

Sets the maximum force that can be applied to this entity.

Parameters
mfmax force allowed

◆ maxSpeed() [1/2]

double game2dai.entities.MovingEntity.maxSpeed ( )

Get the maximum speed allowed for this entity.

Returns
max speed allowed

◆ maxSpeed() [2/2]

MovingEntity game2dai.entities.MovingEntity.maxSpeed ( double  maxSpeed)

Sets the maximum speed this entity is allowed to reach

Parameters
maxSpeed

◆ maxTurnRate() [1/2]

double game2dai.entities.MovingEntity.maxTurnRate ( )

Get the maximum turn rate for this entity

◆ maxTurnRate() [2/2]

MovingEntity game2dai.entities.MovingEntity.maxTurnRate ( double  maxTurnRate)

Sets the maximum turnrate for this entity.

Parameters
maxTurnRate

◆ prevPos()

Vector2D game2dai.entities.MovingEntity.prevPos ( )

Gets the position of the entity prior to the last update.

Returns
previous position before last update

◆ rotateHeadingToAlignWith()

boolean game2dai.entities.MovingEntity.rotateHeadingToAlignWith ( double  deltaTime,
final Vector2D  allignTo 
)

Rotate this entities heading to align with a vector over a given time period

Parameters
deltaTimetime (seconds) to turn entity
allignTovector to align entities heading with
Returns
true if facing alignment vector

◆ rotateHeadingToFacePosition()

boolean game2dai.entities.MovingEntity.rotateHeadingToFacePosition ( double  deltaTime,
Vector2D  faceTarget 
)

--------------------— RotateHeadingToFacePosition ---------------—

given a target position, this method rotates the entity's heading and side vectors by an amount not greater than m_dMaxTurnRate until it directly faces the target.

Parameters
deltaTimetime
faceTargetthe world position to face
Returns
true when the heading is facing in the desired direction

◆ side()

Vector2D game2dai.entities.MovingEntity.side ( )

Get the side vector for this entity. The side vector is always perpendicular to the heading and normalised.

Returns
the side vector

◆ speed()

double game2dai.entities.MovingEntity.speed ( )

Get the entity's speed.
This is the scalar length of the velocity vector.

Returns
speed in direction of travel

◆ speedSq()

double game2dai.entities.MovingEntity.speedSq ( )

Get the square of the entity's speed.

Returns
speed in direction of travel squared

◆ turnRate() [1/2]

double game2dai.entities.MovingEntity.turnRate ( )

Get the current turn rate

◆ turnRate() [2/2]

MovingEntity game2dai.entities.MovingEntity.turnRate ( double  turnRate)

Set the current turnrate making sure it does not exceed the maximum allowed.

Parameters
turnRate

◆ update()

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

Update method for any moving entity in the world that is not under the influence of a steering behaviour.

Parameters
deltaTimeelapsed time since last update
worldthe game world object

Reimplemented from game2dai.entities.BaseEntity.

Reimplemented in game2dai.entities.Vehicle.

◆ velocity() [1/3]

Vector2D game2dai.entities.MovingEntity.velocity ( )

Gets the current velocity

Returns
the current velocity of this entity

◆ velocity() [2/3]

MovingEntity game2dai.entities.MovingEntity.velocity ( double  vx,
double  vy 
)

Sets the current velocity

Parameters
vx
vy

◆ velocity() [3/3]

MovingEntity game2dai.entities.MovingEntity.velocity ( Vector2D  newVel)

Sets the current velocity for this entity

Parameters
newVelthe new velocity vector

◆ viewDistance() [1/2]

double game2dai.entities.MovingEntity.viewDistance ( )

Get the distance that this entity can see.

Returns
the viewDistance

◆ viewDistance() [2/2]

MovingEntity game2dai.entities.MovingEntity.viewDistance ( double  viewDistance)

This sets the distance that this entity can see. It is used by the canSee() method.

Parameters
viewDistancethe viewDistance to set

◆ viewFactors()

MovingEntity game2dai.entities.MovingEntity.viewFactors ( double  viewDistance,
double  viewFOV 
)

Sets the distance and total field of view angle for this entity.

Parameters
viewDistance
viewFOVthe viewFOV to set

◆ viewFOV() [1/2]

double game2dai.entities.MovingEntity.viewFOV ( )

Get the field of view for this entity.

Returns
the viewFOV

◆ viewFOV() [2/2]

MovingEntity game2dai.entities.MovingEntity.viewFOV ( double  viewFOV)

Sets the total field of view angle for this entity.

Parameters
viewFOVthe viewFOV to set

◆ worldDomain() [1/3]

Domain game2dai.entities.MovingEntity.worldDomain ( )

Get the world domain for this entity.

Returns
the world domain

◆ worldDomain() [2/3]

MovingEntity game2dai.entities.MovingEntity.worldDomain ( Domain  wd)

Set the world domain for this entity and its' constraint to the default value of SBF.WRAP this means that when an entity leaves the domain it is wrapped to the other side.

Parameters
wdthe world domain for this entity

◆ worldDomain() [3/3]

MovingEntity game2dai.entities.MovingEntity.worldDomain ( Domain  wd,
int  constraint 
)

Set the world domain

Parameters
wdthe world domain for this entity
constraintSBF.WRAP or SBF.REBOUND or SBF.PASS_THROUGH

◆ worldDomainConstraint() [1/2]

int game2dai.entities.MovingEntity.worldDomainConstraint ( )

Get the world domain constraint for this entity.

Returns
the world domain constraint (ie SBF.WRAP or SBF.REBOUND or SBF.PASS_THROUGH)

◆ worldDomainConstraint() [2/2]

MovingEntity game2dai.entities.MovingEntity.worldDomainConstraint ( int  constraint)

Set the constraint to be applied to the world domain.

Parameters
constraintSBF.WRAP or SBF.REBOUND or SBF.PASS_THROUGH

Member Data Documentation

◆ maxForce

double game2dai.entities.MovingEntity.maxForce
protected

Reimplemented in game2dai.entities.Vehicle.


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