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

View File

@@ -7,24 +7,44 @@ export class SnowEffect extends FullscreenEffect
constructor()
{
super();
this.audio = new Audio('js/effects/storm.mp3');
this.audio.loop = true;
this.image = new Image();
this.image.src = 'js/effects/snow.png';
this.offset = 0;
this.speed = 1.0;
}
init()
{
super.init();
this.audio.play();
}
update(timestamp)
{
super.update(timestamp);
this.offset = timestamp % 512;
this.offsetX = (timestamp * 0.65 * this.speed) % this.image.width;
this.offsetY = (timestamp * 1.5 * this.speed) % this.image.height;
}
render(context)
render(context, camera)
{
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);
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,
);
}
}
}