Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gravity update to bird.js #45

Merged
merged 3 commits into from
Apr 9, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions bird.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Bird {
this.x = 64;

this.gravity = 0.6;
this.lift = -15;
this.delay = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a boolean flag variable make more sense here?

Copy link
Contributor Author

@buensons buensons Apr 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. A boolean variable would work, and it's going ot be easier to read. Is it better now?

this.velocity = 0;

this.icon = birdSprite;
Expand All @@ -26,12 +26,17 @@ class Bird {
}

up() {
this.velocity += this.lift;
if (this.delay > 0)
this.delay--;

if (this.delay <= 0) {
this.velocity = -7;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a global variable for the -7 would be a good thing to do. It's easier to modify static values when they are global.

this.delay = 1;
}
}

update() {
this.velocity += this.gravity;
this.velocity *= 0.9;
this.y += this.velocity;

if (this.y >= height - this.height / 2) {
Expand Down