Skip to content

Commit

Permalink
Sync with published result of episode 15.
Browse files Browse the repository at this point in the history
  • Loading branch information
pomle committed Feb 19, 2020
1 parent 5c8e2bf commit dfdd5e4
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 34 deletions.
4 changes: 2 additions & 2 deletions public/js/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export function loadEntities(audioContext) {

return Promise.all([
loadMario(audioContext).then(addAs('mario')),
loadGoomba().then(addAs('goomba')),
loadKoopa().then(addAs('koopa')),
loadGoomba(audioContext).then(addAs('goomba')),
loadKoopa(audioContext).then(addAs('koopa')),
])
.then(() => entityFactories);
}
8 changes: 4 additions & 4 deletions public/js/entities/Mario.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export function loadMario(audioContext) {
loadSpriteSheet('mario'),
loadAudioBoard('mario', audioContext),
])
.then(([sprite, audioBoard]) => {
return createMarioFactory(sprite, audioBoard);
.then(([sprite, audio]) => {
return createMarioFactory(sprite, audio);
});
}

function createMarioFactory(sprite, audioBoard) {
function createMarioFactory(sprite, audio) {
const runAnim = sprite.animations.get('run');

function routeFrame(mario) {
Expand Down Expand Up @@ -50,7 +50,7 @@ function createMarioFactory(sprite, audioBoard) {

return function createMario() {
const mario = new Entity();
mario.audio = audioBoard;
mario.audio = audio;
mario.size.set(14, 16);

mario.addTrait(new Physics());
Expand Down
13 changes: 8 additions & 5 deletions public/js/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import AudioBoard from './AudioBoard.js';
import Camera from './Camera.js';
import Entity from './Entity.js';
import PlayerController from './traits/PlayerController.js';
import Timer from './Timer.js';
import {createLevelLoader} from './loaders/level.js';
import {createAudioLoader} from './loaders/audio.js';
import {loadFont} from './loaders/font.js';
import {loadEntities} from './entities.js';
import {setupKeyboard} from './input.js';
Expand All @@ -29,9 +27,8 @@ async function main(canvas) {
loadFont(),
]);

const loadAudio = createAudioLoader(audioContext);
const loadLevel = createLevelLoader(entityFactory);

const loadLevel = await createLevelLoader(entityFactory);

const level = await loadLevel('1-1');

Expand Down Expand Up @@ -68,4 +65,10 @@ async function main(canvas) {
}

const canvas = document.getElementById('screen');
main(canvas);

const start = () => {
window.removeEventListener('click', start);
main(canvas);
};

window.addEventListener('click', start);
3 changes: 1 addition & 2 deletions public/js/traits/Go.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export default class Go extends Trait {
this.heading = 1;
}

update(entity, gameContext) {
const deltaTime = gameContext.deltaTime;
update(entity, {deltaTime}) {
const absX = Math.abs(entity.vel.x);

if (this.dir !== 0) {
Expand Down
3 changes: 1 addition & 2 deletions public/js/traits/Jump.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export default class Jump extends Trait {
}
}

update(entity, gameContext, level) {
const deltaTime = gameContext.deltaTime;
update(entity, {deltaTime}) {
if (this.requestTime > 0) {
if (this.ready > 0) {
this.sounds.add('jump');
Expand Down
4 changes: 2 additions & 2 deletions public/js/traits/Killable.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export default class Killable extends Trait {
this.deadTime = 0;
}

update(entity, gameContext, level) {
update(entity, {deltaTime}, level) {
if (this.dead) {
this.deadTime += gameContext.deltaTime;
this.deadTime += deltaTime;
if (this.deadTime > this.removeAfter) {
this.queue(() => {
level.entities.delete(entity);
Expand Down
9 changes: 1 addition & 8 deletions public/js/traits/PendulumMove.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@ export default class PendulumMove extends Trait {
constructor() {
super('pendulumMove');
this.enabled = true;
this.bumped = false;
this.speed = -30;
}

obstruct(entity, side) {
if (side === Sides.LEFT || side === Sides.RIGHT) {
this.speed = -this.speed;
this.bumped = true;
}
}

update(entity, {audioContext}) {
if (this.bumped) {
entity.audio.playAudio('bump', audioContext);
this.bumped = false;
}

update(entity) {
if (this.enabled) {
entity.vel.x = this.speed;
}
Expand Down
10 changes: 1 addition & 9 deletions public/js/traits/Stomper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export default class Stomper extends Trait {
constructor() {
super('stomper');
this.bounceSpeed = 400;
this.didStomp = false;

this.onStomp = function() {
}
Expand All @@ -22,15 +21,8 @@ export default class Stomper extends Trait {

if (us.vel.y > them.vel.y) {
this.bounce(us, them);
this.didStomp = true;
this.onStomp(us, them);
}
}

update(entity) {
if (this.didStomp) {
this.sounds.add('stomp');
this.didStomp = false;
this.onStomp(us, them);
}
}
}

0 comments on commit dfdd5e4

Please sign in to comment.