forked from arne/asdf-games
Added lightsource
This commit is contained in:
parent
f7d6ba99dd
commit
0dc789a168
9
lib/Lightsource.js
Normal file
9
lib/Lightsource.js
Normal 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;
|
@ -8,6 +8,7 @@ var AnimManager = require("./AnimManager.js"),
|
||||
deadInTracks = require("./movement/deadInTracks.js"),
|
||||
wallslide = require("./movement/wallslide.js"),
|
||||
Rect = require("./Rect.js"),
|
||||
Lightsource = require("./Lightsource.js"),
|
||||
KeyControls = require("./controls/KeyControls.js"),
|
||||
MouseControls = require("./controls/MouseControls.js"),
|
||||
Sprite = require("./Sprite.js"),
|
||||
@ -31,6 +32,7 @@ module.exports = {
|
||||
deadInTracks,
|
||||
wallslide,
|
||||
Rect,
|
||||
Lightsource,
|
||||
KeyControls,
|
||||
MouseControls,
|
||||
Sprite,
|
||||
|
@ -82,6 +82,15 @@ class CanvasRenderer {
|
||||
} else if (child.style && child.w && child.h) {
|
||||
ctx.fillStyle = child.style.fill;
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user