Skip to content

Commit

Permalink
Update thunderclap event for changes to SubEvent class
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed Jul 24, 2024
1 parent c573e35 commit 9174ecc
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/js/stendhal/event/generic/ThunderclapEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,26 @@ import { ViewPort } from "../../ui/ViewPort";
*/
export class ThunderclapEvent extends SubEvent {

private startTime = 0;
private image = store.get(Paths.maps + "/effect/lightning.png");
private flash = true;
private lightning = true;
/** Thunder image. */
private static readonly image = store.get(Paths.maps + "/effect/lightning.png");

/** Determines if screen should flash white. */
private readonly flash;
/** Determines if lightning bolt should be drawn. */
private readonly lightning;
/** Time that event execution began. */
private startTime;

override execute(entity: any, flags: string[]) {

constructor(flags: string[]) {
super(flags);
this.flash = !this.flagEnabled("no-flash");
this.lightning = !this.flagEnabled("no-lightning");
this.startTime = 0;
}

override execute(entity: any) {
this.startTime = Date.now();
this.flash = flags.indexOf("no-flash") < 0;
this.lightning = flags.indexOf("no-lightning") < 0;
// thunder sound
SoundManager.get().playLocalizedEffect(entity["x"], entity["y"], SoundManager.DEFAULT_RADIUS,
SoundLayer.SFX.value, SoundID["thunderclap"]!);
Expand Down Expand Up @@ -74,12 +84,12 @@ export class ThunderclapEvent extends SubEvent {
ctx.globalAlpha = 0.75;
}
ctx.fillStyle = Color.WHITE;
ctx.fillRect(offsetX, offsetY, 640, 480);
ctx.fillRect(offsetX, offsetY, ctx.canvas.width, ctx.canvas.height);
// restore composite info to make lightning opaque
ctx.restore();
}
if (this.lightning && this.image.height) {
ctx.drawImage(this.image, offsetX, offsetY);
if (this.lightning && ThunderclapEvent.image.height) {
ctx.drawImage(ThunderclapEvent.image, offsetX, offsetY);
}
ctx.restore();
}
}

0 comments on commit 9174ecc

Please sign in to comment.