-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBird.pde
More file actions
65 lines (61 loc) · 2.16 KB
/
Copy pathBird.pde
File metadata and controls
65 lines (61 loc) · 2.16 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
class Bird {
float w = 60;
float h = 50;
float posX;
float posY;
int flapCount = 0;
int typeOfBird;
//------------------------------------------------------------------------------------------------------------------------------------------------------
//constructor
Bird(int type) {
posX = width;
typeOfBird = type;
switch(type) {
case 0://flying low
posY = 10 + h/2;
break;
case 1://flying middle
posY = 100;
break;
case 2://flying high
posY = 180;
break;
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------
//show the birf
void show() {
flapCount++;
if (flapCount < 0) {//flap the berd
image(bird,posX-bird.width/2,height - groundHeight - (posY + bird.height-20));
} else {
image(bird1,posX-bird1.width/2,height - groundHeight - (posY + bird1.height-20));
}
if(flapCount > 15){
flapCount = -15;
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------
//move the bard
void move(float speed) {
posX -= speed;
}
//------------------------------------------------------------------------------------------------------------------------------------------------------
//returns whether or not the bird collides with the player
boolean collided(float playerX, float playerY, float playerWidth, float playerHeight) {
float playerLeft = playerX - playerWidth/2;
float playerRight = playerX + playerWidth/2;
float thisLeft = posX - w/2 ;
float thisRight = posX + w/2;
if ((playerLeft<= thisRight && playerRight >= thisLeft ) || (thisLeft <= playerRight && thisRight >= playerLeft)) {
float playerUp = playerY + playerHeight/2;
float playerDown = playerY - playerHeight/2;
float thisUp = posY + h/2;
float thisDown = posY - h/2;
if (playerDown <= thisUp && playerUp >= thisDown) {
return true;
}
}
return false;
}
}