Aller au contenu

Inventaire

Anton
  1. load.js
    const PNG = [
    "apple",
    "pineapple",
    "watermelon",
    "grape",
    "grass",
    ]
  2. load.js
    const MP3 = [
    "score",
    "wooosh",
    "off",
    ]
  3. config.js
    const TILE_CONFIG = {
    "q": () => [ // pastèque
    sprite("watermelon"),
    collectible({
    goesToInventory: true,
    type: "watermelon"
    }),
    area(),
    respawn(),
    anchor("center"),
    pos(0, -32),
    ],
    "p": () => [ // pomme
    sprite("apple"),
    collectible({
    goesToInventory: true,
    type: "apple"
    }),
    area(),
    respawn(),
    anchor("center"),
    pos(0, -32),
    ],
    "r": () => [ // raisins
    sprite("grape"),
    collectible({
    goesToInventory: true,
    type: "grape"
    }),
    area(),
    respawn(),
    anchor("center"),
    pos(0, -32),
    ],
    "n": () => [ // ananas
    sprite("pineapple"),
    collectible({
    goesToInventory: true,
    type: "pineapple"
    }),
    area(),
    respawn(),
    anchor("center"),
    pos(0, -32),
    ],
    "#": () => [ // 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
    inventory(),
    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('disapear', 'collectible', (obj) => splashFX(obj.pos, { offset: vec2(0, -20) }))
    on('disapear', 'collectible', () => play('score'))
    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: `
    p p
    ===
    = q
    r r ===
    ===
    n
    ===
    #
    ======
    `,
    },
    ]
collectible()
example
config.js
collectible({
tag: "player",
offset: vec2(0, -20),
type: "item",
goesToInventory: false,
autoDestroy: true,
interactToPick: false
}),
inventory()
example
config.js
inventory({
giveKey: "space",
payDistance: 200,
deleteOnRespawn: true,
numbers: false,
itemSize: 40,
speakHeight: 60,
speakPadding: 4,
stackMargin: 20,
margin: 10,
updateDelay: 0.2,
displayDelay: 4,
textSize: 40,
textOffset: vec2(10, 34)
}),