/
Virus.java
45 lines (43 loc) · 1.02 KB
/
Virus.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Virus
*
* @author Florian Nitschmann
* @version 1.0
*/
public class Virus extends BattleArea
{
GreenfootImage virus;
//initialize variables for speed and counter (Score.class)
int speed;
Score counter;
//constructor Virus
public Virus(Score score) {
counter = score;
virus = getImage();
virus.mirrorHorizontally();
int level = counter.level;
speed = level+2;
}
//method move (checks where virus is and starts actions)
private void move () {
if (atEdge()) {
remove(this);
counter.update(-1);
}
else if (isCollided(Healer.class)) {
counter.update(1);
Actor Healer = getOneIntersectingObject(Healer.class);
remove(Healer);
remove(this);
}
else {
moveLeft(speed);
}
}
//method act
public void act()
{
move();
}
}