Fond sonore
Ismaël
Le son permet de donner une identité sonore au jeu et favoriser l’immersion du joueur.
Charger un son
Section intitulée « Charger un son »load.js const MP3 = ["tough zombeat","wooosh","off",]Créer un composant
Section intitulée « Créer un composant »component.js function music(config) {const param = {volume: 1.0,...config}return {audio: null,add() {if (param.music) {this.audio = play(param.music, { loop: true, volume: param.volume })onSceneLeave(() => this.audio.stop())}}}}modifier la scène
Section intitulée « modifier la scène »game.js scene("game", () => {const config = { ...LEVEL_CONFIG, ...LEVELS[CURRENT_LEVEL].config }const map = LEVELS[CURRENT_LEVEL].map.split("\n")const level = addLevel(map, config)add([music(config),multiplayerCamera(),])setGravity(config.gravity)setBackground(config.backgroundColor)on('jump', 'player', () => play('wooosh'))on('drop', 'player', () => play('off'))on('respawn', 'player', (obj) => obj.play('idle'))on('sleep', 'player', (obj) => obj.play('sleep'))on('awake', 'player', (obj) => obj.play('idle'))on('jump', 'player', (obj) => obj.play('jump', { speed: 4, onEnd: () => obj.play('idle') }))on('drop', 'player', (obj) => obj.play('worry'))}configurer les niveaux
Section intitulée « configurer les niveaux »game.js const LEVEL_CONFIG = {music: 'tough zombeat',volume: 1,tileWidth: 64,tileHeight: 64,backgroundColor: "afe1ff",gravity: 3200,tiles: {"#": () => [ // player 1sprite("bean"),platformerController(),alive(),opacity(),scale(),health(1, 4),area(),anchor("bot"),body(),respawn(),falling(),],"=": () => [ // blocksprite("grass"),area(),body({ isStatic: true }),anchor("bot"),offscreen({ hide: true }),],},};