-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPotatoMine.java
75 lines (62 loc) · 2.11 KB
/
PotatoMine.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class PotatoMine here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class PotatoMine extends Plant
{
private GreenfootImage[] idle;
private GreenfootImage[] arm;
private boolean playOnce = false;
public boolean armed = false;
private long lastFrame2 = System.nanoTime();
private boolean playSFX = false;
private long deltaTime2 = System.nanoTime();
public PotatoMine() {
idle = importSprites("potato", 5);
arm = importSprites("potatomine", 3);
maxHp = 60;
hp = maxHp;
currentFrame = System.nanoTime();
lastFrame2 = System.nanoTime();
}
public void update() {
currentFrame = System.nanoTime();
deltaTime2 = (currentFrame - lastFrame2) / 1000000;
if (deltaTime2 > 22000L) {
armed = true;
if (!playOnce) {
if (!playSFX) {
playSFX = true;
AudioPlayer.play(70, "dirt_rise.mp3");
}
animate(arm, 200, false);
if (frame > 2) {
playOnce = true;
}
} else {
animate(idle, 200, true);
}
checkExplosion();
}
}
public void hit(int dmg) {
if (isLiving() && !armed) {
hp = hp-dmg;
}
}
public void checkExplosion() {
if (MyWorld.level.zombieRow.get(getYPos()).size() == 0) {
} else {
for (Zombie i : MyWorld.level.zombieRow.get(getYPos())) {
if (Math.abs(i.getX() - getX()) < 28) {
getWorld().addObject(new Explosion(MyWorld.level.zombieRow.get(getYPos())), getX(), getY()-25);
((MyWorld)getWorld()).board.removePlant(getXPos(), getYPos());
return;
}
}
}
}
}