mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
New rain and thunder effects added
This commit is contained in:
51
js/effects/RainEffect.js
Normal file
51
js/effects/RainEffect.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import {FullscreenEffect} from "./FullscreenEffect.js";
|
||||
|
||||
export class RainEffect extends FullscreenEffect
|
||||
{
|
||||
static NAME = 'rain';
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this.image = new Image();
|
||||
this.image.src = 'js/effects/rain.png';
|
||||
this.sound = new Audio('js/effects/rain.mp3');
|
||||
this.sound.loop = true;
|
||||
this.offset = 0;
|
||||
this.speed = 1.3;
|
||||
}
|
||||
|
||||
init()
|
||||
{
|
||||
super.init();
|
||||
|
||||
this.sound.play();
|
||||
}
|
||||
|
||||
update(timestamp)
|
||||
{
|
||||
super.update(timestamp);
|
||||
|
||||
this.offsetX = (timestamp * 0.65 * this.speed) % this.image.width;
|
||||
this.offsetY = (timestamp * 1.5 * this.speed) % this.image.height;
|
||||
}
|
||||
|
||||
render(context, camera)
|
||||
{
|
||||
super.render(context, camera);
|
||||
|
||||
const cameraX = -1 * (camera.position.x % this.image.width);
|
||||
const cameraY = -1 * (camera.position.y % this.image.height);
|
||||
|
||||
for (let y = -1; y < Math.ceil(context.canvas.height / this.image.height) + 1; y++) {
|
||||
for (let x = -1; x < Math.ceil(context.canvas.width / this.image.width) + 1; x++) {
|
||||
context.drawImage(
|
||||
this.image,
|
||||
cameraX + this.offsetX + this.image.width * x,
|
||||
cameraY + this.offsetY + this.image.height * y,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user