Skip to content

Commit

Permalink
Sync with published result of episode 20.
Browse files Browse the repository at this point in the history
  • Loading branch information
pomle committed Mar 31, 2020
1 parent 3d9ad5b commit a347981
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion public/js/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export class Trait {
}

listen(name, callback, count = Infinity) {
this.listeners.push({name, callback, count});
const listener = {name, callback, count};
this.listeners.push(listener);
console.log("Added listener", this, name);
}

finalize(entity) {
Expand Down Expand Up @@ -52,6 +54,8 @@ export default class Entity {
this.events = new EventBuffer();
this.sounds = new Set();

this.events = new EventBuffer();

this.pos = new Vec2(0, 0);
this.vel = new Vec2(0, 0);
this.size = new Vec2(0, 0);
Expand Down
1 change: 1 addition & 0 deletions public/js/EventBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default class EventBuffer {
emit(name, ...args) {
const event = {name, args};
this.events.push(event);
console.log(this.events);
}

process(name, callback) {
Expand Down
3 changes: 2 additions & 1 deletion public/js/entities/Koopa.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class Behavior extends Trait {
this.state = STATE_PANIC;
}

update(us, {deltaTime}) {
update(us, gameContext) {
const deltaTime = gameContext.deltaTime;
if (this.state === STATE_HIDING) {
this.hideTime += deltaTime;
if (this.hideTime > this.hideDuration) {
Expand Down
1 change: 1 addition & 0 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async function main(canvas) {
const camera = new Camera();

const mario = createPlayer(entityFactory.mario());
window.mario = mario;

const playerEnv = createPlayerEnv(mario);
level.entities.add(playerEnv);
Expand Down
3 changes: 2 additions & 1 deletion public/js/traits/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import Stomper from '../traits/Stomper.js';
export default class Player extends Trait {
constructor() {
super('player');
this.coins = 0;
this.lives = 3;
this.score = 0;

this.listen(Stomper.EVENT_STOMP, () => {
this.score += 100;
console.log("Stomp", this.score);
console.log('Score', this.score);
});
}
}
4 changes: 4 additions & 0 deletions public/js/traits/PlayerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export default class PlayerController extends Trait {
this.player = null;
this.score = 0;
this.time = 300;

this.listen('stomp', () => {
this.score += 100;
});
}

setPlayer(entity) {
Expand Down

0 comments on commit a347981

Please sign in to comment.