-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathBasicZombie.java
92 lines (77 loc) · 2.51 KB
/
BasicZombie.java
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
81
82
83
84
85
86
87
88
89
90
91
92
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class BasicZombie here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class BasicZombie extends Zombie
{
/**
* Act - do whatever the BasicZombie wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public GreenfootImage[] idle;
public GreenfootImage[] walk;
public GreenfootImage[] armless;
public GreenfootImage[] eat;
public GreenfootImage[] armlesseat;
public BasicZombie() {
walk = importSprites("zombiewalk", 7);
eat = importSprites("zombieeating", 7);
armlesseat = importSprites("armlesszombieeating", 7);
armless = importSprites("armlesszombie", 7);
walkSpeed = Random.Double(11, 14);
maxHp = 100;
hp = maxHp;
}
public void update() {
if (hp > 50) {
if (!isEating()) {
animate(walk, 350, true);
move(-walkSpeed);
} else {
animate(eat, 200, true);
playEating();
}
} else {
if (!fallen) {
fallen = true;
AudioPlayer.play(80, "limbs_pop.mp3");
MyWorld.addObject(new Arm(), getX()+8, getY()+20);
}
if (!isEating()) {
animate(armless, 350, true);
move(-walkSpeed);
} else {
animate(armlesseat, 200, true);
playEating();
}
}
}
public void hit(int dmg) {
AudioPlayer.play(70, "splat.mp3", "splat2.mp3", "splat3.mp3");
if (isLiving()) {
if (!fallen) {
if (!eating) {
hitFlash(walk, "zombiewalk");
} else {
hitFlash(eat, "zombieeating");
}
} else {
if (!eating) {
hitFlash(armless, "armlesszombie");
} else {
hitFlash(armlesseat, "armlesszombieeating");
}
}
hp -= dmg;
} else if (!finalDeath) {
if (!eating) {
hitFlash(headless, "zombieheadless");
} else {
hitFlash(headlesseating, "headlesszombieeating");
}
}
}
}