feat: test night mode

This commit is contained in:
cha0s 2019-03-30 07:00:07 -05:00
parent a02b61f2e8
commit cbad2cac0e

View File

@ -12,13 +12,14 @@ const appNode = document.querySelector('.app');
// Graphics stage.
const stage = new Stage([640, 360]);
stage.scale = [2, 2];
stage.addToDom(appNode);
let isFocused = false;
stage.element.addEventListener('blur', () => {
stage.sepia();
isFocused = false;
});
stage.element.addEventListener('focus', () => {
stage.removeAllFilters();
isFocused = true;
});
stage.addToDom(appNode);
// Create room.
const room = new Room();
room.world = new World();
@ -109,6 +110,7 @@ const messageHandle = setInterval(() => {
}, 1000 / 60);
// Prediction.
let lastTime = performance.now();
let nightIntensity = 0;
const predictionHandle = setInterval(() => {
const now = performance.now();
const elapsed = (now - lastTime) / 1000;
@ -117,6 +119,15 @@ const predictionHandle = setInterval(() => {
selfEntity.inputState = actionState.toJS();
}
room.tick(elapsed);
stage.removeAllFilters();
const intensity = nightIntensity < 0.8 ? nightIntensity : 0.8;
if (!isFocused) {
stage.paused(intensity);
}
else {
stage.night(intensity);
}
nightIntensity += 0.0001;
}, 1000 / 80);
// State updates.
let dirty = false;