sandboxels/mods/velocity.js

139 lines
5.5 KiB
JavaScript
Raw Normal View History

2022-09-13 18:11:22 -04:00
runAfterLoad(function(){
doVelocity = function(pixel) {
if ((pixel.vx||pixel.vy) && elements[pixel.element].movable) {
if (pixel.vx) {
// move the pixel vx times
for (var i = 0; i < Math.abs(pixel.vx); i++) {
var x = pixel.x+Math.sign(pixel.vx);
var y = pixel.y;
if (!tryMove(pixel,x,y)) {
if (!isEmpty(x,y,true)) {
var newPixel = pixelMap[x][y];
if (elements[newPixel.element].movable) {
newPixel.vx = (newPixel.vx||0) + pixel.vx - Math.sign(pixel.vx);
2022-09-13 18:35:34 -04:00
if (elements[pixel.element].breakInto && Math.random()<elements[pixel.element].breakIntoChance) {
changePixel(pixel,elements[pixel.element].breakInto);
}
2022-09-13 18:11:22 -04:00
}
}
pixel.vx = 0;
}
}
Sandboxels v1.9 [Version 1.9 - October 13, 2023 - Local Saves] + Local Saves + SAVES button + Save the scene to 1 of 12 slots + Save the scene to a file + Load a scene from a file + Saves include a ton of information, even your selected element! + Choose to include your settings or mods + Drag & Drop or Paste a save file + Pumpkin + Fireproof solid for carving activities + Pumpkin Seed + Will grow when planted on soil! ~ Thermal View now uses a more useful logarithmic scale [Changes] + Resetting now adjusts canvas size if needed + Dot appears in center of cursor + E-cloner can select an element while unpowered + E-cloner ignores Wires and E-walls + Grass can spread on Sand, Clay, and Mycelium + Tree roots can grow through Clay ~ Sap no longer mixes with Sawdust + Plant and Sauce remove Stench + Humans break Eggs, Grapes, and bugs when on top of them + Humans can trample Grass + Termites can eat Confetti, Straw, and Wheat + Fleas can eat Hair + Ants can eat Honey + Snails can eat Calcium, Limestone, and Paper + Worms can infect and swim in Blood + Worms are killed by Antibodies + Eggs die at high temperatures + Bugs will form Amber when touching Sap ~ Frogs and Fish burn slower + Uranium dirties Salt Water + Radiation can dirty Ice + Blood is infected by Rotten Meat and Rotten Cheese + Vinegar and Limestone reaction + Ketchup slowly deoxidizes Rust ~ Charcoal leaves behind Ash and less CO₂ ~ C4 no longer explodes when burnt + C4 releases poisonous fumes when burnt + C4 burns longer, can be used as fuel + C4 explodes when broken + Fireworks ignite at high temperatures + Dye dissolves in Pool Water + Ink slowly dissolves in Water + Honey dissolves in Tea + Molten Salt conducts electricity + Hair can be made by radiating Skin + Skin can absorb Soap + Proton and Electric reaction generates heat + Positron and Electric reaction generates Light + Escape key resets to Normal View ~ Recolored Tuff ~ Recolored Blood ~ Selected element outline is more clear ~ Improved button readability ~ Improved canvas pixel sharpness + Pressing - or + button centers the cursor ~ Step button is now an arrow + Clear Saves setting [Bug Fixes] ~ Fixed: Fireworks and Flash don't transfer heat ~ Fixed: Flash from Heat Ray is not hot ~ Fixed: Alcohol Gas density too high ~ Fixed: Pistil and Mushroom Gill can be dragged ~ Fixed: Herb can't be mixed in Batter or Dough ~ Fixed: Amber spawns at high temperature ~ Fixed: Heads can detach if Body moves during reaction ~ Fixed: Many Flour reactions make Gingerbread instead of Dough ~ Fixed: Ghost pixels when burning Plague, other deleting gases ~ Fixed: Color picker always appears when toggling GUI on (F1) ~ Fixed: Cooldowned elements can't be placed before 8th tick ~ Fixed: Frozen Fish break into Slime [Technical] + logMessage() function + SOIL eList + generateSave() and loadSave() functions + resizeCanvas() and autoResizeCanvas() functions + sb1 save format ~ Browser dark color scheme for UI elements ~ Light, Laser, etc. use bx/by instead of vx/vy (velocity.js fix)
2023-10-13 18:45:49 -04:00
if (pixel.vx) { pixel.vx = Math.floor(Math.abs(pixel.vx)/1.25)*Math.sign(pixel.vx) }
2022-09-13 18:11:22 -04:00
}
if (pixel.vy) {
// move the pixel vy times
for (var i = 0; i < Math.abs(pixel.vy); i++) {
var x = pixel.x;
var y = pixel.y+Math.sign(pixel.vy);
if (!tryMove(pixel,x,y)) {
if (!isEmpty(x,y,true)) {
var newPixel = pixelMap[x][y];
if (elements[newPixel.element].movable) {
newPixel.vy = (newPixel.vy||0) + pixel.vy - Math.sign(pixel.vy);
2022-09-13 18:35:34 -04:00
if (elements[pixel.element].breakInto && Math.random()<elements[pixel.element].breakIntoChance) {
changePixel(pixel,elements[pixel.element].breakInto);
}
2022-09-13 18:11:22 -04:00
}
}
pixel.vy = 0;
return;
}
}
Sandboxels v1.9 [Version 1.9 - October 13, 2023 - Local Saves] + Local Saves + SAVES button + Save the scene to 1 of 12 slots + Save the scene to a file + Load a scene from a file + Saves include a ton of information, even your selected element! + Choose to include your settings or mods + Drag & Drop or Paste a save file + Pumpkin + Fireproof solid for carving activities + Pumpkin Seed + Will grow when planted on soil! ~ Thermal View now uses a more useful logarithmic scale [Changes] + Resetting now adjusts canvas size if needed + Dot appears in center of cursor + E-cloner can select an element while unpowered + E-cloner ignores Wires and E-walls + Grass can spread on Sand, Clay, and Mycelium + Tree roots can grow through Clay ~ Sap no longer mixes with Sawdust + Plant and Sauce remove Stench + Humans break Eggs, Grapes, and bugs when on top of them + Humans can trample Grass + Termites can eat Confetti, Straw, and Wheat + Fleas can eat Hair + Ants can eat Honey + Snails can eat Calcium, Limestone, and Paper + Worms can infect and swim in Blood + Worms are killed by Antibodies + Eggs die at high temperatures + Bugs will form Amber when touching Sap ~ Frogs and Fish burn slower + Uranium dirties Salt Water + Radiation can dirty Ice + Blood is infected by Rotten Meat and Rotten Cheese + Vinegar and Limestone reaction + Ketchup slowly deoxidizes Rust ~ Charcoal leaves behind Ash and less CO₂ ~ C4 no longer explodes when burnt + C4 releases poisonous fumes when burnt + C4 burns longer, can be used as fuel + C4 explodes when broken + Fireworks ignite at high temperatures + Dye dissolves in Pool Water + Ink slowly dissolves in Water + Honey dissolves in Tea + Molten Salt conducts electricity + Hair can be made by radiating Skin + Skin can absorb Soap + Proton and Electric reaction generates heat + Positron and Electric reaction generates Light + Escape key resets to Normal View ~ Recolored Tuff ~ Recolored Blood ~ Selected element outline is more clear ~ Improved button readability ~ Improved canvas pixel sharpness + Pressing - or + button centers the cursor ~ Step button is now an arrow + Clear Saves setting [Bug Fixes] ~ Fixed: Fireworks and Flash don't transfer heat ~ Fixed: Flash from Heat Ray is not hot ~ Fixed: Alcohol Gas density too high ~ Fixed: Pistil and Mushroom Gill can be dragged ~ Fixed: Herb can't be mixed in Batter or Dough ~ Fixed: Amber spawns at high temperature ~ Fixed: Heads can detach if Body moves during reaction ~ Fixed: Many Flour reactions make Gingerbread instead of Dough ~ Fixed: Ghost pixels when burning Plague, other deleting gases ~ Fixed: Color picker always appears when toggling GUI on (F1) ~ Fixed: Cooldowned elements can't be placed before 8th tick ~ Fixed: Frozen Fish break into Slime [Technical] + logMessage() function + SOIL eList + generateSave() and loadSave() functions + resizeCanvas() and autoResizeCanvas() functions + sb1 save format ~ Browser dark color scheme for UI elements ~ Light, Laser, etc. use bx/by instead of vx/vy (velocity.js fix)
2023-10-13 18:45:49 -04:00
if (pixel.vy) { pixel.vy = Math.floor(Math.abs(pixel.vy)/1.25)*Math.sign(pixel.vy) }
2022-09-13 18:11:22 -04:00
}
}
}
2024-08-02 16:21:02 -04:00
runPerPixel(doVelocity);
2022-09-13 18:11:22 -04:00
2022-09-13 18:13:00 -04:00
})
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) {
2024-08-02 16:21:02 -04:00
// more hardness = less damage, logarithmic
damage *= Math.pow((1-info.hardness),info.hardness);
2022-09-13 18:13:00 -04:00
}
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) {
2023-10-14 20:28:27 -04:00
if (info.breakInto !== undefined) {
breakPixel(pixel);
2022-09-13 18:13:00 -04:00
continue;
}
2023-10-14 20:29:09 -04:00
else {
if (Array.isArray(fire)) {
var newfire = fire[Math.floor(Math.random() * fire.length)];
}
else {
var newfire = fire;
}
2024-08-02 16:21:02 -04:00
if (elements[pixel.element].onBreak !== undefined) {
elements[pixel.element].onBreak(pixel);
}
2023-10-14 20:29:09 -04:00
changePixel(pixel,newfire);
continue;
}
2022-09-13 18:13:00 -04:00
}
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
2022-09-13 18:18:37 -04:00
if (!elements[pixel.element].excludeRandom) {
var angle = Math.atan2(pixel.y-y,pixel.x-x);
2022-09-13 18:35:34 -04:00
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));
2022-09-13 18:18:37 -04:00
}
2022-09-13 18:13:00 -04:00
}
}
}