diff --git a/archive.txt b/archive.txt new file mode 100644 index 00000000..deaef04e --- /dev/null +++ b/archive.txt @@ -0,0 +1,104 @@ +// If the element has reactions, loop through each one (it is an object), if the value for elem1 or elem2 is not an element and is not null, remove that key + if (elements[key].reactions) { + for (var reaction in elements[key].reactions) { + // If elem1 exists + if (elements[key].reactions[reaction].elem1) { + // If elem1 is an array, loop through each element, else check once. Don't delete if it === null + if (Array.isArray(elements[key].reactions[reaction].elem1)) { + for (var i = 0; i < elements[key].reactions[reaction].elem1.length; i++) { + if (elements[key].reactions[reaction].elem1[i] && !elements[elements[key].reactions[reaction].elem1[i]]) { + elements[key].reactions[reaction].elem1.splice(i,1); + } + } + } + else if (elements[key].reactions[reaction].elem1 && !elements[elements[key].reactions[reaction].elem1]) { + delete elements[key].reactions[reaction].elem1; + } + } + // If elem2 exists + if (elements[key].reactions[reaction].elem2) { + // If elem2 is an array, loop through each element, else check once. Don't delete if it === null + if (Array.isArray(elements[key].reactions[reaction].elem2)) { + for (var i = 0; i < elements[key].reactions[reaction].elem2.length; i++) { + if (elements[key].reactions[reaction].elem2[i] && !elements[elements[key].reactions[reaction].elem2[i]]) { + elements[key].reactions[reaction].elem2.splice(i,1); + } + } + } + else if (elements[key].reactions[reaction].elem2 && !elements[elements[key].reactions[reaction].elem2]) { + delete elements[key].reactions[reaction].elem2; + } + } + } + } + + // If the element's stateHigh or stateLow is not an element, remove it and tempHigh/Low + if (elements[key].stateHigh) { + // If it's an array, do it for each item, otherwise, just do it once + if (Array.isArray(elements[key].stateHigh)) { + for (var i = 0; i < elements[key].stateHigh.length; i++) { + if (!elements[elements[key].stateHigh[i]] && elements[key].stateHigh[i] !== null) { + elements[key].stateHigh.splice(i,1); + } + } + if (elements[key].stateHigh.length == 0) { + delete elements[key].stateHigh; + delete elements[key].tempHigh; + } + } + else { + if (!elements[elements[key].stateHigh] && elements[key].stateHigh !== null) { + delete elements[key].stateHigh; + delete elements[key].tempHigh; + } + } + } + if (elements[key].stateLow) { + if (Array.isArray(elements[key].stateLow)) { + for (var i = 0; i < elements[key].stateLow.length; i++) { + if (!elements[elements[key].stateLow[i]] && elements[key].stateLow[i] !== null) { + elements[key].stateLow.splice(i,1); + } + } + if (elements[key].stateLow.length == 0) { + delete elements[key].stateLow; + delete elements[key].tempLow; + } + } + else { + if (!elements[elements[key].stateLow] && elements[key].stateLow !== null) { + delete elements[key].stateLow; + delete elements[key].tempLow; + } + } + } + // same for burnInto + if (elements[key].burnInto) { + if (Array.isArray(elements[key].burnInto)) { + for (var i = 0; i < elements[key].burnInto.length; i++) { + if (!elements[elements[key].burnInto[i]]) { + delete elements[key].burnInto[i]; + } + } + if (elements[key].burnInto.length == 0) { + delete elements[key].burnInto; + } + } + else { + if (!elements[elements[key].burnInto]) { + delete elements[key].burnInto; + } + } + } + // same for breakInto + if (elements[key].breakInto) { + if (Array.isArray(elements[key].breakInto)) { + for (var i = 0; i < elements[key].breakInto.length; i++) { + if (elements[key].breakInto[i]!==null && !elements[elements[key].breakInto[i]]) { delete elements[key].breakInto[i]; } + } + if (elements[key].breakInto.length == 0) { delete elements[key].breakInto; } + } + else { + if (elements[key].breakInto[i]!==null && !elements[elements[key].breakInto]) { delete elements[key].breakInto; } + } + } \ No newline at end of file diff --git a/gravity.js b/gravity.js new file mode 100644 index 00000000..da48e66c --- /dev/null +++ b/gravity.js @@ -0,0 +1,40 @@ +elements.gravity_point = { + color: "#FFD700", // Goudkleurig + behavior: behaviors.STURDYPOWDER, + category: "special", + state: "solid", + density: 5000, + max_gravity_distance: 100, // Bereik van zwaartekracht + gravity_strength: 1, // Kracht van zwaartekracht + + tick: function(pixel) { + for (var x = -pixel.max_gravity_distance; x <= pixel.max_gravity_distance; x++) { + for (var y = -pixel.max_gravity_distance; y <= pixel.max_gravity_distance; y++) { + var nx = pixel.x + x; + var ny = pixel.y + y; + + if (!isEmpty(nx, ny, true)) { + var npixel = pixelMap[nx][ny]; + + if (npixel && npixel.element !== "gravity_point") { + var dx = nx - pixel.x; + var dy = ny - pixel.y; + var distance = Math.sqrt(dx * dx + dy * dy); + + if (distance < 1) distance = 1; // Voorkom delen door 0 + if (distance <= pixel.max_gravity_distance) { + var force = (pixel.gravity_strength * 100) / (distance * distance); + var angle = Math.atan2(dy, dx); + var vx = -Math.cos(angle) * force; + var vy = -Math.sin(angle) * force; + + // Voeg snelheid toe aan objecten + npixel.vx = (npixel.vx || 0) + vx; + npixel.vy = (npixel.vy || 0) + vy; + } + } + } + } + } + } +}; diff --git a/index.html b/index.html index 85ea282e..64be082e 100644 --- a/index.html +++ b/index.html @@ -17970,111 +17970,6 @@ function finalizeElementAfter(key) { } } - // If the element has reactions, loop through each one (it is an object), if the value for elem1 or elem2 is not an element and is not null, remove that key - if (elements[key].reactions) { - for (var reaction in elements[key].reactions) { - // If elem1 exists - if (elements[key].reactions[reaction].elem1) { - // If elem1 is an array, loop through each element, else check once. Don't delete if it === null - if (Array.isArray(elements[key].reactions[reaction].elem1)) { - for (var i = 0; i < elements[key].reactions[reaction].elem1.length; i++) { - if (elements[key].reactions[reaction].elem1[i] && !elements[elements[key].reactions[reaction].elem1[i]]) { - elements[key].reactions[reaction].elem1.splice(i,1); - } - } - } - else if (elements[key].reactions[reaction].elem1 && !elements[elements[key].reactions[reaction].elem1]) { - delete elements[key].reactions[reaction].elem1; - } - } - // If elem2 exists - if (elements[key].reactions[reaction].elem2) { - // If elem2 is an array, loop through each element, else check once. Don't delete if it === null - if (Array.isArray(elements[key].reactions[reaction].elem2)) { - for (var i = 0; i < elements[key].reactions[reaction].elem2.length; i++) { - if (elements[key].reactions[reaction].elem2[i] && !elements[elements[key].reactions[reaction].elem2[i]]) { - elements[key].reactions[reaction].elem2.splice(i,1); - } - } - } - else if (elements[key].reactions[reaction].elem2 && !elements[elements[key].reactions[reaction].elem2]) { - delete elements[key].reactions[reaction].elem2; - } - } - } - } - - // If the element's stateHigh or stateLow is not an element, remove it and tempHigh/Low - if (elements[key].stateHigh) { - // If it's an array, do it for each item, otherwise, just do it once - if (Array.isArray(elements[key].stateHigh)) { - for (var i = 0; i < elements[key].stateHigh.length; i++) { - if (!elements[elements[key].stateHigh[i]] && elements[key].stateHigh[i] !== null) { - elements[key].stateHigh.splice(i,1); - } - } - if (elements[key].stateHigh.length == 0) { - delete elements[key].stateHigh; - delete elements[key].tempHigh; - } - } - else { - if (!elements[elements[key].stateHigh] && elements[key].stateHigh !== null) { - delete elements[key].stateHigh; - delete elements[key].tempHigh; - } - } - } - if (elements[key].stateLow) { - if (Array.isArray(elements[key].stateLow)) { - for (var i = 0; i < elements[key].stateLow.length; i++) { - if (!elements[elements[key].stateLow[i]] && elements[key].stateLow[i] !== null) { - elements[key].stateLow.splice(i,1); - } - } - if (elements[key].stateLow.length == 0) { - delete elements[key].stateLow; - delete elements[key].tempLow; - } - } - else { - if (!elements[elements[key].stateLow] && elements[key].stateLow !== null) { - delete elements[key].stateLow; - delete elements[key].tempLow; - } - } - } - // same for burnInto - if (elements[key].burnInto) { - if (Array.isArray(elements[key].burnInto)) { - for (var i = 0; i < elements[key].burnInto.length; i++) { - if (!elements[elements[key].burnInto[i]]) { - delete elements[key].burnInto[i]; - } - } - if (elements[key].burnInto.length == 0) { - delete elements[key].burnInto; - } - } - else { - if (!elements[elements[key].burnInto]) { - delete elements[key].burnInto; - } - } - } - // same for breakInto - if (elements[key].breakInto) { - if (Array.isArray(elements[key].breakInto)) { - for (var i = 0; i < elements[key].breakInto.length; i++) { - if (elements[key].breakInto[i]!==null && !elements[elements[key].breakInto[i]]) { delete elements[key].breakInto[i]; } - } - if (elements[key].breakInto.length == 0) { delete elements[key].breakInto; } - } - else { - if (elements[key].breakInto[i]!==null && !elements[elements[key].breakInto]) { delete elements[key].breakInto; } - } - } - if (elements[key].colorPattern) { if (!elements[key].colorKey) { delete elements[key].colorPattern; diff --git a/mod-list.html b/mod-list.html index 96137945..c41e32cc 100644 --- a/mod-list.html +++ b/mod-list.html @@ -160,6 +160,7 @@ extra_element_info.jsAdds descriptions to various vanilla elements. Used to provide the functionality that desc now does before it was added to vanillaMelecie extrasaveslots.jsAdds extra saves slots !SAVE IMPORTANT SAVES AS FILES!Jayd find.jsAdds a find mode that highlights a chosen element as pulsating red and yellow (read commit description)Alice +hideandshowtools.jsAdds two tools, one that hides elements, and one that shows hidden elementsMicaelNotUsed human_friendly_design.jsMakes the drag and mix tools not kill humans.Nekonico insane_random_events.jsMassively buffs random eventsAlice jaydsfunctions.jsAdds extra toolsJayd diff --git a/mods/cookie_clicker.js b/mods/cookie_clicker.js new file mode 100644 index 00000000..6e2e8b12 --- /dev/null +++ b/mods/cookie_clicker.js @@ -0,0 +1,943 @@ +// by Nekonico + +elements.cookie_dough = { + color: ["#bfac91","#CDBFAB",], + behavior: behaviors.STURDYPOWDER, + reactions: { + "chocolate": { elem1:"chocolate_chip_cookie_dough", elem2:null, chance: 0.5 }, + "chocolate_powder": { elem1:"chocolate_chip_cookie_dough", elem2:null, chance: 0.5 }, + }, + category: "food", + tempHigh: 74, + stateHigh: "plain_cookie", + burn:40, + burnTime:25, + burnInto:"ash", + state: "solid", + density: 526.9, + isFood: true, + cookievalue: 0.5 +} + +elements.chocolate_chip_cookie_dough = { + color: ["#bfac91","#CDBFAB","#bfac91","#CDBFAB","#bfac91","#CDBFAB","#bfac91","#CDBFAB","#bfac91","#CDBFAB","#4d2818","#3b1b0d","#33160a"], + behavior: behaviors.STURDYPOWDER, + category: "food", + tempHigh: 74, + stateHigh: "cookie", + burn:40, + burnTime:25, + burnInto:"ash", + state: "solid", + density: 526.9, + isFood: true, + cookievalue: 0.5 +} + +clicked = false +shopclicked = false +cookies = 0 +oldcookies = 0 +createdcookies = 0 +/* +CpS = 0 +mouseEff = 1 */ +buildings = { "cursors": [0,15,15], "grandmas": [0,100,100], "farms": [0,1100,1100], } +shopitem = "cursors" +/* +shopupgrade = 0 +boughtUpgrades = { "cursors": [], "grandmas": [], "farms": [], } */ +cursorCount = [] +grandmaCount = [] +farmCount = [] +cursorprice = buildings.cursors[1] +grandmaprice = buildings.grandmas[1] +farmprice = buildings.farms[1] + + +elements.plain_cookie = { + color: ["#C4966C","#C0946B"], + behavior: behaviors.POWDER, + reactions: { + "chocolate": { elem1:"cookie", elem2:null, chance: 0.25 }, + "chocolate_powder": { elem1:"cookie", elem2:null, chance: 0.25 }, + }, + tempHigh: 192, + stateHigh: "toast", + category: "food", + burn: 10, + burnTime: 200, + burnInto: "toast", + breakInto: "crumb", + breakIntoColor: ["#c8946a","#c08655","#ba7a45","#a86d3e"], + state: "solid", + density: 233.96, + isFood: true, + cookievalue: 1 +} + +elements.cookie = { + color: ["#C4966C","#C0946B","#C4966C","#C0946B","#C4966C","#C0946B","#C4966C","#C0946B","#C4966C","#C0946B","#4d2818","#3b1b0d","#33160a"], + behavior: behaviors.POWDER, + tick: function(pixel) { + var top = mousePos.y - Math.floor(mouseSize/2); + var bottom = mousePos.y + Math.floor(mouseSize/2); + var left = mousePos.x - Math.floor(mouseSize/2); + var right = mousePos.x + Math.floor(mouseSize/2); + if ((pixel.x >= left && pixel.x <= right && pixel.y >= top && pixel.y <= bottom) && mouseIsDown === true && clicked === false) { + clicked = true + cookies += 1 + } + else if ((pixel.x >= left && pixel.x <= right && pixel.y >= top && pixel.y <= bottom) && mouseIsDown !== true && clicked === true) { + clicked = false + } + doDefaults(pixel); + }, + tempHigh: 95, + stateHigh: ["melted_chocolate","plain_cookie","plain_cookie"], + category: "food", + burn: 10, + burnTime: 200, + burnInto: ["melted_chocolate","plain_cookie","plain_cookie"], + breakInto: ["crumb","crumb","crumb","crumb","crumb","chocolate","chocolate_powder"], + breakIntoColor: ["#bfac91","#CDBFAB","#bfac91","#CDBFAB","#bfac91","#CDBFAB","#bfac91","#CDBFAB","#bfac91","#CDBFAB","#4d2818","#3b1b0d","#33160a"], + state: "solid", + density: 233.96, + isFood: true, + cookievalue: 1 +} + +elements.the_cookie = { + color: ["#C4966C","#C0946B","#C4966C","#C0946B","#C4966C","#C0946B","#C4966C","#C0946B","#C4966C","#C0946B","#4d2818","#3b1b0d","#33160a"], + colorKey: { + "l": "#C4966C", + "r": "#C0946B", + "d": "#4d2818", + "w": "#3b1b0d", + "b": "#33160a", + }, + colorPattern: [ + "rlrlrlrlrlrlrlrlrlr", + "rlrlrlrlrlrlrlrlrlr", + "rlrldlrlrlrlrlrlrlr", + "rlrlrwblrlrlrlrlrlr", + "rlrlrlrlrlrlwbrlrlr", + "rlrlddwlrlrlddwlrlr", + "rlrlwddbrlrbrlrlrlr", + "rlrldbdwrlrlrlrlrlr", + "rlrlrdwrrlrlrlrlrlr", + "rlrlrlrlrlrlrlblrlr", + "rlwlrlrlrlrlwdwlrlr", + "rlrlwlrlrlrlrlrlrlr", + "rlbwblrlrlrlrlrlrlr", + "rldlblrlrlrlrlrlrlr", + "rlrlrlrlbwrlrlrlrlr", + "rlrlrlrlwbdlrlrlrlr", + "rlrlrlrlrdrlrlrlrlr", + "rlrlrlrlrlrlrlrlrlr", + "rlrlrlrlrlrlrlrlrlr", + ], + behavior: behaviors.WALL, + tick: function(pixel) { + var top = mousePos.y - Math.floor(mouseSize/2); + var bottom = mousePos.y + Math.floor(mouseSize/2); + var left = mousePos.x - Math.floor(mouseSize/2); + var right = mousePos.x + Math.floor(mouseSize/2); + if ((pixel.x >= left && pixel.x <= right && pixel.y >= top && pixel.y <= bottom) && mouseIsDown === true && clicked === false) { + clicked = true + cookies += 1 + } + else if ((pixel.x >= left && pixel.x <= right && pixel.y >= top && pixel.y <= bottom) && mouseIsDown !== true && clicked === true) { + clicked = false + } + doDefaults(pixel); + }, + tempHigh: 95, + stateHigh: ["melted_chocolate","plain_cookie","plain_cookie"], + category: "clicker", + burn: 10, + burnTime: 200, + burnInto: ["melted_chocolate","plain_cookie","plain_cookie"], + breakInto: ["crumb","crumb","crumb","crumb","crumb","chocolate","chocolate_powder"], + breakIntoColor: ["#bfac91","#CDBFAB","#bfac91","#CDBFAB","#bfac91","#CDBFAB","#bfac91","#CDBFAB","#bfac91","#CDBFAB","#4d2818","#3b1b0d","#33160a"], + state: "solid", + density: 233.96, + isFood: true, + movable: false, +} + /* +elements.upgrade_shop = { + color: "#9C998B", + behavior: behaviors.WALL, + onSelect: function() { + var answer5 = prompt("Input the desired upgrade of this shop. It will not work if you place multiple upgrade shops while paused.",(shopupgrade||"cursors")); + if (!answer5) { return } + shopupgrade = (answer5); + var answer4 = prompt("Input the desired item of this shop. It will not work if you place multiple shop items while paused.",(shopitem||"cursors")); + if (!answer4) { return } + shopitem = (answer4); + }, + tick: function(pixel) { + if (pixel.start < pixelTicks && !pixel.upgrade) { + pixel.upgrade = shopupgrade + } + if (pixel.start < pixelTicks && !pixel.item) { + pixel.item = shopitem + } + if (boughtUpgrades[pixel.item].indexOf(pixel.upgrade) !== -1 && pixel.upgrade <= 3) { + pixel.upgrade += 1 + } + if ((cursorprice != buildings.cursors[1] || !cursorprice) || (grandmaprice != buildings.grandmas[1] || !grandmaprice) || (farmprice != buildings.farms[1])) { + cursorprice = Math.floor(buildings.cursors[1]) + grandmaprice = Math.floor(buildings.grandmas[1]) + farmprice = Math.floor(buildings.farms[1]) + } + var top = mousePos.y - Math.floor(mouseSize/2); + var bottom = mousePos.y + Math.floor(mouseSize/2); + var left = mousePos.x - Math.floor(mouseSize/2); + var right = mousePos.x + Math.floor(mouseSize/2); + if ((pixel.x >= left && pixel.x <= right && pixel.y >= top && pixel.y <= bottom) && mouseIsDown === true && shopclicked === false && cookies >= (Math.floor(buildings[pixel.item][1]))) { + shopclicked = true + buildings[pixel.item][0] += 1 + cookies -= (Math.round(buildings[pixel.item][1])) + buildings[pixel.item][1] = (buildings[pixel.item][2] * (1.15 ** buildings[pixel.item][0])) + } + else if ((pixel.x >= left && pixel.x <= right && pixel.y >= top && pixel.y <= bottom) && mouseIsDown === true && shopclicked === false) { + shopclicked = true + } + else if ((pixel.x >= left && pixel.x <= right && pixel.y >= top && pixel.y <= bottom) && mouseIsDown !== true && shopclicked === true) { + shopclicked = false + } + doDefaults(pixel); + }, + tempHigh: 95, + stateHigh: ["melted_chocolate","plain_cookie","plain_cookie"], + category: "clicker", + burn: 10, + burnTime: 200, + burnInto: ["melted_chocolate","plain_cookie","plain_cookie"], + breakInto: ["crumb","crumb","crumb","crumb","crumb","chocolate","chocolate_powder"], + breakIntoColor: ["#bfac91","#CDBFAB","#bfac91","#CDBFAB","#bfac91","#CDBFAB","#bfac91","#CDBFAB","#bfac91","#CDBFAB","#4d2818","#3b1b0d","#33160a"], + state: "solid", + density: 233.96, + isFood: true, + movable: false, +} */ + +elements.shop = { + color: "#9C998B", + behavior: behaviors.WALL, + onSelect: function() { + var answer5 = prompt("Input the desired item of this shop. It will not work if you place multiple shop items while paused.",(shopitem||"cursors")); + if (!answer5) { return } + shopitem = (answer5); + }, + tick: function(pixel) { + if (pixel.start < pixelTicks && !pixel.item) { + pixel.item = shopitem + } + if ((cursorprice != buildings.cursors[1] || !cursorprice) || (grandmaprice != buildings.grandmas[1] || !grandmaprice) || (farmprice != buildings.farms[1])) { + cursorprice = Math.floor(buildings.cursors[1]) + grandmaprice = Math.floor(buildings.grandmas[1]) + farmprice = Math.floor(buildings.farms[1]) + } + var top = mousePos.y - Math.floor(mouseSize/2); + var bottom = mousePos.y + Math.floor(mouseSize/2); + var left = mousePos.x - Math.floor(mouseSize/2); + var right = mousePos.x + Math.floor(mouseSize/2); + if ((pixel.x >= left && pixel.x <= right && pixel.y >= top && pixel.y <= bottom) && mouseIsDown === true && shopclicked === false && cookies >= (Math.floor(buildings[pixel.item][1]))) { + shopclicked = true + buildings[pixel.item][0] += 1 + cookies -= (Math.round(buildings[pixel.item][1])) + buildings[pixel.item][1] = (buildings[pixel.item][2] * (1.15 ** buildings[pixel.item][0])) + } + else if ((pixel.x >= left && pixel.x <= right && pixel.y >= top && pixel.y <= bottom) && mouseIsDown === true && shopclicked === false) { + shopclicked = true + } + else if ((pixel.x >= left && pixel.x <= right && pixel.y >= top && pixel.y <= bottom) && mouseIsDown !== true && shopclicked === true) { + shopclicked = false + } + doDefaults(pixel); + }, + tempHigh: 95, + stateHigh: ["melted_chocolate","plain_cookie","plain_cookie"], + category: "clicker", + burn: 10, + burnTime: 200, + burnInto: ["melted_chocolate","plain_cookie","plain_cookie"], + breakInto: ["crumb","crumb","crumb","crumb","crumb","chocolate","chocolate_powder"], + breakIntoColor: ["#bfac91","#CDBFAB","#bfac91","#CDBFAB","#bfac91","#CDBFAB","#bfac91","#CDBFAB","#bfac91","#CDBFAB","#4d2818","#3b1b0d","#33160a"], + state: "solid", + density: 233.96, + isFood: true, + movable: false, +} + +elements.cookie_maker = { + color: ["#60a2c3","#2e80a9"], + colorKey: { + "l": "#60a2c3", + "r": "#2e80a9", + }, + colorPattern: [ + "rrrlll", + ], + behavior: behaviors.WALL, + tick: function(pixel) { + if (cookies > 0 && oldcookies < cookies) { + createdcookies = (cookies - oldcookies) + oldcookies = cookies + } + else if (oldcookies > cookies) { + oldcookies = cookies + } + if (isEmpty(pixel.x,pixel.y+1) && Math.random() > 0.75 && createdcookies > 0) { + createdcookies -= 1 + createPixel("cookie", pixel.x, pixel.y+1) + } + }, + category: "clicker", + state: "solid", + density: 2000, + movable: false, +} + +elements.cursor = { + color: ["#60a2c3","#2e80a9"], + colorKey: { + "l": "#60a2c3", + "r": "#2e80a9", + }, + colorPattern: [ + "rrrlll", + ], + behavior: behaviors.WALL, + onPlace: function(pixel) { + cursorCount.push(pixel) + for (c = 0; c < cursorCount.length; c++) { + if (cursorCount[c] == pixel) { + pixel.cursorbuy = c + break; + } + } + }, + tick: function(pixel) { + pixel.PixelTicks = pixelTicks + if (buildings.cursors[0] > pixel.cursorbuy) { + pixel.bought = true + } + if (pixel.bought === true) { + if (pixel.click > 0) { + pixel.click-- + } + if ((pixel.PixelTicks - (pixel.cursorbuy * 1.5)) % 300 == 0) { + cookies += 1 + pixel.color = "#aaaaaa" + pixel.click = 4 + } + if ((!pixel.click || pixel.click === 0) && pixel.PixelTicks % 300 != 0 && pixel.PixelPreTicks % 300 != 0 && pixel.color != "#ffffff") { + pixel.color = "#ffffff" + } + if (pixel.cursorbuy === 143 && buildings.cursors[0] > 143) { + if ((pixel.PixelTicks - (pixel.cursorbuy * 1.5)) % 300 == 0) { + cookies += (buildings.cursors[0] - 143) + } + } + } + }, + movable: false, + tempHigh: 220, + stateHigh: "cooked_meat", + category: "clicker", + state: "solid", + density: 1080, + hardness: 0.1, + breakInto: "meat" +}, + +elements.grandma = { + color: "#ffdbac", + category: "clicker", + properties: { + dead: false, + dir: 1, + }, + related: ["granbody","granhead"], + cooldown: defaultCooldown, + forceSaveColor: true, + tick: function(pixel) { + if (isEmpty(pixel.x, pixel.y+1)) { + createPixel("granbody", pixel.x, pixel.y+1); + var color = pixel.color; + changePixel(pixel,"granhead"); + pixel.color = color; + if (pixel.bodyColor) { + pixelMap[pixel.x][pixel.y+1].color = pixel.bodyColor; + } + } + else if (isEmpty(pixel.x, pixel.y-1)) { + createPixel("granhead", pixel.x, pixel.y-1); + pixelMap[pixel.x][pixel.y-1].color = pixel.color; + changePixel(pixel,"granbody"); + if (pixel.bodyColor) { + pixel.color = pixel.bodyColor; + } + } + } +} + +elements.granhead = { + color: "#ffdbac", + category: "clicker", + hidden: true, + density: 1080, + state: "solid", + conduct: .05, + temp: 37, + tempHigh: 150, + stateHigh: "cookie", + tempLow: -30, + stateLow: "frozen_meat", + burn: 10, + burnTime: 250, + burnInto: "cookie", + breakInto: ["cookie_dough","meat","bone"], + forceSaveColor: true, + reactions: { + "cancer": { elem1:"cancer", chance:0.005 }, + "radiation": { elem1:["ash","meat","rotten_meat","cooked_meat"], chance:0.4 }, + "neutron": { elem1:["ash","meat","rotten_meat","cooked_meat"], chance:0.03 }, + "fallout": { elem1:["ash","meat","rotten_meat","cooked_meat"], chance:0.03 }, + "plague": { elem1:"plague", chance:0.05 }, + "oxygen": { elem2:"carbon_dioxide", chance:0.5 }, + "beans": { elem2:[null,null,null,null,null,null,null,null,"stench"], chance:0.2 }, + "sun": { elem1:"cooked_meat" }, + "light": { stain1:"#825043" }, + "bee": { stain1:"#cc564b", chance:0.2 }, + "water": { elem2:"bubble", attr2:{"clone":"water"}, chance:0.001 }, + "salt_water": { elem2:"bubble", attr2:{"clone":"salt_water"}, chance:0.001 }, + "pool_water": { elem2:"bubble", attr2:{"clone":"pool_water"}, chance:0.001 }, + "alcohol": { chance:0.2, attr1:{"panic":0} }, + }, + properties: { + dead: false + }, + tick: function(pixel) { + doHeat(pixel); + doBurning(pixel); + doElectricity(pixel); + if (pixel.dead) { + // Turn into rotten_meat if pixelTicks-dead > 500 + if (pixelTicks-pixel.dead > 200 && Math.random() < 0.1) { + changePixel(pixel,"meat"); + return + } + } + + // Find the body + if (!isEmpty(pixel.x, pixel.y+1, true) && pixelMap[pixel.x][pixel.y+1].element == "granbody") { + var body = pixelMap[pixel.x][pixel.y+1]; + if (body.dead) { // If body is dead, kill head + pixel.dead = body.dead; + } + } + else { var body = null } + + if (tryMove(pixel, pixel.x, pixel.y+1)) { + // create blood if severed 10% chance + if (isEmpty(pixel.x, pixel.y+1) && !pixel.dead && Math.random() < 0.1 && !pixel.charge) { + createPixel("cookie_dough", pixel.x, pixel.y+1); + // set dead to true 15% chance + if (Math.random() < 0.15) { + pixel.dead = pixelTicks; + } + } + } + // homeostasis + if (pixel.temp > 37) { pixel.temp -= 1; } + else if (pixel.temp < 37) { pixel.temp += 1; } + }, + onChange: function(pixel) { + for (var i = 0; i < adjacentCoords.length; i++) { + var coord = adjacentCoords[i]; + var x = pixel.x+coord[0]; + var y = pixel.y+coord[1]; + if (!isEmpty(x,y,true) && pixelMap[x][y].panic !== undefined) { + pixelMap[x][y].panic += 20; + } + } + }, + onDelete: function(pixel) { + for (var i = 0; i < adjacentCoords.length; i++) { + var coord = adjacentCoords[i]; + var x = pixel.x+coord[0]; + var y = pixel.y+coord[1]; + if (!isEmpty(x,y,true) && pixelMap[x][y].panic !== undefined) { + pixelMap[x][y].panic += 20; + } + } + } +} + +elements.granbody = { + color: "#b6effb", + category: "clicker", + hidden: true, + density: 1500, + state: "solid", + conduct: .05, + temp: 37, + tempHigh: 150, + stateHigh: "cookie", + tempLow: -30, + stateLow: "frozen_meat", + burn: 10, + burnTime: 250, + burnInto: "cookie", + breakInto: ["cookie_dough","meat","bone"], + forceSaveColor: true, + properties: { + dead: false, + dir: 1, + }, + tick: function(pixel) { + if (tryMove(pixel, pixel.x, pixel.y+1)) { // Fall + if (!isEmpty(pixel.x, pixel.y-2, true)) { // Drag head down + var headpixel = pixelMap[pixel.x][pixel.y-2]; + if (headpixel.element === "granhead") { + if (isEmpty(pixel.x, pixel.y-1)) { + movePixel(pixelMap[pixel.x][pixel.y-2], pixel.x, pixel.y-1); + } + else { + swapPixels(pixelMap[pixel.x][pixel.y-2], pixelMap[pixel.x][pixel.y-1]); + } + } + } + } + doHeat(pixel); + doBurning(pixel); + doElectricity(pixel); + if (pixel.dead) { + // Turn into rotten_meat if pixelTicks-dead > 500 + if (pixelTicks-pixel.dead > 200 && Math.random() < 0.1) { + changePixel(pixel,"meat"); + } + return + } + + // Find the head + if (!isEmpty(pixel.x, pixel.y-1, true) && pixelMap[pixel.x][pixel.y-1].element == "granhead") { + var head = pixelMap[pixel.x][pixel.y-1]; + if (head.dead) { // If head is dead, kill body + pixel.dead = head.dead; + } + else if (head.panic > 0) { + delete head.panic; + } + } + else { var head = null } + if (pixel.panic > 0) { + pixel.panic -= 0.1; + if (pixel.panic < 0) { pixel.panic = 0; } + else if (pixel.panic > 1) { pixel.panic = 1; } + } + + if (isEmpty(pixel.x, pixel.y-1)) { + // create blood if decapitated 10% chance + if (Math.random() < 0.1 && !pixel.charge) { + createPixel("cookie_dough", pixel.x, pixel.y-1); + // set dead to true 15% chance + if (Math.random() < 0.15) { + pixel.dead = pixelTicks; + } + } + } + else if (head === null) { return } + else if (Math.random() < 0.1*(isEmpty(pixel.x, pixel.y+1) ? 1 : 1)) { // Move 10% chance + var movesToTry = [ + [1*pixel.dir,0], + [1*pixel.dir,-1], + ]; + let moved = false; + // While movesToTry is not empty, tryMove(pixel, x, y) with a random move, then remove it. if tryMove returns true, break. + while (movesToTry.length > 0) { + var move = movesToTry.splice(Math.floor(Math.random() * movesToTry.length), 1)[0]; + if (isEmpty(pixel.x+move[0], pixel.y+move[1]-1)) { + var origx = pixel.x+move[0]; + var origy = pixel.y+move[1]; + if (tryMove(pixel, pixel.x+move[0], pixel.y+move[1]) && pixel.x===origx && pixel.y===origy) { + movePixel(head, head.x+move[0], head.y+move[1]); + moved = true; + break; + } + } + } + // 15% chance to change direction + if (Math.random() < 0.15 || !moved) { + pixel.dir *= -1; + } + // homeostasis + if (pixel.temp > 37) { pixel.temp -= 1; } + else if (pixel.temp < 37) { pixel.temp += 1; } + } + pixel.PixelTicks = pixelTicks + if (pixel.PixelTicks % 30 == 0 && pixel.dead === false) { + cookies += 1 + } + } +} + +elements.grandma_maker = { + color: "#a0522d", + behavior: behaviors.WALL, + onPlace: function(pixel) { + grandmaCount.push(pixel) + for (g = 0; g < grandmaCount.length; g++) { + if (grandmaCount[g] == pixel) { + pixel.grandmalevel = g + break; + } + } + }, + tick: function(pixel) { + if (buildings.grandmas[0] > pixel.grandmalevel && isEmpty(pixel.x,pixel.y+1) && Math.random() > 0.5 && pixel.created !== true) { + pixel.created = true + createPixel("grandma", pixel.x, pixel.y+1) + } + }, + category: "clicker", + state: "solid", + density: 2000, + movable: false, +} + +elements.cookie_crop = { + color: "#C4966C", + behavior: behaviors.WALL, + tick: function(pixel) { + pixel.PixelTicks = pixelTicks + if (pixel.h === undefined) { + pixel.h = 0 + } + if (pixel.h < 2) { + if (!tryMove(pixel,pixel.x,pixel.y+1)) { + if (pixel.temp < 100) { + if (isEmpty(pixel.x,pixel.y-1) && tryMove(pixel,pixel.x,pixel.y-1)) { + createPixel("cookie_crop",pixel.x,pixel.y+1); + pixelMap[pixel.x][pixel.y+1].h = 4 + pixel.h++ + } + } + } + } + if (pixel.h === 2) { + if (pixel.temp < 100) { + if (isEmpty(pixel.x+1,pixel.y) && pixel.leftPetal !== true) { + createPixel("cookie_crop",pixel.x+1,pixel.y); + pixelMap[pixel.x+1][pixel.y].h = 4 + pixelMap[pixel.x+1][pixel.y].color = "#942e8c" + pixel.leftPetal = true + } + if (isEmpty(pixel.x-1,pixel.y) && pixel.rightPetal !== true) { + createPixel("cookie_crop",pixel.x-1,pixel.y); + pixelMap[pixel.x-1][pixel.y].h = 4 + pixelMap[pixel.x-1][pixel.y].color = "#942e8c" + pixel.rightPetal = true + } + if (isEmpty(pixel.x,pixel.y-1)) { + createPixel("flower_cookie",pixel.x,pixel.y-1); + pixel.h = 3 + } + } + } + if (pixel.h === 3) { + if (pixel.temp < 100) { + if (isEmpty(pixel.x+1,pixel.y) && pixel.leftPetal !== true) { + createPixel("cookie_crop",pixel.x+1,pixel.y); + pixelMap[pixel.x+1][pixel.y].h = 4 + pixelMap[pixel.x+1][pixel.y].color = "#942e8c" + pixel.leftPetal = true + } + if (isEmpty(pixel.x-1,pixel.y) && pixel.rightPetal !== true) { + createPixel("cookie_crop",pixel.x-1,pixel.y); + pixelMap[pixel.x-1][pixel.y].h = 4 + pixelMap[pixel.x-1][pixel.y].color = "#942e8c" + pixel.rightPetal = true + } + if (pixel.color != "#734e39") { + pixel.color = "#734e39" + } + } + } + doDefaults(pixel); + }, + tempHigh: 200, + stateHigh: "cookie", + burn: 5, + burnTime: 100, + category: "clicker", + state: "solid", + density: 1500, + cooldown: defaultCooldown, + seed: true +} + +elements.flower_cookie = { + color: ["#C4966C","#C0946B","#C4966C","#C0946B","#4d2818","#3b1b0d","#33160a"], + behavior: [ + "XX|ST:cookie_crop|XX", + "ST:cookie_crop|XX|ST:cookie_crop", + "M2|ST:cookie_crop AND M1|M2", + ], + tick: function(pixel) { + pixel.PixelTicks = pixelTicks + if (pixel.PixelTicks % 30 == 0 && !isEmpty(pixel.x,pixel.y+1, true)) { + cookies += 8 + } + }, + tempHigh: 200, + stateHigh: "cookie", + burn: 5, + burnTime: 100, + category: "clicker", + state: "solid", + density: 1500, + cooldown: defaultCooldown, + seed: true +} + +elements.farm_deployer = { + color: ["#76552b","#5c4221","#573c1a","#6b481e"], + behavior: behaviors.WALL, + onPlace: function(pixel) { + farmCount.push(pixel) + for (f = 0; f < farmCount.length; f++) { + if (farmCount[f] == pixel) { + pixel.farmbuy = f + break; + } + } + }, + tick: function(pixel) { + if (buildings.farms[0] > pixel.farmbuy) { + pixel.bought = true + } + if (pixel.bought === true) { + changePixel(pixel, "cookie_crop") + } + }, + category: "clicker", + state: "solid", + density: 2000, + movable: false, +} + +elements.background = { + color: ["#60a2c3","#2e80a9"], + colorKey: { + "l": "#60a2c3", + "r": "#2e80a9", + }, + colorPattern: [ + "rrrlll", + ], + onSelect: function() { + logMessage("Draw a pipe, wait for walls to appear, then erase the exit hole."); + }, + tick: function(pixel) { + if (!pixel.stage && pixelTicks-pixel.start > 60) { + for (var i = 0; i < squareCoords.length; i++) { + var coord = squareCoords[i]; + var x = pixel.x+coord[0]; + var y = pixel.y+coord[1]; + if (!isEmpty(x,y,true) && elements[pixelMap[x][y].element].movable) { + deletePixel(x,y) + } + if (isEmpty(x,y)) { + createPixel("pipe_wall",x,y); + } + } + pixel.stage = 1; + } + else if (pixel.stage === 1 && pixelTicks-pixel.start > 70) { //uninitialized + for (var i = 0; i < adjacentCoords.length; i++) { + var coord = adjacentCoords[i]; + var x = pixel.x+coord[0]; + var y = pixel.y+coord[1]; + if (isEmpty(x,y)) { + pixel.stage = 2; //blue + break; + } + } + } + else if (pixel.stage > 1 && pixelTicks % 3 === pixel.stage-2) { //initialized + for (var i = 0; i < squareCoords.length; i++) { + var coord = squareCoords[i]; + var x = pixel.x+coord[0]; + var y = pixel.y+coord[1]; + if (!isEmpty(x,y,true) && pixelMap[x][y].element === pixel.element) { + var newPixel = pixelMap[x][y]; + if (newPixel.stage === 1) { + var newColor; + switch (pixel.stage) { + case 2: newPixel.stage = 3; newColor = "#003600"; break; //green + case 3: newPixel.stage = 4; newColor = "#360000"; break; //red + case 4: newPixel.stage = 2; newColor = "#000036"; break; //blue + } + } + } + } + var moved = false; + shuffleArray(squareCoordsShuffle); + for (var i = 0; i < squareCoordsShuffle.length; i++) { + var coord = squareCoordsShuffle[i]; + var x = pixel.x+coord[0]; + var y = pixel.y+coord[1]; + if (!isEmpty(x,y,true)) { + var newPixel = pixelMap[x][y]; + if (newPixel.element === pixel.element) { + var nextStage; + switch (pixel.stage) { + case 2: nextStage = 4; break; //green + case 3: nextStage = 2; break; //red + case 4: nextStage = 3; break; //blue + } + if (pixel.con && !newPixel.con && newPixel.stage === nextStage) { //transfer to adjacent pipe + newPixel.con = pixel.con; + newPixel.con.x = newPixel.x; + newPixel.con.y = newPixel.y; + pixel.con = null; + moved = true; + break; + } + } + else if (!pixel.con && elements[newPixel.element].movable) { //suck up pixel + pixel.con = newPixel; + deletePixel(newPixel.x,newPixel.y); + pixel.con.x = pixel.x; + pixel.con.y = pixel.y; + pixel.con.del; + moved = true; + break; + } + } + } + if (pixel.con && !moved) { // move to same stage if none other + for (var i = 0; i < squareCoordsShuffle.length; i++) { + var coord = squareCoordsShuffle[i]; + var x = pixel.x+coord[0]; + var y = pixel.y+coord[1]; + if (isEmpty(x,y)) { + delete pixel.con.del; + pixel.con.x = x; + pixel.con.y = y; + pixelMap[x][y] = pixel.con; + currentPixels.push(pixel.con); + pixel.con = null; + break; + } + if (!isEmpty(x,y,true) && pixelMap[x][y].element === pixel.element) { + var newPixel = pixelMap[x][y]; + if (pixel.con && !newPixel.con && newPixel.stage === pixel.stage) { + newPixel.con = pixel.con; + newPixel.con.x = newPixel.x; + newPixel.con.y = newPixel.y; + pixel.con = null; + break; + } + } + } + } + } + doDefaults(pixel); + }, + movable: false, + canContain: true, + behavior: behaviors.WALL, + tempHigh: 248, + stateHigh: ["fire","fire","fire","fire","fire","ash"], + burn: 70, + burnTime: 300, + burnInto: ["fire","fire","fire","fire","fire","ash"], + category: "clicker", + state: "solid", + density: 1201, + breakInto: "confetti", + breakIntoColor: ["#ffffff","#e6e6e6","#dbdbdb"] +} + +updateStats = function() { + var statsDiv = document.getElementById("stats"); + var stats = "x"+mousePos.x+",y"+mousePos.y+""; + stats += "Pxls:" + currentPixels.length+""; + stats += "" + tps+"tps"; + stats += "" + pixelTicks+""; + stats += "Cookies:" + cookies+""; + if ((typeof pixelMap).length === 9) { return; } + if (pixelMap[mousePos.x] !== undefined) { + var currentPixel = pixelMap[mousePos.x][mousePos.y]; + if (currentPixel !== undefined) { + stats += ""+langKey("gui.stats.elem","Elem")+":"+(elements[currentPixel.element].name || currentPixel.element).toUpperCase()+""; + stats += ""+langKey("gui.stats.temp","Temp")+":"+formatTemp(currentPixel.temp)+""; + if (currentPixel.charge) { + stats += "C"+parseFloat(currentPixel.charge)+""; + } + if (currentPixel.burning) { + stats += ""+langKey("gui.stats.burning","Burning")+""; + } + if (elements[currentPixel.element].hoverStat) { + stats += ""+elements[currentPixel.element].hoverStat(currentPixel).toString().replaceAll("<","<")+""; + } + else if (elements[currentElement].toolHoverStat) { + stats += ""+elements[currentElement].toolHoverStat(currentPixel).toString().replaceAll("<","<")+""; + } + else if (currentPixel.clone) { + stats += ""+currentPixel.clone.toString().toUpperCase().replaceAll("<","<")+""; + } + else if (currentPixel.con && currentPixel.con.element) { + stats += ""+currentPixel.con.element.toString().toUpperCase().replaceAll("<","<")+""; + } + } + } + if (shiftDown) { + stats += ""+shiftDownTypes[shiftDown]+""; + } + // If the view is not null, show the view in all caps + if (view !== null) { + stats += ""+(viewInfo[view] ? viewInfo[view].name : view)+""; + } + statsDiv.innerHTML = stats; +} + +buildingProduction = function() { + for (var i = 0; i <= cursorCount.length; i++) { + if (i >= (cursorCount.length - 1) && cursorCount[i - 1] && cursorCount[i - 1].bought == true) { + if ((pixelTicks - (buildings.cursors[i] * 1.5)) % 300 == 0) { + cookies += (buildings.cursors[0] - (i + 1)) + break; + } + } + } + for (var i = 0; i <= (grandmaCount.length - 1); i++) { + if (i >= (grandmaCount.length - 1) && grandmaCount[i - 1] && grandmaCount[i - 1].created == true) { + if (pixelTicks % 30 == 0) { + cookies += (buildings.grandmas[0] - (i + 1)) + break; + } + } + } + for (var i = 0; i <= farmCount.length; i++) { + if (i >= (farmCount.length - 1) && farmCount[i - 1] && farmCount[i - 1].bought == true) { + if (pixelTicks % 30 == 0) { + cookies += ((buildings.farms[0] - (i + 1)) * 8) + break; + } + } + } +} + +runEveryTick(buildingProduction) + +elements.dough.reactions.sugar = { elem1:"cookie_dough", elem2: null, chance:0.5} +elements.dough.reactions.chocolate = { elem1:"chocolate_chip_cookie_dough", elem2: null, chance:0.5} +elements.dough.reactions.chocolate_powder = { elem1:"chocolate_chip_cookie_dough", elem2: null, chance:0.5} \ No newline at end of file diff --git a/mods/hideandshowtools.js b/mods/hideandshowtools.js new file mode 100644 index 00000000..63a3370a --- /dev/null +++ b/mods/hideandshowtools.js @@ -0,0 +1,18 @@ +elements.hide = { + color: "#000000", + tool: function(pixel){ + pixel.alpha = 0 + }, + category: "tools", + canPlace: false, + desc: "Use on pixels to hide them.", +}; +elements.show = { + color: "#ffffff", + tool: function(pixel){ + pixel.alpha = 1 + }, + category: "tools", + canPlace: false, + desc: "Use on pixels to show them." +};