Aller au contenu

Clés

  1. load.js
    const PNG = [
    "door",
    "locker",
    "key",
    "grass",
    ]
  2. load.js
    const MP3 = [
    "door",
    "score",
    "bloup",
    "wooosh",
    "off",
    ]
  3. config.js
    const TILE_CONFIG = {
    "l": () => [ // porte verrouillée
    sprite("door"),
    headSprite({sprite:"locker",pos:vec2(5,-30)}),
    area(),
    door({ locked: true }),
    anchor("bot"),
    offscreen({ hide: true }),
    z(-1),
    ],
    "c": () => [ // clé
    sprite("key"),
    area(),
    anchor("bot"),
    respawn(),
    catchable({ type: "key" }),
    ],
    "#": () => [ // player 1
    sprite("bean"),
    platformerController(),
    jumpController(),
    sleep(),
    alive(),
    opacity(),
    scale(),
    health(1, 4),
    area(),
    body(),
    respawn(),
    falling(),
    rotate(),
    pos(0, -20),
    anchor("center"),
    ],
    "=": () => [ // block
    sprite("grass"),
    area({ collisionIgnore: ["agent"] }),
    body({ isStatic: true }),
    anchor("bot"),
    offscreen({ hide: true }),
    tile({ isObstacle: true }),
    ],
    }
  4. config.js
    "#": () => [ // player 1
    holdItem(),
    sprite("bean"),
    platformerController(),
    jumpController(),
    sleep(),
    alive(),
    opacity(),
    scale(),
    health(1, 4),
    area(),
    body(),
    respawn(),
    falling(),
    rotate(),
    pos(0, -20),
    anchor("center"),
    ],
  5. game.js
    scene("game", () => {
    const tiles = { ...TILE_CONFIG, ...LEVELS[CURRENT_LEVEL].tiles }
    const config = { ...LEVEL_CONFIG, ...LEVELS[CURRENT_LEVEL].config, ...{tiles:tiles}}
    const map = LEVELS[CURRENT_LEVEL].map.split('\n')
    const level = addLevel(map, config)
    const utility = add([
    multiplayerCamera(),
    ])
    setGravity(config.gravity)
    setBackground(config.backgroundColor)
    on('picked', 'hold', () => play("score"))
    on('try enter', 'door', (obj, p) => obj.tryEnter(p.from.isHolding("key"), p.from))
    on('locked', 'door', () => play('bloup'))
    on('locked', 'door', (obj) => tween(0, Math.PI * 2, 0.2, (v) => obj.head.angle = Math.sin(v) * 10))
    on('grab catch', 'hand', (obj, p) => { tween(p.dist, obj.hand.pos, 0.2, (v) => obj.hand.pos = v, easings.easeOutSine); obj.hand.pos = p.dist })
    on('dropped', 'catchable', (obj, p) => tween(p.parentPos, p.pos, 0.2, (v) => obj.pos = v, easings.easeOutSine))
    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'))
    }
  6. level.js
    const LEVELS = [
    {
    map: `
    c
    l #
    ==========
    =
    =
    =
    ========== =
    `,
    },
    ]
door()
example
config.js
door({
nextLevel: true,
destination: 0,
delay: 0.1,
onInteract: false,
locked: false
}),
holdItem()
example
config.js
holdItem({
pos: vec2(0, -30),
item: "{",
sprite: "key",
holdItemType: "key"
}),