Aller au contenu

Bloc traversable

Sullivan
  1. load.js
    const PNG = [
    "small-grass",
    "grass",
    ]
  2. component.js
    function passThroughController(p) {
    const param = {
    downKey: "down",
    ...p
    }
    return {
    id: "pass though",
    add() {
    onKeyPress(param.downKey, () => this.isPassingThrough = true)
    this.onCollideEnd("pass through", () => this.isPassingThrough = false)
    this.onBeforePhysicsResolve(col => {
    if (col.target.is("pass through") && (this.isPassingThrough || this.isJumping())) {
    col.preventResolution()
    this.trigger("passing through")
    }
    })
    },
    }
    }
  3. config.js
    const LEVEL_CONFIG = {
    // paramètres du niveau
    tileWidth: 64,
    tileHeight: 64,
    backgroundColor: "afe1ff",
    gravity: 3200,
    tiles: {
    "-": () => [ // block
    sprite("small-grass"),
    area(),
    body({ isStatic: true }),
    anchor("bot"),
    offscreen({ hide: true }),
    pos(0, -32),
    "pass through",
    ],
    "#": () => [ // player 1
    sprite("bean"),
    platformerController(),
    alive(),
    opacity(),
    scale(),
    health(1, 4),
    area(),
    anchor("bot"),
    body(),
    respawn(),
    falling(),
    ],
    "=": () => [ // block
    sprite("grass"),
    area(),
    body({ isStatic: true }),
    anchor("bot"),
    offscreen({ hide: true }),
    ],
    },
    }
  4. config.js
    "#": () => [ // player 1
    passThroughController(),
    sprite("bean"),
    platformerController(),
    alive(),
    opacity(),
    scale(),
    health(1, 4),
    area(),
    anchor("bot"),
    body(),
    respawn(),
    falling(),
    ],
  5. level.js
    const LEVELS = [
    {
    map: `
    -----
    #
    =====
    `,
    },
    ]
example
config.js
passThroughController({
downKey: "down"
}),