sandboxels/mods/flipflop.js

29 lines
752 B
JavaScript

elements.flipflop = {
powerstate: "false",
name: "Flip Flop",
color: "#CF300D",
state: "solid",
category: "machines",
conduct: 1,
tick: function(pixel) {
doHeat(pixel)
doBurning(pixel)
doElectricity(pixel)
let Output = pixelMap[pixel.x+1][pixel.y]
let Input = pixelMap[pixel.x-1][pixel.y]
if (typeof Output !== "undefined" && typeof Input !== "undefined"){
Output.charge = 0
if (pixel.powerstate == "true" && pixel.charge > 0.2) {
pixel.powerstate = "false"
pixel.color = "#CF300D"
Output.charge = 0
} else if (pixel.powerstate == "false" && pixel.charge > 0.2) {
pixel.powerstate = "true"
pixel.color = "#94CF0D"
Output.charge = 5
}
}
}
};