From abbc486d297fe1077163842e29a786d37461ccd4 Mon Sep 17 00:00:00 2001 From: slweeb <91897291+slweeb@users.noreply.github.com> Date: Tue, 13 Sep 2022 18:13:00 -0400 Subject: [PATCH] Update velocity.js --- mods/velocity.js | 91 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/mods/velocity.js b/mods/velocity.js index f9ba49d6..a88eb2a2 100644 --- a/mods/velocity.js +++ b/mods/velocity.js @@ -142,4 +142,93 @@ drawPixels = function(forceTick=false) { } -}) \ No newline at end of file +}) + +explodeAt = function(x,y,radius,fire="fire") { + // if fire contains , split it into an array + if (fire.indexOf(",") !== -1) { + fire = fire.split(","); + } + var coords = circleCoords(x,y,radius); + var power = radius/10; + //for (var p = 0; p < Math.round(radius/10+1); p++) { + for (var i = 0; i < coords.length; i++) { + // damage value is based on distance from x and y + var damage = Math.random() + (Math.floor(Math.sqrt(Math.pow(coords[i].x-x,2) + Math.pow(coords[i].y-y,2)))) / radius; + // invert + damage = 1 - damage; + if (damage < 0) { damage = 0; } + damage *= power; + if (isEmpty(coords[i].x,coords[i].y)) { + // create smoke or fire depending on the damage if empty + if (damage < 0.02) { } // do nothing + else if (damage < 0.2) { + createPixel("smoke",coords[i].x,coords[i].y); + } + else { + // if fire is an array, choose a random item + if (Array.isArray(fire)) { + createPixel(fire[Math.floor(Math.random() * fire.length)],coords[i].x,coords[i].y); + } + else { + createPixel(fire,coords[i].x,coords[i].y); + } + } + } + else if (!outOfBounds(coords[i].x,coords[i].y)) { + // damage the pixel + var pixel = pixelMap[coords[i].x][coords[i].y]; + var info = elements[pixel.element]; + if (info.hardness) { // lower damage depending on hardness(0-1) + if (info.hardness < 1) { + damage = damage * ((1 - info.hardness)*10); + } + else { damage = 0; } + } + if (damage > 0.9) { + if (Array.isArray(fire)) { + var newfire = fire[Math.floor(Math.random() * fire.length)]; + } + else { + var newfire = fire; + } + changePixel(pixel,newfire); + continue; + } + else if (damage > 0.25) { + if (info.breakInto) { + // if it is an array, choose a random item, else just use the value + if (Array.isArray(info.breakInto)) { + var result = info.breakInto[Math.floor(Math.random() * info.breakInto.length)]; + } + else { + var result = info.breakInto; + } + // change the pixel to the result + changePixel(pixel,result); + continue; + } + else { + if (Array.isArray(fire)) { + var newfire = fire[Math.floor(Math.random() * fire.length)]; + } + else { + var newfire = fire; + } + changePixel(pixel,newfire); + continue; + } + } + if (damage > 0.75 && info.burn) { + pixel.burning = true; + pixel.burnStart = pixelTicks; + } + pixel.temp += damage*radius*power; + pixelTempCheck(pixel); + // set the pixel.vx and pixel.vy depending on the angle and power + var angle = Math.atan2(pixel.y-y,pixel.x-x); + pixel.vx = Math.floor((pixel.vx|0) + Math.cos(angle) * (radius * power/10)); + pixel.vy = Math.floor((pixel.vy|0) + Math.sin(angle) * (radius * power/10)); + } + } +} \ No newline at end of file