-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plane.java
121 lines (101 loc) · 2.81 KB
/
Plane.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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import java.awt.image.*;
import java.io.IOException;
import javax.sound.sampled.*;
import javax.imageio.ImageIO;
public class Plane {
private double x;
private double y;
private BufferedImage planeIcon;
private double scale;
private double width;
private double y_constant;
private boolean tookOff = false;
private boolean plane_steady = false;
private boolean case1 = true;
private boolean sound1playing = false;
Plane(double x, double y, double scale, double width) {
this.x = x;
this.y = y;
this.scale = scale;
this.width = width;
try {
planeIcon = ImageIO.read(getClass().getResource("PlaneImages/PlaneDrawing.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void movePlane() {
if (!plane_steady) {
takeOff();
} else {
steadyFlight();
}
}
private void takeOff() {
if (!sound1playing) {
playTakeOffSound();
sound1playing = true;
}
double sc = scale;
if (x < 300 && !tookOff) {
x += 9;
y = -sc * Math.pow(2, x / sc); // funksioni 1
if (x >= 0) {
y = -sc * (1 + Math.log10((x / sc) + 1)); // funksioni 2
}
} else {
tookOff = true;
{
if (x > -width / 3) {
x -= 5;
} else {
plane_steady = true;
y_constant = y;
}
}
}
}
private void steadyFlight() {
if (sound1playing) {
playConstantSound();
sound1playing = false;
}
if (y > y_constant - 50 && case1) {
y -= 1;
} else {
case1 = false;
}
if (y < y_constant + 50 && !case1) {
y += 1;
} else {
case1 = true;
}
}
public void flyAway() {
x = x + 20;
}
private void playTakeOffSound() {
try {
Sounds.playSound("Sounds/takeOffSound.wav", false);
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
}
}
private void playConstantSound() {
try {
Sounds.playSound("Sounds/planeSound1.wav", true);
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
}
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public boolean flewAway() {
return x > width;
}
public BufferedImage getPlaneIcon() {
return planeIcon;
}
}