mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Snow fullscreen effect implemented
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
13
js/Level.js
13
js/Level.js
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
22
js/effects/FullscreenEffect.js
Normal file
22
js/effects/FullscreenEffect.js
Normal file
@@ -0,0 +1,22 @@
|
||||
export class FullscreenEffect
|
||||
{
|
||||
static NAME = '';
|
||||
|
||||
constructor(canvas)
|
||||
{
|
||||
this.canvas = canvas;
|
||||
}
|
||||
|
||||
update(timestamp)
|
||||
{
|
||||
}
|
||||
|
||||
render(context)
|
||||
{
|
||||
}
|
||||
|
||||
getName()
|
||||
{
|
||||
return this.constructor.NAME;
|
||||
}
|
||||
}
|
||||
27
js/effects/FullscreenEffectFactory.js
Normal file
27
js/effects/FullscreenEffectFactory.js
Normal 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
31
js/effects/SnowEffect.js
Normal 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
BIN
js/effects/snow.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 83 KiB |
Reference in New Issue
Block a user