function onExplosionBreakOrSurvive

fires if a pixel is broken by or survives an explosion
This commit is contained in:
Laetitia (O-01-67) 2022-12-10 18:23:01 -05:00 committed by GitHub
parent 40436449ad
commit 43a31a8882
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -1,3 +1,5 @@
velocityBlacklist = [];
function explodeAtPlus(x,y,radius,fire="fire",smoke="smoke",beforeFunction=null,afterFunction=null,changeTemp=true) {
// if fire contains , split it into an array
if(fire !== null) {
@ -84,6 +86,9 @@ function explodeAtPlus(x,y,radius,fire="fire",smoke="smoke",beforeFunction=null,
}
// change the pixel to the result
changePixel(pixel,result,changeTemp);
if(info.onExplosionBreakOrSurvive) {
info.onExplosionBreakOrSurvive(pixel,x,y,radius,fire,smoke,power,damage);
};
continue;
}
else {
@ -100,6 +105,10 @@ function explodeAtPlus(x,y,radius,fire="fire",smoke="smoke",beforeFunction=null,
}
continue;
}
} else {
if(info.onExplosionBreakOrSurvive) {
info.onExplosionBreakOrSurvive(pixel,x,y,radius,fire,smoke,power,damage);
};
}
if (damage > 0.75 && info.burn) {
pixel.burning = true;
@ -107,6 +116,14 @@ function explodeAtPlus(x,y,radius,fire="fire",smoke="smoke",beforeFunction=null,
}
pixel.temp += damage*radius*power;
pixelTempCheck(pixel);
if(enabledMods.includes("mods/velocity.js")) {
// set the pixel.vx and pixel.vy depending on the angle and power
if (!elements[pixel.element].excludeRandom && !elements[pixel.element].excludeVelocity) {
var angle = Math.atan2(pixel.y-y,pixel.x-x);
pixel.vx = Math.round((pixel.vx|0) + Math.cos(angle) * (radius * power/10));
pixel.vy = Math.round((pixel.vy|0) + Math.sin(angle) * (radius * power/10));
}
};
if(typeof(afterFunction) === "function") {
//console.log(`running afterFunction ${afterFunction}`)
//console.log(`arguments: ${pixel}, ${x}, ${y}, ${radius}, ${fire}, ${smoke}, ${power}, ${damage}`)
@ -115,4 +132,3 @@ function explodeAtPlus(x,y,radius,fire="fire",smoke="smoke",beforeFunction=null,
};
};
};