-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBird.js
41 lines (38 loc) · 822 Bytes
/
Bird.js
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
var x;
var y;
var length;
var height;
var velocity;
var acceleration;
var jumpTimer;
class Bird{
constructor(x,y,length,height){
this.x=x;
this.y=y;
this.length=length;
this.height=height;
this.velocity=-10;
this.acceleration=1;
this.jumpTimer=0;
}
display(){
var temping;
if(this.velocity<0) temping=imgBirdFly;
else if(this.velocity>7) temping=imgBirdFall;
else temping=imgBird;
image(temping,this.x,this.y,this.length,this.height);
}
move(){
if(keyIsPressed && keyCode==87 && (millis()-this.jumpTimer)>180){
this.jumpTimer=millis();
this.velocity=-14;
tururu.play();
}
if(!(this.y+this.velocity<=0 || this.y+this.length+this.velocity>=frameY)){
this.velocity+=this.acceleration;
}
else this.velocity=0;
if(this.velocity>30) this.velocity=10;
this.y+=this.velocity;
}
}