Class ThreadActor

java.lang.Object
  extended by greenfoot.Actor
      extended by ThreadActor
All Implemented Interfaces:
java.lang.Runnable

public abstract class ThreadActor
extends greenfoot.Actor
implements java.lang.Runnable

class of Threadfoot

Counterpart of Greenfoot-class Actor. Working with Threadfoot you should use always this class instead of class Actor.

Remark 1: If you override the method "addedToWorld" in a derived class you have to call the ThreadActor-method "addedToWorld" within that method!

Version:
(2.0) 2010/12/08
Author:
Dietrich Boles (Uni Oldenburg, Germany)

Constructor Summary
ThreadActor()
          Creates a ThreadActor-Object with an internal Thread-Object
 
Method Summary
 void act()
          meaningless in Threadfoot
protected  void addedToWorld(greenfoot.World world)
          This method is called by the Greenfoot system when the object has been inserted into the world.
 greenfoot.GreenfootImage getImage()
          Returns the image used to represent this Actor.
protected  java.util.List getIntersectingObjects(java.lang.Class cls)
          Return all the objects that intersect this object.
protected  java.util.List getNeighbours(int distance, boolean diagonal, java.lang.Class cls)
          Return the neighbours to this object within a given distance.
protected  java.util.List getObjectsAtOffset(int dx, int dy, java.lang.Class cls)
          Return all objects that intersect the given location (relative to this object's location).
protected  java.util.List getObjectsInRange(int radius, java.lang.Class cls)
          Return all objects within range 'radius' around this object.
protected  greenfoot.Actor getOneIntersectingObject(java.lang.Class cls)
          Return an object that intersects this object.
protected  greenfoot.Actor getOneObjectAtOffset(int dx, int dy, java.lang.Class cls)
          Return one object that is located at the specified cell (relative to this objects location).
 int getRotation()
          Return the current rotation of the object.
 java.lang.Thread getThread()
          Return the internal Thread-Object
 greenfoot.World getWorld()
          Return the world that this object lives in.
 int getX()
          Return the x-coordinate of the object's current location.
 int getY()
          Return the y-coordinate of the object's current location.
protected  boolean intersects(greenfoot.Actor other)
          Check whether this object intersects with another given object.
 void run()
          This method does nothing.
 void setImage(greenfoot.GreenfootImage image)
          Set the image for this object to the specified image.
 void setImage(java.lang.String filename)
          Set an image for this object from an image file.
 void setLocation(int x, int y)
          Assign a new location for this object.
 void setRotation(int rotation)
          Set the rotation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadActor

public ThreadActor()
Creates a ThreadActor-Object with an internal Thread-Object

Method Detail

act

public final void act()
meaningless in Threadfoot

Overrides:
act in class greenfoot.Actor
See Also:
Actor.act()

addedToWorld

protected void addedToWorld(greenfoot.World world)
This method is called by the Greenfoot system when the object has been inserted into the world. This method can be overridden to implement custom behaviour when the actor is inserted into the world.

If you override this method in a derived class you have to call this method within that method!

Overrides:
addedToWorld in class greenfoot.Actor
Parameters:
world - The world the object was added to.

getImage

public greenfoot.GreenfootImage getImage()
Returns the image used to represent this Actor. This image can be modified to change the object's appearance.

Overrides:
getImage in class greenfoot.Actor
Returns:
The object's image.

getIntersectingObjects

protected java.util.List getIntersectingObjects(java.lang.Class cls)
Return all the objects that intersect this object. This takes the graphical extent of objects into consideration.
NOTE: Does not take rotation into consideration.

Overrides:
getIntersectingObjects in class greenfoot.Actor
Parameters:
cls - Class of objects to look for (passing 'null' will find all objects).

getNeighbours

protected java.util.List getNeighbours(int distance,
                                       boolean diagonal,
                                       java.lang.Class cls)
Return the neighbours to this object within a given distance. This method considers only logical location, ignoring extent of the image. Thus, it is most useful in scenarios where objects are contained in a single cell.

All cells that can be reached in the number of steps given in 'distance' from this object are considered. Steps may be only in the four main directions, or may include diagonal steps, depending on the 'diagonal' parameter. Thus, a distance/diagonal specification of (1,false) will inspect four cells, (1,true) will inspect eight cells.

Overrides:
getNeighbours in class greenfoot.Actor
Parameters:
distance - Distance (in cells) in which to look for other objects.
diagonal - If true, include diagonal steps.
cls - Class of objects to look for (passing 'null' will find all objects).
Returns:
A list of all neighbours found.

getObjectsAtOffset

protected java.util.List getObjectsAtOffset(int dx,
                                            int dy,
                                            java.lang.Class cls)
Return all objects that intersect the given location (relative to this object's location).

Overrides:
getObjectsAtOffset in class greenfoot.Actor
Parameters:
dx - X-coordinate relative to this objects location.
dy - y-coordinate relative to this objects location.
cls - Class of objects to look for (passing 'null' will find all objects).
Returns:
List of objects at the given offset. The list will include this object, if the offset is zero.

getObjectsInRange

protected java.util.List getObjectsInRange(int radius,
                                           java.lang.Class cls)
Return all objects within range 'radius' around this object. An object is within range if the distance between its centre and this object's centre is less than or equal to 'radius'.

Overrides:
getObjectsInRange in class greenfoot.Actor
Parameters:
radius - Radius of the circle (in cells)
cls - Class of objects to look for (passing 'null' will find all objects).

getOneIntersectingObject

protected greenfoot.Actor getOneIntersectingObject(java.lang.Class cls)
Return an object that intersects this object. This takes the graphical extent of objects into consideration.
NOTE: Does not take rotation into consideration.

Overrides:
getOneIntersectingObject in class greenfoot.Actor
Parameters:
cls - Class of objects to look for (passing 'null' will find all objects).

getOneObjectAtOffset

protected greenfoot.Actor getOneObjectAtOffset(int dx,
                                               int dy,
                                               java.lang.Class cls)
Return one object that is located at the specified cell (relative to this objects location). Objects found can be restricted to a specific class (and its subclasses) by supplying the 'cls' parameter. If more than one object of the specified class resides at that location, one of them will be chosen and returned.

Overrides:
getOneObjectAtOffset in class greenfoot.Actor
Parameters:
dx - X-coordinate relative to this objects location.
dy - y-coordinate relative to this objects location.
cls - Class of objects to look for (passing 'null' will find all objects).
Returns:
An object at the given location, or null if none found.

getRotation

public int getRotation()
Return the current rotation of the object. Rotation is expressed as a degree value, range (0..359). Zero degrees is to the east. The angle increases clockwise.

Overrides:
getRotation in class greenfoot.Actor
Returns:
The rotation in degrees.
See Also:
setRotation(int)

getThread

public java.lang.Thread getThread()
Return the internal Thread-Object

Returns:
the internal Thread-Object

getWorld

public greenfoot.World getWorld()
Return the world that this object lives in.

Overrides:
getWorld in class greenfoot.Actor
Returns:
The world.

getX

public int getX()
         throws java.lang.IllegalStateException
Return the x-coordinate of the object's current location. The value returned is the horizontal index of the object's cell in the world.

Overrides:
getX in class greenfoot.Actor
Returns:
The x-coordinate of the object's current location.
Throws:
java.lang.IllegalStateException - If the actor has not been added into a world.

getY

public int getY()
Return the y-coordinate of the object's current location. The value returned is the vertical index of the object's cell in the world.

Overrides:
getY in class greenfoot.Actor
Returns:
The y-coordinate of the object's current location
Throws:
java.lang.IllegalStateException - If the actor has not been added into a world.

intersects

protected boolean intersects(greenfoot.Actor other)
Check whether this object intersects with another given object. NOTE: When rotated, it only uses the axis alligned bounds of the rotated image.

Overrides:
intersects in class greenfoot.Actor
Returns:
True if the object's intersect, false otherwise.

run

public void run()
This method does nothing. It should be overridden in subclasses to implement an thread's action.

Specified by:
run in interface java.lang.Runnable

setImage

public void setImage(greenfoot.GreenfootImage image)
Set the image for this object to the specified image.

Overrides:
setImage in class greenfoot.Actor
Parameters:
image - The image.
See Also:
setImage(String)

setImage

public void setImage(java.lang.String filename)
              throws java.lang.IllegalArgumentException
Set an image for this object from an image file. The file may be in jpeg, gif or png format. The file should be located in the project directory.

Overrides:
setImage in class greenfoot.Actor
Parameters:
filename - The name of the image file.
Throws:
java.lang.IllegalArgumentException - If the image can not be loaded.

setLocation

public void setLocation(int x,
                        int y)
Assign a new location for this object. The location is specified as a cell index in the world. If this method is overridden it is important to call this method with super.setLocation(x,y) from the overriding method.

Overrides:
setLocation in class greenfoot.Actor
Parameters:
x - Location index on the x-axis
y - Location index on the y-axis
Throws:
java.lang.IllegalStateException - If the actor has not been added into a world.

setRotation

public void setRotation(int rotation)
Set the rotation of the object. Rotation is expressed as a degree value, range (0..359). Zero degrees is to the east. The angle increases clockwise.

Overrides:
setRotation in class greenfoot.Actor
Parameters:
rotation - The rotation in degrees.