-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBirdie.java
32 lines (29 loc) · 870 Bytes
/
Birdie.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
import javax.swing.*;
import java.awt.*;
public class Birdie extends Thread {
JPanel bird;
JPanel desk;
Window window;
public Birdie(JPanel bird, JPanel desk, Window window) {
this.bird = bird;
this.desk = desk;
this.window = window;
}
public void run() {
while (!window.gameOver) {
try {
Thread.sleep(45);
} catch (InterruptedException e) {
e.printStackTrace();
}
Rectangle bounds = bird.getBounds();
int Y = bounds.y + 10;
if ((Y >= 0 && Y <= desk.getHeight() - bounds.height)) {
bird.setBounds(bounds.x, Y, bounds.width, bounds.height);
desk.repaint();
} else {
window.endGame();
}
}
}
}