-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVirus.java
executable file
·49 lines (39 loc) · 1.16 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
46
47
48
49
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Virus class
*
* @author Jimmy, Adrian, Daniel
* @version April 24, 2024
*/
public class Virus extends Event {
private GreenfootSound virusSound = new GreenfootSound("virus.wav");
private MainWorld mw;
private GreenfootImage virus;
private int actsLeft;
Label virusText = new Label("", 45);
/** Constructor for Virus class */
public Virus() {
changeIndex(0, -2, -3);
virus = new GreenfootImage(1280, 720);
virus.setColor(Color.GREEN);
virus.fillRect(0, 0, 1280, 720);
virus.setTransparency(100);
setImage(virus);
actsLeft = 400;
}
public void act() {
// Add your action code here.
actsLeft--;
if (actsLeft == 0) {
virusSound.stop();
getWorld().removeObject(this.virusText);
getWorld().removeObject(this);
}
}
/** Adds label to the left side of the screen when an instance of Virus is added to the world */
public void addedToWorld(World MainWorld) {
virusSound.play();
virusText.setValue("A Virus approaches..." + "\nEPR -2" + "\nCWI -3");
MainWorld.addObject(virusText, 230, 360);
}
}