-
Notifications
You must be signed in to change notification settings - Fork 88
/
Bird.java
66 lines (52 loc) · 1.23 KB
/
Bird.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
import java.awt.Image;
import java.awt.event.KeyEvent;
public class Bird {
public int x;
public int y;
public int width;
public int height;
public boolean collision;
// y velocity
public double yvel;
public double gravity;
// delay between key presses
private int jumpDelay;
private Image image;
private Keyboard keyboard;
public Bird () {
x = 100;
y = 200;
yvel = 0;
width = 40;
height = 40;
gravity = 0.6;
jumpDelay = 0;
collision = false;
keyboard = Keyboard.getInstance();
}
private void checkCollision(){
//System.out.println(y);
if(y > 380){
collision = true;
}
}
public void update () {
yvel += gravity;
if (jumpDelay > 0)
jumpDelay--;
if (keyboard.isDown(KeyEvent.VK_SPACE) && jumpDelay <= 0) {
yvel = -10;
jumpDelay = 10;
}
checkCollision();
if(!collision){
y += (int)yvel;
}
}
public Image getImage () {
if (image == null) {
image = Util.loadImage("lib/bird.png");
}
return image;
}
}