-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBetterObjectMovement.java
55 lines (41 loc) · 1.18 KB
/
BetterObjectMovement.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package grah8384;
import spacesettlers.objects.AbstractObject;
import spacesettlers.simulator.Toroidal2DPhysics;
import spacesettlers.utilities.Position;
public class BetterObjectMovement extends BetterMovement {
AbstractObject goalObject;
Position originalLocation;
public BetterObjectMovement(Toroidal2DPhysics space,
Position currentLocation, AbstractObject goalObject) {
super(space, currentLocation, goalObject.getPosition());
this.goalObject = goalObject;
this.originalLocation = goalObject.getPosition().deepCopy();
}
/**
* Return the goal object (and remember it is a clone so use its UUID!)
* @return
*/
public AbstractObject getGoalObject() {
return goalObject;
}
/**
* Returns true if the movement finished or the goal object died or moved
*
*/
public boolean isMovementFinished(Toroidal2DPhysics space) {
if (super.isMovementFinished(space)) {
return true;
}
AbstractObject newGoalObj = space.getObjectById(goalObject.getId());
if (newGoalObj == null) {
return true;
}
if (!newGoalObj.isAlive()) {
return true;
}
if (!newGoalObj.getPosition().equals(originalLocation)) {
return true;
}
return false;
}
}