-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActor.java
More file actions
63 lines (53 loc) · 1.37 KB
/
Actor.java
File metadata and controls
63 lines (53 loc) · 1.37 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import processing.core.PImage;
import java.util.List;
import java.util.LinkedList;
public abstract class Actor
extends WorldEntity
{
private int rate;
private List<Action> pendingActions;
public Actor(String name, Point position, int rate, List<PImage> imgs)
{
super(name, position, imgs);
this.rate = rate;
this.pendingActions = new LinkedList<>();
}
public int getRate()
{
return this.rate;
}
protected void removePendingAction(Action action)
{
pendingActions.remove(action);
}
protected void addPendingAction(Action action)
{
pendingActions.add(action);
}
protected void clearPendingActions()
{
pendingActions.clear();
}
public void remove(WorldModel world)
{
for (Action action : pendingActions)
{
world.unscheduleAction(action);
}
clearPendingActions();
super.remove(world);
}
protected static void scheduleAction(WorldModel world, Actor entity,
Action action, long time)
{
entity.addPendingAction(action);
world.scheduleAction(action, time);
}
public void schedule(WorldModel world, long time, ImageStore imageStore)
{
scheduleAction(world, this, createAction(world, imageStore),
time + getRate());
}
protected abstract Action createAction(WorldModel world,
ImageStore imageStore);
}