-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOreBlob.java
More file actions
80 lines (69 loc) · 2.09 KB
/
OreBlob.java
File metadata and controls
80 lines (69 loc) · 2.09 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
77
78
79
80
import processing.core.PImage;
import java.util.List;
public class OreBlob
extends MobileAnimatedActor
{
private static final int QUAKE_ANIMATION_RATE = 100;
public OreBlob(String name, Point position, int rate, int animation_rate,
List<PImage> imgs)
{
super(name, position, rate, animation_rate, imgs);
}
protected boolean canPassThrough(WorldModel world, Point pt)
{
return !world.isOccupied(pt) || world.getTileOccupant(pt) instanceof Ore;
}
private boolean move(WorldModel world, WorldEntity target)
{
if (target == null)
{
return false;
}
if (adjacent(getPosition(), target.getPosition()))
{
target.remove(world);
return true;
}
else
{
Point new_pt = nextPosition(world, target.getPosition());
WorldEntity old_entity = world.getTileOccupant(new_pt);
if (old_entity != null && old_entity != this)
{
old_entity.remove(world);
}
world.moveEntity(this, new_pt);
return false;
}
}
public Action createAction(WorldModel world, ImageStore imageStore)
{
Action[] action = { null };
action[0] = ticks -> {
removePendingAction(action[0]);
WorldEntity target = world.findNearest(getPosition(), Vein.class);
long nextTime = ticks + getRate();
if (target != null)
{
Point tPt = target.getPosition();
if (move(world, target))
{
Quake quake = createQuake(world, tPt, ticks, imageStore);
world.addEntity(quake);
nextTime = nextTime + getRate();
}
}
scheduleAction(world, this, createAction(world, imageStore),
nextTime);
};
return action[0];
}
private Quake createQuake(WorldModel world, Point pt, long ticks,
ImageStore imageStore)
{
Quake quake = new Quake("quake", pt, QUAKE_ANIMATION_RATE,
imageStore.get("quake"));
quake.schedule(world, ticks, imageStore);
return quake;
}
}