-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiner.java
More file actions
76 lines (64 loc) · 1.85 KB
/
Miner.java
File metadata and controls
76 lines (64 loc) · 1.85 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
64
65
66
67
68
69
70
71
72
73
74
75
76
import processing.core.PImage;
import java.util.List;
public abstract class Miner
extends MobileAnimatedActor
{
private int resource_limit;
private int resource_count;
private Class<?> seeking;
public Miner(String name, Point position, int rate, int animation_rate,
int resource_limit, int resource_count, Class<?> seeking,
List<PImage> imgs)
{
super(name, position, rate, animation_rate, imgs);
this.resource_limit = resource_limit;
this.resource_count = resource_count;
this.seeking = seeking;
}
public void setResourceCount(int count)
{
this.resource_count = count;
}
public int getResourceCount()
{
return this.resource_count;
}
public int getResourceLimit()
{
return this.resource_limit;
}
protected boolean canPassThrough(WorldModel world, Point pt)
{
return !world.isOccupied(pt);
}
protected abstract Miner transform(WorldModel world);
protected abstract boolean move(WorldModel world, WorldEntity ore);
public Action createAction(WorldModel world, ImageStore imageStore)
{
Action[] action = { null };
action[0] = ticks -> {
removePendingAction(action[0]);
WorldEntity target = world.findNearest(getPosition(), seeking);
Actor newEntity = this;
if (move(world, target))
{
newEntity = tryTransform(world);
}
scheduleAction(world, newEntity,
newEntity.createAction(world, imageStore),
ticks + newEntity.getRate());
};
return action[0];
}
private Miner tryTransform(WorldModel world)
{
Miner newEntity = transform(world);
if (this != newEntity)
{
this.remove(world);
world.addEntity(newEntity);
newEntity.scheduleAnimation(world);
}
return newEntity;
}
}