xxxxxxxxxx
46
/*
Ajoutes dans ce srcipt tes propres composants
*/
// composant permettant d'animer l'arrière plan
function movingBackground( scaling = 1.4 , movement = 0.1){
const x = width() / 2 - width() / 2 * scaling ;
const y = height() / 2 - height() / 2 * scaling ;
const ax = width() * movement / 2 ;
const ay = height() * movement / 2 ;
let w = 0 ;
let h = 0 ;
return {
load() {
h = LEVELS[CURRENT_LEVEL].length;
for (let i = 0 ; i < h ; i++) {
let n = LEVELS[CURRENT_LEVEL][i].length;
if (n>w) w=n;
}
every("background", (e) => {
e.scale = scaling ;
});
},
update() {
const vx = this.pos.x / ( w * LEVEL_CONFIG.width ) - 0.5 * 2 ;
const vy = this.pos.y / ( h * LEVEL_CONFIG.height ) - 0.5 * 2 ;
every("background", (e) => {
e.pos.x = x - vx * ax ;
e.pos.y = y - vy * ay ;
});
},
}
}