Skip to content

Commit 30f1d18

Browse files
authored
Merge pull request #19 from musabkilic/master
Added this.size to bird.js and improved the code for keeping the bird in the screen
2 parents 7f01de9 + baa45eb commit 30f1d18

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

bird.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ class Bird {
77
constructor() {
88
this.y = height/2;
99
this.x = 64;
10+
this.size = 32;
11+
1012
this.gravity = 0.6;
1113
this.lift = -15;
1214
this.velocity = 0;
15+
1316
this.icon = loadImage("graphics/train.png");
1417
this.width = 64;
1518
this.height = 64;
@@ -29,13 +32,13 @@ class Bird {
2932
this.velocity *= 0.9;
3033
this.y += this.velocity;
3134

32-
if (this.y >= height) {
33-
this.y = height;
35+
if (this.y >= height - this.size/2) {
36+
this.y = height - this.size/2;
3437
this.velocity = 0;
3538
}
3639

37-
if (this.y < 0) {
38-
this.y = 0;
40+
if (this.y <= this.size/2) {
41+
this.y = this.size/2;
3942
this.velocity = 0;
4043
}
4144
}

0 commit comments

Comments
 (0)