Blocs qui écrasent

Les blocs qui écrasent sont des objets dynamiques que le joueur peut pousser, mais qui lui sont hostiles si elles le touchent par le haut alors que celui-ci est au contact du sol.

Charger une image

load.js
const PNG = [ "steel", "grass" , ]

Charger un effet sonore

load.js
const MP3 = [ "squish" , "wooosh" , "off" , ]

Créer un composant

component.js
// Ajoutes ici tes propres composants
function stomp(p) { // permet à un objet d'infliger des dégats aux personnages sur lesquels il tombe const param = { tag: "alive", ...p } return { add() { this.onCollide(param.tag, (obj, col) => this.checkDangerColission(obj, col)) }, checkDangerColission(obj, col) { if ( obj.isGrounded() && col.isBottom() ) { if (obj.hit(obj.hp())) play("squish") } }, } }

Déclarer un symbole

levelConf.js
const LEVEL_CONFIG = { // paramètres du niveau tileWidth: 64, tileHeight: 64, backgroundColor: "afe1ff", gravity: 3200, tiles: { // listes des objets à placer dans les niveaux
"X": () => [ // steel sprite("steel"), area(), body(), anchor("bot"), stomp(), falling(), respawn({ live: true }), opacity(), scale(), ],
"#": () => [ // player sprite("bean"), platformerController(), health(1), character(), area(), anchor("bot"), body(), ], "=": () => [ // bloc sprite("grass"), area(), body({ isStatic: true }), anchor("bot"), offscreen({ hide: true }), ], }, }

Placer les objets

level.js
const LEVELS = [ // liste des niveaux du jeu { map: ` === X = X = X # X ============ `, }, ];

stomp

levelConf.js
tiles :
stomp({ tag: "alive", }),

respawn

levelConf.js
tiles :
respawn({ live: false, appearAnimDuration: 0.4, }),