-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathProjectile.java
75 lines (63 loc) · 2.13 KB
/
Projectile.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 Pea here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Projectile extends animatedObject {
public int speed = 4;
public GreenfootImage[] image;
public boolean hit = false;
public MyWorld MyWorld;
public boolean foundTarget = false;
public Zombie hitZombie;
public int frameCount;
public int yPos;
public int damage;
/**
* Act - do whatever the Pea wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public Projectile(String name, int frameCount, int yPos, int dmg, int speed) {
this.frameCount = frameCount;
this.image = importSprites(name, frameCount);
this.yPos = yPos;
this.damage = dmg;
this.speed = speed;
setImage(image[0]);
}
public void act()
{
if (getWorld() != null) {
MyWorld = (MyWorld)getWorld();
if (frame >= frameCount) {
MyWorld.removeObject(this);
return;
}
if (!hit) {
move(speed);
} else {
animate(image, 150, false);
}
if (isAtEdge()) {
MyWorld.removeObject(this);
return;
}
for (Zombie i : MyWorld.level.zombieRow.get(yPos)) {
if (Math.abs(i.getX() - getX()) < 30) {
if (!foundTarget) {
hitZombie = i;
foundTarget = true;
}
if (!hit) {
hitZombie.hit(damage);
hit = true;
} else if (hitZombie.getWorld() != null && getX() < hitZombie.getX()) {
move(speed);
}
}
}
}
}
}