import greenfoot.*;
| A variation of an actor that maintains a precise location (using doubles for the co-ordinates
| instead of ints). This allows small precise movements (e.g. movements of 1 pixel or less)
| that do not lose precision.
|
| @author Poul Henriksen
| @author Michael Kolling
| @author Neil Brown
|
| @version 3.0
|
public abstract class SmoothMover
extends Actor
{
private double exactX;
private double exactY;
| Move forward by the specified distance.
| (Overrides the method in Actor).
|
@Override
public void move(int distance)
{
move((double)distance);
}
| Move forward by the specified exact distance.
|
public void move(double distance)
{
double radians = Math.toRadians(getRotation());
double dx = Math.cos(radians) * distance;
double dy = Math.sin(radians) * distance;
setLocation(exactX + dx, exactY + dy);
}
| Set the location using exact coordinates.
|
public void setLocation(double x, double y)
{
exactX = x;
exactY = y;
super.setLocation((int) (x + 0.5), (int) (y + 0.5));
}
| Set the location using integer coordinates.
| (Overrides the method in Actor.)
|
@Override
public void setLocation(int x, int y)
{
exactX = x;
exactY = y;
super.setLocation(x, y);
}
| Return the exact x-coordinate (as a double).
|
public double getExactX()
{
return exactX;
}
| Return the exact y-coordinate (as a double).
|
public double getExactY()
{
return exactY;
}
}
top,
use,
map,
abstract class SmoothMover
. move
. move
. setLocation
. setLocation
. getExactX
. getExactY
48 neLoCode
+ 15 LoComm