forked from arne/asdf-games
Lighting is now even more broken
This commit is contained in:
parent
9b5e993062
commit
aff23993c5
24
lib/Lighting.js
Normal file
24
lib/Lighting.js
Normal 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;
|
@ -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;
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user