-
Notifications
You must be signed in to change notification settings - Fork 0
/
bird.pde
48 lines (39 loc) · 983 Bytes
/
bird.pde
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
class Bird{
// x position of Bird
float posx;
// y position of Bird
float posy;
// velocity of Bird
float vely;
// acceleration of Bird
float accy;
// constant gravity i.e It must fall down
float gravity=0.5;
Bird(){
// the starting point of Bird
posx=64;
posy=height/2;
// velocity of Bird
vely=0;
accy=0;
}
// update function is called in setup functiom
void update(){
// rate of change of velocity is acceleration
vely+=accy;
// rate of change of distance is velocity
// update velocity and acceleration
vely+=gravity;
posy+=vely;
// we have make posY limited to (0, height), else it will continuing moving upward out of canvas
posy=constrain(posy,0,height);
// we have make valY limited to (0, 4), else it will move so fast
vely=constrain(vely,0,4);
accy=0;
}
// function to show the bird
void show(){
fill(255);
ellipse(posx,posy,32,32);
}
}