-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCloud.java
More file actions
72 lines (68 loc) · 2.19 KB
/
Copy pathCloud.java
File metadata and controls
72 lines (68 loc) · 2.19 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
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;
public class Cloud {
protected Rectangle cloudRect;
protected BufferedImage cloudImage;
protected int cloudX;
protected int cloudY;
protected int cloudScore;
public Cloud(){
try {
cloudImage = ImageIO.read(Window.class.getResource("./assets/images/cloud.png"));
} catch (IOException e) {
e.printStackTrace();
}
cloudScore = 0;
cloudRect = new Rectangle(90,40);
Random cloudRN = new Random();
cloudX = cloudRN.nextInt(1080-500)+500;
cloudY = cloudRN.nextInt(200);
cloudRect.x=cloudX;
cloudRect.y=cloudY;
}
public void cloudScoreUpdate(boolean avatarBonus){
cloudScore+=50;
}
public void cloudUpdate(Cloud cloud, Avatar avatar, int gameState){
//moves the cloud offscreen if isHit returns true; else just move backwards
if((cloud.getCloudBounds().intersects(avatar.avatarBound()))) {
avatar.setHit(true);
cloudScoreUpdate(true);
Random rn = new Random();
int placement = rn.nextInt(500);
cloudX=3000 + placement;
}
if (gameState == 1 && cloudX >= -40) {
//move cloud if in playing mode
cloudX -= 20;
}
else {
Random rnX = new Random();
int xCloudPlacement = rnX.nextInt(500);
cloudX = 1920 + xCloudPlacement;
Random rnY = new Random();
cloudY = rnY.nextInt(200);
try {
cloudImage = ImageIO.read(Window.class.getResource("./assets/images/cloud.png"));
cloudRect.width = 90;
cloudRect.height = 40;
} catch (IOException e) {
e.printStackTrace();
}
}
cloudRect.x=cloudX;
cloudRect.y=cloudY;
}
public Rectangle getCloudBounds(){
return cloudRect;
}
public int getCloudScore(){
return cloudScore;
}
public void drawCloud(Graphics g){
g.drawImage(cloudImage, cloudX, cloudY, null);
}
}