Aller au contenu

Fond sonore

Ismaël

Le son permet de donner une identité sonore au jeu et favoriser l’immersion du joueur.

  1. load.js
    const MP3 = [
    'tough zombeat',
    'wooosh',
    'off',
    ];
  2. game.js
    function events() {
    return {
    add() {
    // personnages
    on('respawn', 'alive', (obj) => (obj.flipY = false));
    on('hurt', 'alive', (obj) => {
    play('hit');
    colorShiftFx(obj, { color: 'ff9b9b' });
    });
    on('death', 'alive', (obj) => {
    obj.flipY = true;
    wait(0.2, () => {
    if (!obj.isAlive) {
    obj.hidden = true;
    obj.collisionIgnore = ['*'];
    obj.isStatic = true;
    }
    });
    });
    // joueur
    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) => {
    play('wooosh');
    obj.play('jump', {
    speed: 4,
    onEnd: () => obj.play('idle'),
    });
    });
    on('drop', 'player', (obj) => {
    play('off');
    obj.play('worry');
    });
    on('hurt', 'player', (obj) => {
    obj.play('worry', {
    speed: 2,
    onEnd: () => obj.play('idle'),
    });
    });
    },
    };
    }
  3. config.js
    const LEVEL_CONFIG = {
    music: 'tough zombeat',
    volume: 1,
    tileWidth: 64,
    tileHeight: 64,
    backgroundColor: 'afe1ff',
    gravity: 3200,
    }