Décors
Issa
Les éléments de décoration permettent de rendre l’univers figuré par le jeu plus vivant et plus immersif. Ils peuvent aussi être l’occasion de cacher des passages ou des objets secrets.Charger une image
Section intitulée « Charger une image »load.js const PNG = ["bush","grass",]Créer des composants
Section intitulée « Créer des composants »component.js function swing(p) {const param = {delay: 0.4,amplitude: 4,speed: 1,on: true,...p}const offset_mult = 0.5return {id: "swing",require: ["rotate"],swingAmp: 0,add() {if (param.on) this.swingAmp = 1;},update() {const offset = this.pos.x + this.pos.yconst timer = time() * param.speed + offset * offset_multthis.angle = wave(-param.amplitude, param.amplitude, timer) * this.swingAmp},swingSwitch(b) {tween(this.swingAmp, b ? 1 : 0, param.delay, (v) => (this.swingAmp = v))},}}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: {"b": () => [ // décoration arrière plansprite("bush"),area(),anchor("bot"),swing(),offscreen({ hide: true }),rotate(),scale(1),z(-1),],"B": () => [ // décoration premier plansprite("bush"),area(),anchor("bot"),swing(),offscreen({ hide: true }),rotate(),scale(1.25),z(1),],"#": () => [ // 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 }),],},}Placer les objets
Section intitulée « Placer les objets »level.js const LEVELS = [{map: `====# b B b===========`,},]
Paramètres
Section intitulée « Paramètres »exampleconfig.js
swing({ delay: 0.4, amplitude: 4, speed: 1, on: true}),