Lighting is now even more broken

This commit is contained in:
Arne van Iterson 2020-03-26 20:10:53 +01:00
parent 9b5e993062
commit aff23993c5
3 changed files with 33 additions and 4 deletions

24
lib/Lighting.js Normal file
View File

@ -0,0 +1,24 @@
const Lightsource = require("./Lightsource.js");
const Container = require("./Container.js");
class Lighting extends Container {
constructor(x, y, mapW, mapH, sources, style = { start: "rgba(0, 0, 0, 0)", stop: "rgba(0, 0, 0, 0.5)", radius: 75 }) {
super();
this.pos = { x, y };
this.w = mapW;
this.h = mapH;
this.style = style;
if (sources.length > 1) {
this.style.stop = `rgba(0, 0, 0, ${1 - Math.round(Math.pow(0.25, 1 / sources.length) * 100) / 100})`;
console.log(this.style.stop);
}
for (let index = 0; index < sources.length; index++) {
const element = sources[index];
this.children.push(new Lightsource(element.x, element.y, x, y, mapW, mapH, this.style));
}
}
}
module.exports = Lighting;

View File

@ -1,9 +1,12 @@
class Lightsource { class Lightsource {
constructor(radius, style = { start: "rgba(255,255,255,0.5)", stop: "rgba(0,0,0,0.9)" }) { constructor(x, y, mapX, mapY, mapW, mapH, style = { start: "rgba(0, 0, 0, 0)", stop: "rgba(0, 0, 0, 0.5)", radius: 100 }) {
this.pos = { x: 0, y: 0 }; this.pos = { mapX, mapY };
this.radius = radius; this.radPos = { x, y };
this.mapW = mapW;
this.mapH = mapH;
this.radius = style.radius;
this.style = style; this.style = style;
} }
} }
module.exports = Lightsource; module.exports = Lightsource;

View File

@ -8,6 +8,7 @@ var AnimManager = require("./AnimManager.js"),
deadInTracks = require("./movement/deadInTracks.js"), deadInTracks = require("./movement/deadInTracks.js"),
wallslide = require("./movement/wallslide.js"), wallslide = require("./movement/wallslide.js"),
Rect = require("./Rect.js"), Rect = require("./Rect.js"),
Lighting = require("./Lighting.js"),
Lightsource = require("./Lightsource.js"), Lightsource = require("./Lightsource.js"),
KeyControls = require("./controls/KeyControls.js"), KeyControls = require("./controls/KeyControls.js"),
MouseControls = require("./controls/MouseControls.js"), MouseControls = require("./controls/MouseControls.js"),
@ -32,6 +33,7 @@ module.exports = {
deadInTracks, deadInTracks,
wallslide, wallslide,
Rect, Rect,
Lighting,
Lightsource, Lightsource,
KeyControls, KeyControls,
MouseControls, MouseControls,