public final class World
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.util.HashMap<java.lang.Integer,BaseEntity> |
allEntities |
int |
nbr_artefacts
Number of artefacts in this world
|
int |
nbr_buildings
Number of buildings in this world
|
int |
nbr_movers
Number of moving entities in this world
|
int |
nbr_obstacles
Number of obstacles in this world
|
int |
nbr_walls
Number of walls in this world
|
double |
worldUpdateTime
The average time it takes for the world to update all the components in the world.
|
Constructor and Description |
---|
World(int width,
int height)
Create a world without cell space partitioning.
|
World(int width,
int height,
double partitionSize,
double partitionOverlap)
Create a world with cell space partitioning.
|
Modifier and Type | Method and Description |
---|---|
void |
add(BaseEntity entity)
This method must only be used before the main program starts.
|
void |
birth(BaseEntity entity,
double timeToBirth)
This is the preferred method to add an entity to the
world once the game is in progress i.e.
|
void |
cancelBirthsAndDeaths()
Cancels outstanding birth and deaths scheduled with birth and death methods.
|
void |
death(BaseEntity entity,
double timeToLive)
This is the preferred method to remove an entity from the
world once the game is in progress i.e.
|
void |
death(int entityID,
double timeToLive)
This is the preferred method to remove an entity from the
world once the game is in progress i.e.
|
void |
draw()
Deprecated.
|
void |
draw(double elapsedTime)
Any entity that requires to be rendered will have its own render object.
|
boolean |
exists(BaseEntity entity)
Determines whether the entity still exists in this world.
|
boolean |
exists(int id)
Determines whether the entity still exists in this world.
|
java.util.Set<Building> |
getBuildings(MovingEntity m)
For a particular moving entity get all the buildings in the same partition.
|
BaseEntity |
getEntity(int entityID)
Get the entity associated with a particular ID number.
|
java.util.Set<MovingEntity> |
getMovers(MovingEntity m)
For a particular moving entity get all the moving entities in the same partition.
|
java.util.Set<MovingEntity> |
getMovers(MovingEntity m,
double range)
Get a list of moving entities in partitions within a given range
of a moving entity.
|
java.util.Set<Obstacle> |
getObstacles(double x,
double y) |
java.util.Set<Obstacle> |
getObstacles(MovingEntity m)
Get a list of obstacles that need to be tested for obstacle avoidance.
|
java.util.Set<Obstacle> |
getObstacles(MovingEntity m,
double px,
double py)
Get a list of obstacles that are in the box made by the moving entity's position
and the position px,py
|
java.util.Set<Wall> |
getWalls(MovingEntity m)
Get a list of walls that need to be tested for wall avoidance.
|
java.util.Set<Wall> |
getWalls(MovingEntity m,
double px,
double py)
Get a list of walls that are in the box made by the moving entity's position
and the position px,py
|
boolean |
isCspOn() |
boolean |
isNoOverlapOn() |
void |
moveToWorldX(double wx)
Move the world view so it is centred about the given world position.
|
void |
moveToWorldXY(double wx,
double wy)
Move the world view so it is centred about the given world position.
|
void |
moveToWorldY(double wy)
Move the world view so it is centred about the given world position.
|
void |
noOverlap(boolean noOverlap) |
void |
panPixelX(int px)
Pan the world display by the given number of pixels.
|
void |
panPixelXY(int px,
int py)
Pan the world display by the given number of pixels.
|
void |
panPixelY(int py)
Pan the world display by the given number of pixels.
|
void |
panWorldX(double wx)
Pan the world display by the given world distance.
|
void |
panWorldXY(double wx,
double wy)
Pan the world display by the given world distance.
|
void |
panWorldY(double wy)
Pan the world display by the given world distance.
|
Vector2D |
pixel2world(int px,
int py,
Vector2D wxy)
Calculate the equivalent world position from a pixel position.
|
void |
printForceData()
Used to display all collected steering force data by Vehicle
A vehicle must have it's force logger activated with |
double |
scale()
Get the current viewScale (zoom factor)
|
void |
scale(double scale)
Resize the world due to changes in magnification
so that the image is centred in the display area.
|
void |
update(double deltaTime)
This is the core method which will loop through entity state machines (if any) then it will update
the positions and velocities of all moving entities (applying any steering behaviours used).
|
Domain |
viewOnWorld()
Get the extent of the world being drawn.
|
java.awt.Point |
world2pixel(double wx,
double wy,
java.awt.Point pxy)
Calculate the pixel position from a given world position.
|
java.awt.Point |
world2pixel(Vector2D wxy,
java.awt.Point pxy)
Calculate the pixel position from a given world position.
|
double |
xOffset()
Get the world x position equivalent to the left hand side of the display area.
|
double |
yOffset()
Get the world x position equivalent to the left hand side of the display area.
|
public static java.util.HashMap<java.lang.Integer,BaseEntity> allEntities
public int nbr_artefacts
public int nbr_buildings
public int nbr_obstacles
public int nbr_walls
public int nbr_movers
public double worldUpdateTime
public World(int width, int height)
(0,0) ___________________________________ X axis | | | | | | | | | | | | |__________________________| (width, height) | Y axis
moveTo, panPixel, panWorld & setScale methods.
width
- the physical screen display width in pixelsheight
- the physical screen display height in pixelspublic World(int width, int height, double partitionSize, double partitionOverlap)
(0,0) ___________________________________ X axis | | | | | | | | | | | | |__________________________| (width, height) | Y axis
moveTo, panPixel, panWorld & setScale methods.
partitionSize >= 5 x MCR
partitionOverlap >= 2 x MCR
partitionSize >= 2 x partitionOverlap
partitionOverlap > whisker length if using steering behaviours with wall avoidance enabled
width
- the physical screen display width in pixelsheight
- the physical screen display height in pixelspartitionSize
- the size of the partition in world distancepartitionOverlap
- the overlap between partitionspublic java.awt.Point world2pixel(double wx, double wy, java.awt.Point pxy)
wx
- world x positionwy
- world y positionpxy
- object to hold the calculate pixel positionpublic java.awt.Point world2pixel(Vector2D wxy, java.awt.Point pxy)
wxy
- world x,y positionpxy
- object to hold the calculate pixel positionpublic Vector2D pixel2world(int px, int py, Vector2D wxy)
px
- display screen pixel x positionpy
- display screen pixel x positionwxy
- a Vector2D object to hold the world positionpublic void scale(double scale)
scale
- the level of magnification (must be > 0)public double scale()
public void panPixelX(int px)
px
- pixels to pan horizontally.public void panPixelY(int py)
py
- pixels to pan vertically.public void panPixelXY(int px, int py)
px
- pixels to pan horizontally.py
- pixels to pan vertically.public void panWorldX(double wx)
wx
- world distance to pan horizontally.public void panWorldY(double wy)
wy
- world distance to pan vertically.public void panWorldXY(double wx, double wy)
wx
- world distance to pan horizontally.wy
- world distance to pan vertically.public void moveToWorldX(double wx)
wx
- centre horizontally about this value.public void moveToWorldY(double wy)
wy
- centre vertically about this value.public void moveToWorldXY(double wx, double wy)
wx
- centre horizontally about this value.wy
- centre vertically about this value.public double xOffset()
public double yOffset()
public Domain viewOnWorld()
public BaseEntity getEntity(int entityID)
entityID
- unique ID number for the entitypublic java.util.Set<Building> getBuildings(MovingEntity m)
m
- the moving entitypublic java.util.Set<MovingEntity> getMovers(MovingEntity m)
m
- the moving entitypublic java.util.Set<MovingEntity> getMovers(MovingEntity m, double range)
m
- the mover we are interested in getting the neighboursrange
- the radius of the circle surrounding neighbours.public java.util.Set<Wall> getWalls(MovingEntity m)
m
- the moving entitypublic java.util.Set<Wall> getWalls(MovingEntity m, double px, double py)
m
- the moving entitypx
- py
- public java.util.Set<Obstacle> getObstacles(MovingEntity m)
m
- the moving entitypublic java.util.Set<Obstacle> getObstacles(double x, double y)
public java.util.Set<Obstacle> getObstacles(MovingEntity m, double px, double py)
m
- the moving entitypx
- py
- public boolean exists(int id)
id
- the entity's ID numberpublic boolean exists(BaseEntity entity)
entity
- public void add(BaseEntity entity)
entity
- the entity to add.public void death(BaseEntity entity, double timeToLive)
setup()method.
entity
- the entity to dietimeToLive
- number of seconds of life leftpublic void death(int entityID, double timeToLive)
setup()method.
entityID
- the ID number of the entity to dietimeToLive
- number of seconds of life leftpublic void birth(BaseEntity entity, double timeToBirth)
setup()method.
entity
- timeToBirth
- public void cancelBirthsAndDeaths()
public void update(double deltaTime)
deltaTime
- the time in seconds since the last update.@Deprecated public void draw()
public void draw(double elapsedTime)
elapsedTime
- the elapsed time since the last updatepublic boolean isCspOn()
public boolean isNoOverlapOn()
public void noOverlap(boolean noOverlap)
noOverlap
- the ensureZeroOverlap to setpublic void printForceData()
vehicle.forceLoggerOn();
Processing library AI_for_2D_Games by Peter Lager. (C) 2013