-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbird.js
More file actions
45 lines (38 loc) · 1.08 KB
/
Copy pathbird.js
File metadata and controls
45 lines (38 loc) · 1.08 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
/*
* Her lager vi en klasse
* this. viser til variabler som er spesifike for hvert objekt
* som blir laget med klassen.
* Et objekt blir laget ved å skrive
* new bird();
*/
function Bird(){//fuglen trenger kun en y-pos
this.y = height/2; //starter fuglen i midten av vinduet
this.x = 64;
this.width = 32;
this.height = 32;
this.gravity = 0.7;
this.lift = -17;
this.velocity = 0;
this.angle = 0;
this.show = function() { //Tegne fuglen
stroke(255);
fill(225);
//ellipse(this.x, this.y, 32, 32);//fuglen blir først en sirkel
};
this.up = function(){
this.velocity += this.lift;
}
this.update = function() { //får den til å falle
this.velocity += this.gravity;
this.velocity *= 0.9;
this.y += this.velocity;
if(this.y > height){ //stopper når den treffer bakken
this.y = height;
this.velocity = 0;
}
if(this.y < 0){ //stopper når den treffer himmel
this.y = 0;
this.velocity = 0;
}
}
}