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 2 commits
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 = false;
this.velocity = 0;

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

up() {
this.velocity += this.lift;
if (this.delay)
Copy link

@ZwergB ZwergB Apr 3, 2018

Choose a reason for hiding this comment

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

Isn't this whole this.delay variable kind of irrelevant? Sorry if I miss something but it seems like you could delete the entire if-statement and just leave line 33.

this.delay = false;

if (!this.delay) {
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 = true;
}
}

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

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