-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBabyPig.java
More file actions
43 lines (31 loc) · 1.84 KB
/
BabyPig.java
File metadata and controls
43 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
import processing.core.PImage;
import java.util.List;
public class BabyPig extends Pig {
private static final double BABY_PIG_ACTION_ANIMATION_PERIOD = 1.000; // have to be in sync since grows and gains health at same time
private static final int BABY_PIG_HEALTH_LIMIT = 5;
public BabyPig(String id, Point position, List<PImage> images, double animationPeriod, double actionPeriod, int health, int healthLimit) {
super(id, position, images, BABY_PIG_ACTION_ANIMATION_PERIOD, BABY_PIG_ACTION_ANIMATION_PERIOD, 0, BABY_PIG_HEALTH_LIMIT);
}
public boolean transform(WorldModel world, EventScheduler scheduler, ImageStore imageStore) {
if (this.getHealth() <= 0) {
Bacon bacon = Factory.createBacon(WorldLoader.BACON_KEY + "_" + this.getId(), this.getPosition(), imageStore.getImageList(WorldLoader.BACON_KEY));
world.removeEntity(scheduler, this);
world.tryAddEntity(bacon);
}else if (this.getHealth() >= (this).getHealthLimit()) {
GrownPig grownPig = Factory.createGrownPigWithDefaults(WorldLoader.GROWN_PIG_KEY + "_" + this.getId(), this.getPosition(), imageStore.getImageList(WorldLoader.GROWN_PIG_KEY));
world.removeEntity(scheduler, this);
world.tryAddEntity(grownPig);
grownPig.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());
}
}