java.lang.Objectgreenfoot.World
public abstract class World
World is the world that Actors live in. It is a two-dimensional grid of
cells.
All Actor are associated with a World and can get access to the world object.
The size of cells can be specified at world creation time, and is constant
after creation. Simple scenarios may use large cells that entirely contain
the representations of objects in a single cell. More elaborate scenarios may
use smaller cells (down to single pixel size) to achieve fine-grained
placement and smoother animation.
The world background can be decorated with drawings or images.
Actor
Field Summary | |
---|---|
(package private) static greenfoot.util.Version |
VERSION
Version number of the Greenfoot API |
Constructor Summary | |
---|---|
World(int worldWidth,
int worldHeight,
int cellSize)
Construct a new world. |
Method Summary | |
---|---|
void |
addObject(greenfoot.Actor object,
int x,
int y)
Add an Actor to the world (at the object's specified location). |
greenfoot.GreenfootImage |
getBackground()
Return the world's background image. |
(package private) double |
getCellCenter(int l)
Returns the center of the cell. |
int |
getCellSize()
Return the size of a cell (in pixels). |
java.awt.Color |
getColorAt(int x,
int y)
Return the color at the center of the cell. |
int |
getHeight()
Return the height of the world (in number of cells). |
(package private) int |
getHeightInPixels()
Get the height of the world in pixels. |
(package private) java.util.List |
getIntersectingObjects(greenfoot.Actor actor,
java.lang.Class cls)
Return all the objects that intersect the given object. |
(package private) java.util.List |
getNeighbours(int x,
int y,
int distance,
boolean diag,
java.lang.Class cls)
Returns the neighbours to the given location. |
java.util.List |
getObjects(java.lang.Class cls)
Get all the objects in the world. If iterating through these objects, you should synchronize on this world to avoid ConcurrentModificationException. |
java.util.List |
getObjectsAt(int x,
int y,
java.lang.Class cls)
Return all objects at a given cell. |
(package private) java.util.Collection |
getObjectsAtPixel(int x,
int y)
|
(package private) java.util.List |
getObjectsInDirection(int x0,
int y0,
int angle,
int length,
java.lang.Class cls)
Return all objects that intersect a straight line from the location at a specified angle. |
(package private) java.util.List |
getObjectsInRange(int x,
int y,
int r,
java.lang.Class cls)
Returns all objects with the logical location within the specified circle. |
(package private) java.util.List<greenfoot.Actor> |
getObjectsList()
Get the list of all objects in the world. |
(package private) greenfoot.Actor |
getOneIntersectingObject(greenfoot.Actor object,
java.lang.Class cls)
|
(package private) greenfoot.Actor |
getOneObjectAt(greenfoot.Actor object,
int dx,
int dy,
java.lang.Class cls)
|
(package private) static rmiextension.wrappers.RObject |
getRObject(java.lang.Object obj)
Gets the remote reference to the obj. |
int |
getWidth()
Return the width of the world (in number of cells). |
(package private) int |
getWidthInPixels()
Get the width of the world in pixels. |
boolean |
isTiled()
Returns true if the world is tiled. |
(package private) void |
paintDebug(java.awt.Graphics g)
|
void |
removeObject(greenfoot.Actor object)
Remove an object from the world. |
void |
removeObjects(java.util.Collection objects)
Remove a list of objects from the world. |
void |
setBackground(greenfoot.GreenfootImage image)
Set a background image for the world. |
void |
setBackground(java.lang.String filename)
Set a background image for the world from an image file. |
void |
setTiled(boolean tiled)
If set to true, the background image will be tiled to fill out the entire background of the world. |
(package private) void |
startSequence()
Used to indicate the start of an animation sequence. |
(package private) int |
toCellCeil(int i)
|
(package private) int |
toCellFloor(int i)
|
(package private) void |
updateObjectLocation(greenfoot.Actor object,
int oldX,
int oldY)
|
(package private) void |
updateObjectSize(greenfoot.Actor object)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static final greenfoot.util.Version VERSION
Constructor Detail |
---|
public World(int worldWidth, int worldHeight, int cellSize)
worldWidth
- The width of the world (in cells).worldHeight
- The height of the world (in cells).cellSize
- Size of a cell in pixels.Method Detail |
---|
public void addObject(greenfoot.Actor object, int x, int y) throws java.lang.IndexOutOfBoundsException
object
- The new object to add.
java.lang.IndexOutOfBoundsException
- If the coordinates are outside the
bounds of the world.public greenfoot.GreenfootImage getBackground()
double getCellCenter(int l)
l
- Cell location.
public int getCellSize()
public java.awt.Color getColorAt(int x, int y)
java.lang.IndexOutOfBoundsException
- If the pixel location is not within the world bounds. If there is no background image at the location it will return Color.WHITE.public int getHeight()
int getHeightInPixels()
java.util.List getIntersectingObjects(greenfoot.Actor actor, java.lang.Class cls)
actor
- An Actor in the worldcls
- Class of objects to look for (null or Object.class will find
all classes)java.util.List getNeighbours(int x, int y, int distance, boolean diag, java.lang.Class cls)
x
- Locationy
- Locationdistance
- Distance in which to look for other objectsdiag
- Is the distance also diagonal?cls
- Class of objects to look for (null or Object.class will find
all classes)
public java.util.List getObjects(java.lang.Class cls)
The objects are returned in their paint order. The first object in the List is the one painted first. The last object is the one painted on top of all other objects.
If a class is specified as a parameter, only objects of that class (or its subclasses) will be returned.
cls
- Class of objects to look for ('null' will find all objects).
public java.util.List getObjectsAt(int x, int y, java.lang.Class cls)
An object is defined to be at that cell if its graphical representation overlaps with the cell at any point.
x
- X-coordinate of the cell to be checked.y
- Y-coordinate of the cell to be checked.cls
- Class of objects to look return ('null' will return all
objects).java.util.Collection getObjectsAtPixel(int x, int y)
java.util.List getObjectsInDirection(int x0, int y0, int angle, int length, java.lang.Class cls)
x
- x-coordinatey
- y-coordinateangle
- The angle relative to current rotation of the object.
(0-359)length
- How far we want to look (in cells)cls
- Class of objects to look for (passing 'null' will find all
objects).java.util.List getObjectsInRange(int x, int y, int r, java.lang.Class cls)
x
- Center of the cirley
- Center of the cirler
- Radius of the cirlecls
- Class of objects to look for (null or Object.class will find
all classes)java.util.List<greenfoot.Actor> getObjectsList()
greenfoot.Actor getOneIntersectingObject(greenfoot.Actor object, java.lang.Class cls)
greenfoot.Actor getOneObjectAt(greenfoot.Actor object, int dx, int dy, java.lang.Class cls)
static rmiextension.wrappers.RObject getRObject(java.lang.Object obj) throws bluej.extensions.ProjectNotOpenException, bluej.extensions.PackageNotFoundException, java.rmi.RemoteException, bluej.extensions.ClassNotFoundException
IMPORTANT: This code is duplicated in greenfoot.Actor!
bluej.extensions.ClassNotFoundException
java.rmi.RemoteException
bluej.extensions.PackageNotFoundException
bluej.extensions.ProjectNotOpenException
public int getWidth()
int getWidthInPixels()
public boolean isTiled()
setTiled(boolean)
void paintDebug(java.awt.Graphics g)
public void removeObject(greenfoot.Actor object)
object
- the object to removepublic void removeObjects(java.util.Collection objects)
objects
- A list of Actors to remove.public final void setBackground(greenfoot.GreenfootImage image)
image
- The image to be shownsetBackground(String)
,
setTiled(boolean)
public final void setBackground(java.lang.String filename) throws java.lang.IllegalArgumentException
filename
- The file holding the image to be shown
java.lang.IllegalArgumentException
- If the image can not be loaded.setBackground(GreenfootImage)
,
setTiled(boolean)
public void setTiled(boolean tiled)
tiled
- Whether it should tile the image or not.void startSequence()
CollisionChecker.startSequence()
int toCellCeil(int i)
int toCellFloor(int i)
void updateObjectLocation(greenfoot.Actor object, int oldX, int oldY)
void updateObjectSize(greenfoot.Actor object)