-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClouds.java
More file actions
75 lines (61 loc) · 2.08 KB
/
Clouds.java
File metadata and controls
75 lines (61 loc) · 2.08 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.util.Random;
public class Clouds {
private Cloud[] clouds;
private double frame_width;
private double frame_height;
private int[] cloudMovement = { 10, 15, 20 };
Clouds(double frame_width, double frame_height) {
this.frame_width = frame_width;
this.frame_height = frame_height;
clouds = new Cloud[3];
clouds[0] = new Cloud(frame_width, -frame_height / 2, "Clouds/Cloud0.png");
clouds[1] = new Cloud(frame_width, 0, "Clouds/Cloud1.png");
clouds[2] = new Cloud(frame_width, frame_height / 3, "Clouds/Cloud2.png");
}
public void moveAll() {
for (int i = 0; i < clouds.length; i++) {
clouds[i].move(cloudMovement[i]);
// Reseto rete
if (clouds[i].getX() < -frame_width) {
clouds[i].resetX(frame_width / 2);
clouds[i].resetY(getRandomSign() * Math.random() * frame_height / 3);
clouds[i].resetScale(getRandomScale());
}
}
}
//Largo rete nga frame
public void noMoreClouds() {
for (int i = 0; i < clouds.length; i++) {
clouds[i].move(cloudMovement[i]);
// reset
if (clouds[i].getX() < -frame_width-100) {
clouds[i].resetX(frame_width / 2);
clouds[i].resetY(frame_height);
clouds[i].resetScale(getRandomScale());
}
}
}
public double getRandomScale() {
return getRandomNumberUsingNextInt(0, 3) / 10.0;
}
public int getRandomNumberUsingNextInt(int min, int max) {
Random random = new Random();
return random.nextInt(max - min) + min;
}
public void moveCloud(int i) {
clouds[i].move(10);
}
public Cloud[] getClouds() {
return clouds;
}
public Cloud getCloud(int i) {
return clouds[i];
}
private int getRandomSign() {
if (Math.random() > 0.5) {
return 1;
} else {
return -1;
}
}
}