New rain and thunder effects added

This commit is contained in:
Mal
2024-12-14 12:09:49 +01:00
parent a583005814
commit f6ebd8f3aa
14 changed files with 183 additions and 11 deletions

51
js/effects/RainEffect.js Normal file
View 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,
);
}
}
}
}