-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDudeFull.java
More file actions
48 lines (38 loc) · 1.79 KB
/
Copy pathDudeFull.java
File metadata and controls
48 lines (38 loc) · 1.79 KB
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
import processing.core.PImage;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class DudeFull extends Dude implements Transform, Move {
protected DudeFull(String id, Point position, List<PImage> images, double animationPeriod, double actionPeriod, int resourceLimit) {
super(id, position, images, animationPeriod, actionPeriod, resourceLimit);
}
public void executeActivity(WorldModel world, ImageStore imageStore, EventScheduler scheduler) {
Optional<Entity> fullTarget = findNearest(world, this.position,
new ArrayList<>(List.of("House")));
if (fullTarget.isPresent() && this.moveTo(world, fullTarget.get(), scheduler)) {
transform(world, scheduler, imageStore);
} else {
Activity activity = new Activity(this, world, imageStore);
scheduler.scheduleEvent(this, activity, this.actionPeriod);
}
}
public boolean transform(WorldModel world, EventScheduler scheduler, ImageStore imageStore) {
Dude dude = new DudeNotFull(this.id, this.position, ImageStore.getImageList(imageStore, "dude"), .18, .787,
this.resourceLimit);
world.removeEntity(scheduler, this);
world.addEntity(dude);
dude.scheduleActions(scheduler, world, imageStore);
return true;
}
public boolean moveTo(WorldModel world, Entity target, EventScheduler scheduler) {
if (this.position.adjacent(target.position)) {
return true;
} else {
Point nextPos = nextPosition(world, target.position);
if (!this.position.equals(nextPos)) {
world.moveEntity(scheduler, this, nextPos);
}
return false;
}
}
}