controllable_pixel_test.js but it can fuck shit up
This commit is contained in:
parent
e2555a9554
commit
4280079009
|
|
@ -0,0 +1,311 @@
|
|||
var modName = "mods/cpt_alt.js";
|
||||
var explodeAtPlusMod = "mods/explodeAtPlus.js";
|
||||
|
||||
if(enabledMods.includes(explodeAtPlusMod)) {
|
||||
function breakPixel(pixel,changetemp=false,defaultBreakIntoDust=false) {
|
||||
var info = elements[pixel.element];
|
||||
if(typeof(info.breakInto) === "undefined") {
|
||||
if(defaultBreakIntoDust) {
|
||||
if(Math.random() < defaultBreakIntoDust) { changePixel(pixel,"dust",changetemp) };
|
||||
};
|
||||
return defaultBreakIntoDust;
|
||||
};
|
||||
var breakIntoElement = info.breakInto;
|
||||
if(Array.isArray(breakIntoElement)) {
|
||||
breakIntoElement = breakIntoElement[Math.floor(Math.random() * breakIntoElement.length)]
|
||||
};
|
||||
changePixel(pixel,breakIntoElement,changetemp)
|
||||
return true;
|
||||
};
|
||||
|
||||
actExcludedElements = ["wall","alt_controllable_pixel"];
|
||||
|
||||
function breakCircle(x,y,radius,respectHardness=false,changeTemp=false,defaultBreakIntoDust=false) {
|
||||
var coords = circleCoords(x,y,radius);
|
||||
for(i = 0; i < coords.length; i++) {
|
||||
coordX = coords[i].x;
|
||||
coordY = coords[i].y;
|
||||
if(!isEmpty(coordX,coordY,true)) {
|
||||
var pixel = pixelMap[coordX][coordY];
|
||||
respectHardness ? tryBreak(pixel,changeTemp,defaultBreakIntoDust) : breakPixel(pixel,changeTemp,defaultBreakIntoDust);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
function tryBreak(pixel,changetemp=false,defaultBreakIntoDust=false) {
|
||||
var info = elements[pixel.element];
|
||||
var hardness = defaultHardness;
|
||||
if(typeof(info.hardness) === "number") {
|
||||
hardness = info.hardness;
|
||||
};
|
||||
hardness = 1 - hardness; //invert hardness, so a hardness of 0 becomes a 100% chance and a hardness of 1 becomes a 0% chance
|
||||
if(Math.random() < hardness) {
|
||||
return breakPixel(pixel,changetemp=false,defaultBreakIntoDust=false);
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
function fillCircle(element,x,y,radius,overwrite=false) {
|
||||
var coords = circleCoords(x,y,radius);
|
||||
var newElement = element;
|
||||
if(Array.isArray(newElement)) {
|
||||
newElement = newElement[Math.floor(Math.random() * newElement.length)];
|
||||
};
|
||||
for(i = 0; i < coords.length; i++) {
|
||||
coordX = coords[i].x;
|
||||
coordY = coords[i].y;
|
||||
if(overwrite && !isEmpty(coordX,coordY,true)) {
|
||||
changePixel(pixelMap[coordX][coordY],element);
|
||||
};
|
||||
if(isEmpty(coordX,coordY,false)) {
|
||||
createPixel(element,coordX,coordY);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
function actTryMove(pixel,x,y) {
|
||||
if(!tryMove(pixel,x,y)) {
|
||||
if(outOfBounds(x,y)) {
|
||||
return false;
|
||||
};
|
||||
if(!isEmpty(x,y,true)) {
|
||||
var newPixel = pixelMap[x][y];
|
||||
var newElement = newPixel.element;
|
||||
if(actExcludedElements.includes(newElement)) {
|
||||
return false;
|
||||
};
|
||||
if(newElement == pixel.element) { //Copy-paste of "break" code
|
||||
swapPixels(pixel,newPixel);
|
||||
return true;
|
||||
} else {
|
||||
breakCircle(newPixel.x,newPixel.y,pixel.breakAroundRadius,false,false,false); //does nothing to elements without breakIntos if defaultBreakIntoDust is false
|
||||
swapPixels(pixel,newPixel);
|
||||
return true;
|
||||
};
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
} else {
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
function cptaEapFunction(pixel,x,y,radius,fire,smoke,power,damage) {
|
||||
var coords = circleCoords(pixel.x,pixel.y,radius);
|
||||
for (var i = 0; i < coords.length; i++) {
|
||||
var x = coords[i].x;
|
||||
var y = coords[i].y;
|
||||
if(isEmpty(x,y)) { //if there's space for fire
|
||||
if (Array.isArray(fire)) { //this should remain "fire"
|
||||
var newfire = fire[Math.floor(Math.random() * fire.length)];
|
||||
} else {
|
||||
var newfire = fire;
|
||||
};
|
||||
createPixel(newfire,x,y); //add fire
|
||||
var firePixel = pixelMap[x][y];
|
||||
firePixel.temp = Math.max(elements[newfire].temp,firePixel.temp);
|
||||
firePixel.burning = true;
|
||||
};
|
||||
if(!isEmpty(x,y,true)) {
|
||||
pixel.temp += (400 * ((1 + (5 * damage)) ** 2) * ((power ** 1.5) * 1.5));
|
||||
pixelTempCheck(pixel);
|
||||
};
|
||||
if(enabledMods.includes("mods/velocity.js")) {
|
||||
if (!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));
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
alt_sussyKey = null;
|
||||
isShift = false;
|
||||
isAlt = false;
|
||||
|
||||
document.addEventListener("keydown", function(modifierDownListener) {
|
||||
// User presses shift
|
||||
if (modifierDownListener.keyCode == 16) {
|
||||
isShift = true;
|
||||
}
|
||||
// User presses alt
|
||||
if (modifierDownListener.keyCode == 18) {
|
||||
isAlt = true;
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("keyup", function(modifierUpListener) {
|
||||
// User releases shift
|
||||
if (modifierUpListener.keyCode == 16) {
|
||||
isShift = false;
|
||||
}
|
||||
// User releases alt
|
||||
if (modifierUpListener.keyCode == 18) {
|
||||
isAlt = false;
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("keyup", function(alt_sussyListener) {
|
||||
switch (alt_sussyListener.keyCode) {
|
||||
case 87:
|
||||
alt_sussyKey = "W";
|
||||
break;
|
||||
case 65:
|
||||
alt_sussyKey = "A";
|
||||
break;
|
||||
case 83:
|
||||
alt_sussyKey = "S";
|
||||
break;
|
||||
case 68:
|
||||
alt_sussyKey = "D";
|
||||
break;
|
||||
case 81:
|
||||
alt_sussyKey = "Q";
|
||||
break;
|
||||
case 88:
|
||||
alt_sussyKey = "X";
|
||||
break;
|
||||
case 90:
|
||||
alt_sussyKey = "Z";
|
||||
break;
|
||||
case 72:
|
||||
alt_sussyKey = "H";
|
||||
break;
|
||||
case 76:
|
||||
alt_sussyKey = "L";
|
||||
break;
|
||||
};
|
||||
});
|
||||
|
||||
function tryCreatePixel(_element,_x,_y) {
|
||||
if(!elements[_element]) {
|
||||
throw new Error("Element " + _element + " doesn't exist!");
|
||||
};
|
||||
if(isEmpty(_x,_y)) {
|
||||
createPixel(_element,_x,_y);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function controllablePixelTryCreatePixelNullCheck(_element,_x,_y) {
|
||||
if(!elements[_element]) { //catch the null
|
||||
return false;
|
||||
};
|
||||
if(isEmpty(_x,_y)) {
|
||||
tryCreatePixel(_element,_x,_y);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
elements.alt_controllable_pixel = {
|
||||
color: "#7F7F7F",
|
||||
colorOn: "#FFFF00",
|
||||
behavior: behaviors.WALL,
|
||||
state: "solid",
|
||||
density: 2000,
|
||||
maxSize: 1,
|
||||
conduct: 1,
|
||||
hardness: 1,
|
||||
movable: true,
|
||||
desc: "it breaks things more<br/>Use the console or enable prop.js to set speed / explosionRadius / circleRadius / breakAroundRadius (though it has an Illogical™ random resetting bug)",
|
||||
breakInto: "alt_controllable_pixel",
|
||||
properties: {
|
||||
speed: 1,
|
||||
explosionRadius: 8,
|
||||
circleRadius: 8,
|
||||
breakAroundRadius: 4,
|
||||
},
|
||||
excludeVelocity: true,
|
||||
tick: function(pixel) {
|
||||
userElement = currentElement;
|
||||
if(userElement === pixel.element) {
|
||||
userElement = null;
|
||||
};
|
||||
if(isShift && !isAlt) {
|
||||
alt_sussyKey === "Z" ? pixel.color = "rgb(255,191,127)" : pixel.color = "rgb(255,127,127)";
|
||||
}
|
||||
if(isAlt && !isShift) {
|
||||
alt_sussyKey === "Z" ? pixel.color = "rgb(191,255,127)" : pixel.color = "rgb(127,255,127)";
|
||||
}
|
||||
if(isAlt && isShift) {
|
||||
alt_sussyKey === "Z" ? pixel.color = "rgb(255,255,0)" : pixel.color = "rgb(255,255,127)";
|
||||
}
|
||||
if(!isAlt && !isShift) {
|
||||
alt_sussyKey === "Z" ? pixel.color = "rgb(255,255,191)" : pixel.color = "rgb(255,255,255)";
|
||||
}
|
||||
if(alt_sussyKey !== null) {
|
||||
switch (alt_sussyKey) {
|
||||
case "W":
|
||||
if(isAlt) { controllablePixelTryCreatePixelNullCheck(userElement,pixel.x,pixel.y-1) } else { for(move = 0; move < pixel.speed; move++) { actTryMove(pixel,pixel.x,pixel.y-1) } };
|
||||
if(!isShift) {
|
||||
alt_sussyKey = null;
|
||||
}
|
||||
break;
|
||||
case "A":
|
||||
if(isAlt) { controllablePixelTryCreatePixelNullCheck(userElement,pixel.x-1,pixel.y) } else { for(move = 0; move < pixel.speed; move++) { actTryMove(pixel,pixel.x-1,pixel.y) } };
|
||||
if(!isShift) {
|
||||
alt_sussyKey = null;
|
||||
}
|
||||
break;
|
||||
case "S":
|
||||
if(isAlt) { controllablePixelTryCreatePixelNullCheck(userElement,pixel.x,pixel.y+1) } else { for(move = 0; move < pixel.speed; move++) { actTryMove(pixel,pixel.x,pixel.y+1) } };
|
||||
if(!isShift) {
|
||||
alt_sussyKey = null;
|
||||
}
|
||||
break;
|
||||
case "D":
|
||||
for(move = 0; move < pixel.speed; move++) { actTryMove(pixel,pixel.x+1,pixel.y) };
|
||||
if(!isShift) {
|
||||
alt_sussyKey = null;
|
||||
}
|
||||
break;
|
||||
case "H": //Alt+D is something else in some browsers.
|
||||
if(isAlt) {
|
||||
controllablePixelTryCreatePixelNullCheck(userElement,pixel.x+1,pixel.y);
|
||||
};
|
||||
if(!isShift) {
|
||||
alt_sussyKey = null;
|
||||
}
|
||||
break;
|
||||
case "X":
|
||||
explodeAtPlus(pixel.x,pixel.y,pixel.explosionRadius,"plasma,fire,fire","fire,smoke,smoke",null,cptaEapFunction)
|
||||
if(!isShift) {
|
||||
alt_sussyKey = null;
|
||||
}
|
||||
break;
|
||||
case "Z":
|
||||
if (!pixel.charge && !pixel.chargeCD && !isEmpty(pixel.x,pixel.y,true)) {
|
||||
pixel.charge = 1;
|
||||
}
|
||||
if(!isShift === 0) {
|
||||
alt_sussyKey = null;
|
||||
}
|
||||
break;
|
||||
case "L":
|
||||
if(userElement !== null) {
|
||||
fillCircle(currentElement,pixel.x,pixel.y,pixel.circleRadius,false);
|
||||
if(!isShift === 0) {
|
||||
alt_sussyKey = null;
|
||||
}
|
||||
};
|
||||
break;
|
||||
case "Q": //Use if a key gets stuck
|
||||
alt_sussyKey = null;
|
||||
isShift = null;
|
||||
isAlt = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
} else {
|
||||
alert(`The ${explodeAtPlusMod} mod is required and has been automatically inserted (reload for this to take effect).`)
|
||||
enabledMods.splice(enabledMods.indexOf(modName),0,explodeAtPlusMod)
|
||||
localStorage.setItem("enabledMods", JSON.stringify(enabledMods));
|
||||
};
|
||||
Loading…
Reference in New Issue