-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathActorThatDoesntSuck.java
executable file
·35 lines (32 loc) · 1.15 KB
/
ActorThatDoesntSuck.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import greenfoot.*;
/**
* A subclass of Actor that has setX and setY, because Greenfoot left them out
* for no good reason.
*
* @author Will Franzen
* @version 1.0.0
*/
public class ActorThatDoesntSuck extends Actor
{
// Set the actor's X coordinate
public void setX(int x) {
int rot = getRotation(); // Get initial rotation
int deltaX = x- getX(); // Find distance from target
setRotation(0); // Turn towards target
move(deltaX); // Move correct distance
setRotation(rot); // Reset rotation
}
// Set the actor's Y coordinate
public void setY(int y) {
int rot = getRotation(); // Get initial rotation
int deltaY = y - getY(); // Find distance from target
setRotation(90); // Turn towards target
move(deltaY); // Move correct distance
setRotation(rot); // Reset rotation
}
// Set the actor's X and Y coordinates to that of a Point
public void moveTo(Point point) {
setX(point.getX()); // Set X coordinate
setY(point.getY()); // Set Y coordinate
}
}