Bloc traversable
Sullivan
Charger une image
Section intitulée « Charger une image »load.js const PNG = ["small-grass","grass",]Créer un composant
Section intitulée « Créer un composant »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")}})},}}Déclarer un objet
Section intitulée « Déclarer un objet »config.js const LEVEL_CONFIG = {// paramètres du niveautileWidth: 64,tileHeight: 64,backgroundColor: "afe1ff",gravity: 3200,tiles: {"-": () => [ // blocksprite("small-grass"),area(),body({ isStatic: true }),anchor("bot"),offscreen({ hide: true }),pos(0, -32),"pass through",],"#": () => [ // player 1sprite("bean"),platformerController(),alive(),opacity(),scale(),health(1, 4),area(),anchor("bot"),body(),respawn(),falling(),],"=": () => [ // blocksprite("grass"),area(),body({ isStatic: true }),anchor("bot"),offscreen({ hide: true }),],},}modifier le joueur
Section intitulée « modifier le joueur »config.js "#": () => [ // player 1passThroughController(),sprite("bean"),platformerController(),alive(),opacity(),scale(),health(1, 4),area(),anchor("bot"),body(),respawn(),falling(),],Placer les objets
Section intitulée « Placer les objets »level.js const LEVELS = [{map: `-----#=====`,},]
Paramètres
Section intitulée « Paramètres »exampleconfig.js
passThroughController({ downKey: "down"}),