Class SmoothMover

java.lang.Object
  extended by greenfoot.Actor
      extended by SmoothMover

public abstract class SmoothMover
extends greenfoot.Actor

A variation of an actor that maintains precise location (using doubles for the co-ordinates instead of ints). It also maintains a current movement in form of a movement vector.

Version:
2.1
Author:
Poul Henriksen, Michael Kolling

Constructor Summary
SmoothMover()
           
SmoothMover(Vector movement)
          Create new thing initialised with given speed.
 
Method Summary
 void accelerate(double factor)
          Accelerate the speed of this mover by the given factor.
 void addForce(Vector force)
          Modify the current movement by adding a new vector to the existing movement.
 double getExactX()
          Return the exact x co-ordinate (as a double).
 double getExactY()
          Return the exact y co-ordinate (as a double).
 Vector getMovement()
          Return the current movement of this object (as a vector).
 double getSpeed()
          Return the speed of this actor.
 void move()
          Move in the current movement direction.
 void setLocation(double x, double y)
          Set the location using exact (double) co-ordinates.
 void setLocation(int x, int y)
          Set location.
 
Methods inherited from class greenfoot.Actor
act, addedToWorld, getHeight, getImage, getIntersectingObjects, getNeighbours, getObjectsAtOffset, getObjectsInRange, getOneIntersectingObject, getOneObjectAtOffset, getRotation, getWidth, getWorld, getX, getY, intersects, setImage, setImage, setRotation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SmoothMover

public SmoothMover()

SmoothMover

public SmoothMover(Vector movement)
Create new thing initialised with given speed.

Method Detail

accelerate

public void accelerate(double factor)
Accelerate the speed of this mover by the given factor. (Factors less than 1 will decelerate.) The direction remains unchanged.


addForce

public void addForce(Vector force)
Modify the current movement by adding a new vector to the existing movement.


getExactX

public double getExactX()
Return the exact x co-ordinate (as a double).


getExactY

public double getExactY()
Return the exact y co-ordinate (as a double).


getMovement

public Vector getMovement()
Return the current movement of this object (as a vector).


getSpeed

public double getSpeed()
Return the speed of this actor.


move

public void move()
Move in the current movement direction.


setLocation

public void setLocation(double x,
                        double y)
Set the location using exact (double) co-ordinates.


setLocation

public void setLocation(int x,
                        int y)
Set location. Redefinition of the standard Greenfoot method to make sure the exact co-ordinates are updated in sync.

Overrides:
setLocation in class greenfoot.Actor
Parameters:
x - Location index on the x-axis
y - Location index on the y-axis