Échelles
Issa
Les échelles peuvent permettre de donner au jeu plus de verticalité et peuvent être l’occasion de présenter de nouveaux types de défis pour le joueur.
Charger une image
Section intitulée « Charger une image »load.js const PNG = ["ladder","grass",]Créer des composants
Section intitulée « Créer des composants »component.js function climbController(p) {const param = {upKey: "up",downKey: "down",climbSpeed: 400,climbJump: 600,delay: 0.05,sticky: true,catch: true,...p}return {onLadder: false,savedTimeOnLadder: 0,isClimbing: false,require: ["player"],add() {this.onCollideUpdate("climb", () => this.savedTimeOnLadder = time())onKeyDown(param.upKey, () => this.climb(-1));onKeyDown(param.downKey, () => this.climb(1));this.on("climb start", () => {this.gravityScale = 0this.vel = vec2(0, 0)this.isClimbing = true})this.on("climb stop", () => {this.isClimbing = falsethis.gravityScale = 1})this.on("climb jump", () => this.jump(param.climbJump))},climb(d) {if (this.isAlive && this.isClimbing && this.onLadder) {this.move(0, d * param.climbSpeed)}},update() {this.onLadder = time() - this.savedTimeOnLadder < param.delayif (!this.isClimbing && this.isAlive && this.onLadder && (param.sticky || isKeyDown(param.upKey))) this.trigger("climb start")else if (this.isClimbing && !this.onLadder) {if (isKeyDown(param.upKey)) this.trigger("climb jump")this.trigger("climb stop")}else if (this.isClimbing && this.isGrounded()) this.trigger("climb stop")else if (this.isClimbing && !param.catch && !isKeyDown(param.upKey)) this.trigger("climb stop")},}}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: {"H": () => [ // échellesprite("ladder"),area(),anchor("bot"),offscreen({ hide: true }),z(-1),"climb",],"#": () => [ // 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 1climbController(),sprite("bean"),platformerController(),alive(),opacity(),scale(),health(1, 4),area(),anchor("bot"),body(),respawn(),falling(),],Lancer une animation
Section intitulée « Lancer une animation »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('climb jump', 'player', () => play('wooosh'))on('climb 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'))}Placer les objets
Section intitulée « Placer les objets »level.js const LEVELS = [{map: `HH H H ===H H H# H H======`,},]
Paramètres
Section intitulée « Paramètres »exampleconfig.js
climbController({ upKey: "up", downKey: "down", climbSpeed: 400, climbJump: 600, delay: 0.05, sticky: true, catch: true}),