-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBabyCow.java
More file actions
44 lines (31 loc) · 1.84 KB
/
BabyCow.java
File metadata and controls
44 lines (31 loc) · 1.84 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
import processing.core.PImage;
import java.util.List;
public class BabyCow extends Cow {
private static final double BABYCOW_ACTION_ANIMATION_PERIOD = 1.000; // have to be in sync since grows and gains health at same time
private static final int BABYCOW_HEALTH_LIMIT = 5;
public BabyCow(String id, Point position, List<PImage> images, double animationPeriod, double actionPeriod, int health, int healthLimit) {
super(id, position, images, BABYCOW_ACTION_ANIMATION_PERIOD, BABYCOW_ACTION_ANIMATION_PERIOD, 0, BABYCOW_HEALTH_LIMIT);
}
public boolean transform(WorldModel world, EventScheduler scheduler, ImageStore imageStore) {
if (this.getHealth() <= 0) {
Steak steak = Factory.createSteak(WorldLoader.STEAK_KEY + "_" + this.getId(), this.getPosition(), imageStore.getImageList(WorldLoader.STEAK_KEY));
world.removeEntity(scheduler, this);
world.tryAddEntity(steak);
} else if (this.getHealth() >= (this).getHealthLimit()) {
GrownCow grownCow = Factory.createGrownCowWithDefaults(WorldLoader.GROWN_COW_KEY + "_" + this.getId(), this.getPosition(), imageStore.getImageList(WorldLoader.GROWN_COW_KEY));
world.removeEntity(scheduler, this);
world.tryAddEntity(grownCow);
grownCow.scheduleActions(scheduler, world, imageStore);
return true;
}
return false;
}
@Override
public void executeActivity(WorldModel world, ImageStore imageStore, EventScheduler scheduler) {
super.setHealth(super.getHealth() + 1);
super.executeActivity(world, imageStore, scheduler);
}
public void scheduleActions(EventScheduler scheduler, WorldModel world, ImageStore imageStore) {
scheduler.scheduleEvent(this, Factory.createActivityAction(this, world, imageStore), getActionPeriod());
}
}