more updates
This commit is contained in:
parent
3d73a320f7
commit
ea8360cbe6
|
|
@ -9,46 +9,98 @@ function increment(){
|
||||||
function drawPixels(forceTick=false) {
|
function drawPixels(forceTick=false) {
|
||||||
// newCurrentPixels = shuffled currentPixels
|
// newCurrentPixels = shuffled currentPixels
|
||||||
var newCurrentPixels = currentPixels.slice();
|
var newCurrentPixels = currentPixels.slice();
|
||||||
newCurrentPixels.sort(function() {return 0.5 - Math.random()});
|
var pixelsFirst = [];
|
||||||
|
var pixelsLast = [];
|
||||||
|
if (!paused || forceTick) {
|
||||||
|
shuffleArray(newCurrentPixels);
|
||||||
|
}
|
||||||
|
/*{newCurrentPixels.sort(function(p) { // shuffle the pixels but keep elements[p.element].isGas last
|
||||||
|
return 0.5 - Math.random();
|
||||||
|
})} // shuffle the pixels if not paused*/
|
||||||
for (var i = 0; i < newCurrentPixels.length; i++) {
|
for (var i = 0; i < newCurrentPixels.length; i++) {
|
||||||
pixel = newCurrentPixels[i];
|
pixel = newCurrentPixels[i];
|
||||||
//if (pixelMap[pixel.x][pixel.y] == undefined || currentPixels.indexOf(pixel) == -1) {continue}
|
//if (pixelMap[pixel.x][pixel.y] == undefined || currentPixels.indexOf(pixel) == -1) {continue}
|
||||||
if (pixel.del) {continue}
|
if (pixel.del) {continue}
|
||||||
if ((!paused) || forceTick) {
|
if (!paused || forceTick) {
|
||||||
if (elements[pixel.element].tick) { // Run tick function if it exists
|
if (elements[pixel.element].tick) { // Run tick function if it exists
|
||||||
elements[pixel.element].tick(pixel);
|
elements[pixel.element].tick(pixel);
|
||||||
}
|
}
|
||||||
|
if (pixel.del) {continue}
|
||||||
if (elements[pixel.element].behavior) { // Parse behavior if it exists
|
if (elements[pixel.element].behavior) { // Parse behavior if it exists
|
||||||
pixelTick(pixel);
|
pixelTick(pixel);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if (elements[pixel.element].isGas) {
|
||||||
|
pixelsLast.push(pixel);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pixelsFirst.push(pixel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
adjacentCoords = [
|
||||||
|
[0,1],
|
||||||
|
[0,-1],
|
||||||
|
[1,0],
|
||||||
|
[-1,0]
|
||||||
|
];
|
||||||
|
biCoords = [
|
||||||
|
[0,1],
|
||||||
|
[1,0]
|
||||||
|
];
|
||||||
// Draw the current pixels
|
// Draw the current pixels
|
||||||
var canvas = document.getElementById("game");
|
var canvas = document.getElementById("game");
|
||||||
var ctx = canvas.getContext("2d");
|
var ctx = canvas.getContext("2d");
|
||||||
for (var i = 0; i < newCurrentPixels.length; i++) {
|
var pixelDrawList = pixelsFirst.concat(pixelsLast);
|
||||||
pixel = newCurrentPixels[i];
|
for (var i = 0; i < pixelDrawList.length; i++) {
|
||||||
if (pixelMap[pixel.x][pixel.y] == undefined) {continue}
|
pixel = pixelDrawList[i];
|
||||||
if (view===null) {
|
if (pixelMap[pixel.x][pixel.y] == undefined) {continue}
|
||||||
ctx.fillStyle = pixel.color;
|
if (view===null || view===3) {
|
||||||
}
|
ctx.fillStyle = pixel.color;
|
||||||
else if (view === "thermal") {
|
}
|
||||||
// set the color to pixel.temp, from hottest at 0 hue to coldest 225 hue, with the minimum being -273, max being 6000
|
else if (view === 2) { // thermal view
|
||||||
var temp = pixel.temp;
|
// set the color to pixel.temp, from hottest at 0 hue to coldest 225 hue, with the minimum being -273, max being 6000
|
||||||
if (temp < -273) {temp = -273}
|
var temp = pixel.temp;
|
||||||
if (temp > 6000) {temp = 6000}
|
if (temp < -273) {temp = -273}
|
||||||
var hue = 225 - (temp/6000)*225;
|
if (temp > 6000) {temp = 6000}
|
||||||
if (hue < 0) {hue = 0}
|
var hue = 225 - (temp/6000)*225;
|
||||||
if (hue > 225) {hue = 225}
|
if (hue < 0) {hue = 0}
|
||||||
ctx.fillStyle = "hsl("+hue+",100%,50%)";
|
if (hue > 225) {hue = 225}
|
||||||
}
|
ctx.fillStyle = "hsl("+hue+",100%,50%)";
|
||||||
ctx.fillRect(pixel.x*pixelSize+(18*Math.sin((pixel.y+incrementt )/4.4)), pixel.y*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4)), pixelSize, pixelSize);
|
}
|
||||||
if (pixel.charge) { // Yellow glow on charge
|
else if (view === 4) { // smooth view, average of surrounding pixels
|
||||||
if (!elements[pixel.element].colorOn) {
|
var colorlist = [];
|
||||||
ctx.fillStyle = "rgba(255,255,0,0.5)";
|
// check adjacent coords on the pixelMap, add the color to the list if the pixel is not empty and the color indexOf "rgb" is not -1
|
||||||
ctx.fillRect(pixel.x*pixelSize+(18*Math.sin((pixel.y+incrementt)/4.4)), pixel.y*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4)), pixelSize, pixelSize);
|
for (var j = 0; j < biCoords.length; j++) {
|
||||||
|
var x = pixel.x + biCoords[j][0];
|
||||||
|
var y = pixel.y + biCoords[j][1];
|
||||||
|
if (isEmpty(x,y,true) || elements[pixelMap[x][y].element].state !== elements[pixel.element].state) {continue}
|
||||||
|
var color = pixelMap[x][y].color;
|
||||||
|
if (color.indexOf("rgb") !== -1) {
|
||||||
|
colorlist.push(color.match(/\d+/g));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (colorlist.length === 0) {
|
||||||
|
ctx.fillStyle = pixel.color;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ctx.fillStyle = averageRGB(colorlist);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if ((view === null || view === 4) && elements[pixel.element].state === "gas") {
|
||||||
|
ctx.globalAlpha = 0.5;
|
||||||
|
ctx.fillRect((pixel.x-1)*pixelSize+(18*Math.sin((pixel.y+incrementt )/4.4)), (pixel.y)*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4)), pixelSize*3, pixelSize);
|
||||||
|
ctx.fillRect((pixel.x)*pixelSize+(18*Math.sin((pixel.y+incrementt )/4.4)), (pixel.y-1)*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4)), pixelSize, pixelSize*3);
|
||||||
|
ctx.globalAlpha = 1;
|
||||||
|
}
|
||||||
|
else { // draw the pixel (default)
|
||||||
|
ctx.fillRect(pixel.x*pixelSize+(18*Math.sin((pixel.y+incrementt )/4.4)), pixel.y*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4)), pixelSize, pixelSize);
|
||||||
|
}
|
||||||
|
if (pixel.charge && view !== 2) { // Yellow glow on charge
|
||||||
|
if (!elements[pixel.element].colorOn) {
|
||||||
|
ctx.fillStyle = "rgba(255,255,0,0.5)";
|
||||||
|
ctx.fillRect(pixel.x*pixelSize+(18*Math.sin((pixel.y+incrementt )/4.4)), pixel.y*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4)), pixelSize, pixelSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if ((!paused) || forceTick) {pixelTicks++};
|
if ((!paused) || forceTick) {pixelTicks++};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue