Snow fullscreen effect implemented

This commit is contained in:
Mal
2024-12-08 16:53:56 +01:00
parent 4bf46d99fd
commit 4b85a314c4
13 changed files with 250 additions and 2 deletions

View File

@@ -71,7 +71,13 @@ export class Game
this.architecture.draw(this.context, this.camera);
this.mrCroc.draw(this.context, this.camera);
this.gisela.draw(this.context, this.camera);
this.userInterface.draw(this.context);
for (const effect of this.level.fullscreenEffects) {
effect.update(timestamp);
effect.render(this.context);
}
this.userInterface.draw(this.context);
this.lastRendered = timestamp;
}

View File

@@ -1,5 +1,6 @@
import FileLoader from "./FileLoader.js";
import Terrain from "../tilorswift/js/Terrain.js";
import {FullscreenEffectFactory} from "./effects/FullscreenEffectFactory.js";
export default class Level
{
@@ -8,6 +9,7 @@ export default class Level
constructor(terrain)
{
this.terrain = terrain;
this.fullscreenEffects = [];
this.gravity = 2.0;
}
@@ -83,7 +85,6 @@ export default class Level
const json = JSON.parse(data);
const level = new Level(Terrain.createFromJson(json));
level.setGravity(json.gravity / Level.FACTOR_GRAVITY);
callback(level);
}
loader.loadContent();
@@ -97,6 +98,16 @@ export default class Level
const level = new Level(terrain);
level.setGravity(data.gravity / Level.FACTOR_GRAVITY);
if (data.hasOwnProperty('effects')) {
const effectFactory = new FullscreenEffectFactory();
for (const effect of data.effects) {
level.fullscreenEffects.push(
effectFactory.getEffect(effect)
);
}
}
return level;
}
}

View File

@@ -0,0 +1,22 @@
export class FullscreenEffect
{
static NAME = '';
constructor(canvas)
{
this.canvas = canvas;
}
update(timestamp)
{
}
render(context)
{
}
getName()
{
return this.constructor.NAME;
}
}

View File

@@ -0,0 +1,27 @@
import {SnowEffect} from "./SnowEffect.js";
export class FullscreenEffectFactory
{
static EFFECTS = {
[SnowEffect.NAME]: SnowEffect,
}
getEffect(name)
{
return new FullscreenEffectFactory.EFFECTS[name]();
}
static getNames()
{
const names = [];
for (const name in FullscreenEffectFactory.EFFECTS) {
console.log(name);
names.push(name);
}
console.log(names);
return names;
}
}

31
js/effects/SnowEffect.js Normal file
View File

@@ -0,0 +1,31 @@
import {FullscreenEffect} from "./FullscreenEffect.js";
export class SnowEffect extends FullscreenEffect
{
static NAME = 'snow';
constructor()
{
super();
this.image = new Image();
this.image.src = '/js/effects/snow.png';
this.offset = 0;
}
update(timestamp)
{
super.update(timestamp);
this.offset = timestamp % 512;
}
render(context)
{
super.render(context);
for (let y = -1; y < Math.ceil(context.canvas.height / 512); y++) {
for (let x = -1; x < Math.ceil(context.canvas.width / 512); x++) {
context.drawImage(this.image, this.offset + 512 * x, this.offset + 512 * y);
}
}
}
}

BIN
js/effects/snow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB