Aller au contenu

Double saut

Andy

Le double saut permet de donner plus de contrôle au joueur dans ces déplacements. Cela peut lui permettre de sauter plus haut ou plus loin, ou encore d’effectuer des mouvements spécifiques en jouant sur le timing du deuxième saut.

  1. config.js
    "#": () => [ // player 1
    sprite("bean"),
    platformerController({ doubleJump: 1 }),
    alive(),
    opacity(),
    scale(),
    health(1, 4),
    area(),
    anchor("bot"),
    body(),
    respawn(),
    falling(),
    ],
  2. 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([
    multiplayerCamera(),
    ])
    setGravity(config.gravity)
    setBackground(config.backgroundColor)
    on('double jump', 'player', () => play('wooosh'))
    on('double jump', 'player', (obj) => obj.play('jump', { speed: 4, onEnd: () => obj.play('idle') }))
    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'))
    }
example
config.js
platformerController({
jumpKey: "up",
leftKey: "left",
rightKey: "right",
downKey: "down",
jumpForce: 1000,
moveSpeed: 480,
glideDelay: 0.1,
airjumpForce: 800,
doubleJump: 0,
sleepDelay: 2
}),