Trampolines

pour Saul

Les objets rebondissants peuvent être l'occasion de confronter le joueur à de nouveaux challenges sollicitant sa précision et son sens du timing

Charger une image

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

Charger un effet sonore

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

Créer un composant

component.js
// Ajoutes ici tes propres composants
function spring(p) { // permet à un objet de faire rebondinr les objets qui se trouvent dessus const param = { power: 1200, delay: 1, amplitude: 0.3, tag: "body", ...p } return { id: "spring", require: ["scale"], add() { this.onCollide(param.tag, (obj, col) => this.checkSpringColission(obj, col)) }, checkSpringColission(obj, col) { if (col.isTop()) { obj.jump(param.power) play("boing") this.springAnim() } }, springAnim() { tween( param.amplitude, 0, param.delay, (v) => (this.scale.y = 1 - v), easings.easeOutBounce ) }, } }

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
"C": () => [ // champignon sprite("mushroom"), area(), anchor("bot"), body({ isStatic: true }), scale(), spring(), ],
"#": () => [ // player sprite("bean"), platformerController(), alive(), opacity(), scale(), health(1, 4), area(), anchor("bot"), body(), respawn(), falling(), coloring(), animator(), ], "=": () => [ // block sprite("grass"), area(), body({ isStatic: true }), anchor("bot"), offscreen({ hide: true }), ], }, }

Placer les objets

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

spring

levelConf.js
tiles :
spring({ power: 1200, delay: 1, amplitude: 0.3, tag: "body", }),