-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZombie.pde
75 lines (57 loc) · 1.59 KB
/
Zombie.pde
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
public class Zombie extends Spark {
int brains;
Zombie lastswap;
public Zombie(int pos, int life, Zombie zombifier) {
super(pos,life,zombifier,null);
brains = (int)World.zombieBrains;
}
public boolean act() {
if (brains-- < 0) dlife(-1);
if (this.isDead) return true;
return super.act();
}
public boolean canMate() {
return false;
}
public boolean canEat(Spark victim, boolean trapped) {
return life >= victim.life && !(victim instanceof Zombie) && !(victim instanceof Dragon);
}
public boolean eat(Spark victim) {
int oldpos = victim.pos;
dlife((int)(victim.life/World.zombifyDivisor));
World.kill(victim);
Zombie zombie = new Zombie(oldpos,(int)(life/World.zombifiedDivisor),this);
World.add(zombie);
brains = (int)World.zombieBrains;
return true;
}
public boolean canMove(int delta) {
Spark c = World.get(pos+delta);
return (c == null || (c instanceof Zombie && c != lastswap));
}
public boolean move(int delta) {
Spark c = World.get(pos+delta);
if (c == null) {
int newpos = World.move(this,delta);
if (newpos >= 0) {
pos = newpos;
return true;
}
return false;
}
else {
lastswap = c;
World.swap(this.pos, c.pos);
int tmp = this.pos;
this.pos = c.pos;
c.pos = tmp;
return true;
}
}
public void draw() {
int x = pos / Config.HEIGHT;
int y = pos % Config.HEIGHT;
draw.stroke(life,(int)(life/255.0*178),(int)(life/255.0*63));
draw.point(x,y);
}
}