2026-03-09 20:05:21 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using MonoGameLibrary.Graphics;
|
|
|
|
|
|
2026-03-22 18:31:05 +01:00
|
|
|
namespace ONDClient.GUI;
|
2026-03-09 20:05:21 +01:00
|
|
|
|
|
|
|
|
public class JumpscareUIElement : UIElement {
|
|
|
|
|
private int twitchHorizontal;
|
|
|
|
|
private int twitchVertical;
|
|
|
|
|
private Point positionDefault;
|
|
|
|
|
private Random random;
|
|
|
|
|
|
|
|
|
|
private bool playing = false;
|
|
|
|
|
private Stopwatch stopwatch = new();
|
|
|
|
|
private int duration;
|
|
|
|
|
|
2026-03-28 09:59:31 +01:00
|
|
|
public JumpscareUIElement(TextureRegion texture, Point positionDefault, int twitchHorizontal, int twitchVertical, float defaultScaleMultiplier, int durationMs = 2000, Action afterStop = null) : base(texture, positionDefault) {
|
2026-03-09 20:05:21 +01:00
|
|
|
this.twitchHorizontal = twitchHorizontal;
|
|
|
|
|
this.twitchVertical = twitchVertical;
|
|
|
|
|
this.positionDefault = positionDefault;
|
|
|
|
|
random = new Random();
|
|
|
|
|
ScaleMultiplier = defaultScaleMultiplier;
|
|
|
|
|
duration = durationMs;
|
|
|
|
|
Active = false;
|
|
|
|
|
Visible = false;
|
|
|
|
|
AfterStop = afterStop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Play() {
|
|
|
|
|
playing = true;
|
|
|
|
|
Active = true;
|
|
|
|
|
Visible = true;
|
|
|
|
|
stopwatch.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Update() {
|
|
|
|
|
if (!playing) return;
|
|
|
|
|
SetPosition(new(positionDefault.X + random.Next(-twitchHorizontal, twitchHorizontal), positionDefault.Y + random.Next(-twitchVertical, twitchVertical)));
|
|
|
|
|
if (stopwatch.ElapsedMilliseconds >= duration){
|
|
|
|
|
playing = false;
|
|
|
|
|
Active = false;
|
|
|
|
|
Visible = false;
|
|
|
|
|
if (AfterStop != null){
|
|
|
|
|
AfterStop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Action AfterStop;
|
|
|
|
|
}
|