From aff23993c5e66cd2592dc3e91065aeaeab8a8555 Mon Sep 17 00:00:00 2001 From: Arne van Iterson Date: Thu, 26 Mar 2020 20:10:53 +0100 Subject: [PATCH] Lighting is now even more broken --- lib/Lighting.js | 24 ++++++++++++++++++++++++ lib/Lightsource.js | 11 +++++++---- lib/index.js | 2 ++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 lib/Lighting.js diff --git a/lib/Lighting.js b/lib/Lighting.js new file mode 100644 index 0000000..096c032 --- /dev/null +++ b/lib/Lighting.js @@ -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; \ No newline at end of file diff --git a/lib/Lightsource.js b/lib/Lightsource.js index 43f533a..bd3146e 100644 --- a/lib/Lightsource.js +++ b/lib/Lightsource.js @@ -1,9 +1,12 @@ class Lightsource { - constructor(radius, style = { start: "rgba(255,255,255,0.5)", stop: "rgba(0,0,0,0.9)" }) { - this.pos = { x: 0, y: 0 }; - this.radius = radius; + 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 = { mapX, mapY }; + this.radPos = { x, y }; + this.mapW = mapW; + this.mapH = mapH; + this.radius = style.radius; this.style = style; } } - + module.exports = Lightsource; \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index 5d974b9..fdbacc0 100644 --- a/lib/index.js +++ b/lib/index.js @@ -8,6 +8,7 @@ var AnimManager = require("./AnimManager.js"), deadInTracks = require("./movement/deadInTracks.js"), wallslide = require("./movement/wallslide.js"), Rect = require("./Rect.js"), + Lighting = require("./Lighting.js"), Lightsource = require("./Lightsource.js"), KeyControls = require("./controls/KeyControls.js"), MouseControls = require("./controls/MouseControls.js"), @@ -32,6 +33,7 @@ module.exports = { deadInTracks, wallslide, Rect, + Lighting, Lightsource, KeyControls, MouseControls,