Skip to content

Commit

Permalink
Sync with published result of episode 8.
Browse files Browse the repository at this point in the history
  • Loading branch information
pomle committed Oct 17, 2017
1 parent b9799cf commit 650bbca
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions public/js/Entity.js
Expand Up @@ -11,6 +11,7 @@ export class Trait {
}

obstruct() {

}

update() {
Expand Down
5 changes: 1 addition & 4 deletions public/js/entities.js
Expand Up @@ -29,10 +29,7 @@ export function createMario() {
}

if (mario.go.distance > 0) {
if (
(mario.vel.x > 0 && mario.go.dir < 0) ||
(mario.vel.x < 0 && mario.go.dir > 0)
) {
if ((mario.vel.x > 0 && mario.go.dir < 0) || (mario.vel.x < 0 && mario.go.dir > 0)) {
return 'break';
}

Expand Down
8 changes: 6 additions & 2 deletions public/js/traits/Go.js
Expand Up @@ -19,7 +19,11 @@ export default class Go extends Trait {
if (this.dir !== 0) {
entity.vel.x += this.acceleration * deltaTime * this.dir;

if (!entity.jump || !entity.jump.falling) {
if (entity.jump) {
if (entity.jump.falling === false) {
this.heading = this.dir;
}
} else {
this.heading = this.dir;
}

Expand All @@ -31,7 +35,7 @@ export default class Go extends Trait {
}

const drag = this.dragFactor * entity.vel.x * absX;
entity.vel.x += -drag;
entity.vel.x -= drag;

this.distance += absX * deltaTime;
}
Expand Down
8 changes: 5 additions & 3 deletions public/js/traits/Jump.js
Expand Up @@ -9,6 +9,7 @@ export default class Jump extends Trait {
this.engageTime = 0;
this.requestTime = 0;
this.gracePeriod = 0.1;
this.speedBoost = 0.3;
this.velocity = 200;
}

Expand All @@ -21,8 +22,8 @@ export default class Jump extends Trait {
}

cancel() {
this.requestTime = 0;
this.engageTime = 0;
this.requestTime = 0;
}

obstruct(entity, side) {
Expand All @@ -39,14 +40,15 @@ export default class Jump extends Trait {
this.engageTime = this.duration;
this.requestTime = 0;
}

this.requestTime -= deltaTime;
}

if (this.engageTime > 0) {
entity.vel.y = -(this.velocity + Math.abs(entity.vel.x) * 0.3);
entity.vel.y = -(this.velocity + Math.abs(entity.vel.x) * this.speedBoost);
this.engageTime -= deltaTime;
}

--this.ready;
this.ready--;
}
}

0 comments on commit 650bbca

Please sign in to comment.