Added lightsource

This commit is contained in:
Arne van Iterson 2020-03-24 20:29:33 +01:00
parent f7d6ba99dd
commit 0dc789a168
3 changed files with 20 additions and 0 deletions

9
lib/Lightsource.js Normal file
View File

@ -0,0 +1,9 @@
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;
this.style = style;
}
}
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"),
Lightsource = require("./Lightsource.js"),
KeyControls = require("./controls/KeyControls.js"), KeyControls = require("./controls/KeyControls.js"),
MouseControls = require("./controls/MouseControls.js"), MouseControls = require("./controls/MouseControls.js"),
Sprite = require("./Sprite.js"), Sprite = require("./Sprite.js"),
@ -31,6 +32,7 @@ module.exports = {
deadInTracks, deadInTracks,
wallslide, wallslide,
Rect, Rect,
Lightsource,
KeyControls, KeyControls,
MouseControls, MouseControls,
Sprite, Sprite,

View File

@ -82,6 +82,15 @@ class CanvasRenderer {
} else if (child.style && child.w && child.h) { } else if (child.style && child.w && child.h) {
ctx.fillStyle = child.style.fill; ctx.fillStyle = child.style.fill;
ctx.fillRect(0, 0, child.w, child.h); ctx.fillRect(0, 0, child.w, child.h);
} else if (child.style && child.radius) {
var gradient = ctx.createRadialGradient(0, 0, 50, 0, 0, 50);
gradient.addColorStop(0, child.style.start);
gradient.addColorStop(1, child.style.stop);
ctx.arc(0, 0, child.radius, 0, 2 * Math.PI);
ctx.fillStyle = gradient;
ctx.fill();
} }
// Handle children with children // Handle children with children