Skip to content

Commit

Permalink
Add music to game and take debug cubes"
Browse files Browse the repository at this point in the history
  • Loading branch information
Goncalves95 committed Aug 19, 2024
1 parent 720b342 commit 651aee3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
9 changes: 2 additions & 7 deletions assets/js/layers/collision.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ function createTileCandidateLayer(tileCollider) {
}

export function createCollisionLayer(level) {

const drawTileCandidates = createTileCandidateLayer(level.tileCollider);
const drawBoundingBoxes = createEntityLayer(level.entities);

return function drawCollision(context, camera) {
drawTileCandidates(context, camera);
drawBoundingBoxes(context, camera);
// No-op, as we're not drawing anything
};
}
}
36 changes: 26 additions & 10 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ 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 {loadFont} from './loaders/font.js';
import {loadEntities} from './entities.js';
import {setupKeyboard} from './input.js';
import {createCollisionLayer} from './layers/collision.js';
import {createDashboardLayer} from './layers/dashboard.js';
import { createLevelLoader } from './loaders/level.js';
import { loadFont } from './loaders/font.js';
import { loadEntities } from './entities.js';
import { setupKeyboard } from './input.js';
import { createCollisionLayer } from './layers/collision.js';
import { createDashboardLayer } from './layers/dashboard.js';

function createPlayerEnv(playerEntity) {
const playerEnv = new Entity();
Expand All @@ -27,6 +27,14 @@ async function main(canvas) {
loadFont(),
]);

let audio = new Audio('audio/overworld.mp3');

// Set the loop attribute to true
audio.loop = true;

// Play the audio when the game starts
audio.play();


const loadLevel = await createLevelLoader(entityFactory);

Expand All @@ -51,7 +59,7 @@ async function main(canvas) {
deltaTime: null,
};

const timer = new Timer(1/60);
const timer = new Timer(1 / 60);
timer.update = function update(deltaTime) {
gameContext.deltaTime = deltaTime;
level.update(gameContext);
Expand Down Expand Up @@ -83,6 +91,14 @@ startButton.style.cssText = `
document.body.appendChild(startButton);

startButton.addEventListener('click', () => {
startButton.remove();
main(canvas);
});
startButton.remove();
main(canvas);
});

let audio = new Audio('audio/overworld.mp3');

// Set the loop attribute to true
audio.loop = true;

// Play the audio when the game starts
audio.play();
Binary file added audio/overworld.mp3
Binary file not shown.
Binary file added audio/overworld.ogg
Binary file not shown.

0 comments on commit 651aee3

Please sign in to comment.