-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStorm.java
More file actions
executable file
·55 lines (44 loc) · 1.34 KB
/
Storm.java
File metadata and controls
executable file
·55 lines (44 loc) · 1.34 KB
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import greenfoot.GreenfootSound;
/**
* Storm class
*
* @author Jimmy, Adrian, Daniel
* @version April 24, 2024
*/
public class Storm extends Event {
private GreenfootSound storm = new GreenfootSound("storm.wav");
private int actsLeft;
private int direction;
private double speed;
private GreenfootImage image;
private MainWorld mw;
Label stormText = new Label("", 45);
/** Constructor for Storm */
public Storm() {
changeIndex(-1, -1, -2);
image = Utility.drawStorm(2560, 1440, 100);
setImage(image);
actsLeft = 600;
speed = 0.55;
}
/**
* Act - do whatever the Storm wants to do. This method is called whenever the 'Act' or 'Run'
* button gets pressed in the environment.
*/
public void act() {
actsLeft--;
setLocation((double) (getX() - speed), (double) (getY() + speed));
if (actsLeft == 0) {
storm.stop();
getWorld().removeObject(this.stormText);
getWorld().removeObject(this);
}
}
/** Adds label to the left side of the screen when an instance of Storm is added to the world */
public void addedToWorld(World MainWorld) {
storm.play();
stormText.setValue("A Storm approaches..." + "\nSI -1" + "\nEPR -1" + "\nCWI -2");
MainWorld.addObject(stormText, 230, 360);
}
}