xxxxxxxxxx
85
/*
Ajoutes dans ce srcipt tes propres composants
*/
function climbSurface() {
return {
require: [ "pos", "area", ],
add() {
this.onCollide("climbableExit", (e) => {
destroy(e);
});
},
load() {
const epw = 20 , mrgw = 10 , mrgh = 30 ;
const x = this.pos.x , y = this.pos.y ;
const h = this.height , w = this.width ;
let m = [];
for ( let i = 0 ; i < 5 ; i ++ ){
m[i]=add([
rect(epw,epw),
opacity(0),
area(),
pos(this.pos.x,this.pos.y),
origin("bot"),
"climbableExit",
]);
}
m[0].height = h ;
m[1].height = h ;
m[2].width = w * 2 + epw + mrgw ;
m[3].width = w * 2 + epw + mrgw ;
m[4].width = w * 2 + epw + mrgw ;
m[0].pos.x = x - w - mrgw ;
m[1].pos.x = x + w + mrgw ;
m[2].pos.y = y + mrgh ;
m[3].pos.y = y - h - mrgh / 2 ;
m[4].pos.y = y - h - mrgh * 2 - epw ;
},
}
}
function climb(climbKey = "up") {
const climbPower = 600 ;
let onLadder = false ;
return {
require: [ "pos" , "area" , "body" ],
add() {
this.onCollide("climbableExit", (p) => {
onLadder = false;
});
this.onCollide("climbable" , (p) => {
onLadder = true;
});
this.onHeadbutt((p) => {
onLadder = false;
})
onKeyDown(climbKey, () => {
if(onLadder) this.jump(climbPower) ;
});
},
}
}