Projekt přejmenován. Neko nastaven na výchozí pozici
This commit is contained in:
parent
1a27dd6fab
commit
ceac37920b
104 changed files with 873 additions and 208 deletions
59
ONDClient/GUI/JumpscareUIElement.cs
Normal file
59
ONDClient/GUI/JumpscareUIElement.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using MonoGameLibrary.Graphics;
|
||||
|
||||
namespace ONDClient.GUI;
|
||||
|
||||
public class JumpscareUIElement : UIElement {
|
||||
private int twitchHorizontal;
|
||||
private int twitchVertical;
|
||||
private Point positionDefault;
|
||||
private Random random;
|
||||
private float defaultScaleMultiplier;
|
||||
private float twitchScale;
|
||||
|
||||
private bool playing = false;
|
||||
private Stopwatch stopwatch = new();
|
||||
private int duration;
|
||||
|
||||
public JumpscareUIElement(TextureRegion texture, Point positionDefault, int twitchHorizontal, int twitchVertical, float defaultScaleMultiplier, float twitchScale, int durationMs = 2000, Action afterStop = null) : base(texture, positionDefault) {
|
||||
this.twitchHorizontal = twitchHorizontal;
|
||||
this.twitchVertical = twitchVertical;
|
||||
this.positionDefault = positionDefault;
|
||||
random = new Random();
|
||||
this.defaultScaleMultiplier = defaultScaleMultiplier;
|
||||
ScaleMultiplier = defaultScaleMultiplier;
|
||||
this.twitchScale = twitchScale;
|
||||
duration = durationMs;
|
||||
Active = false;
|
||||
Visible = false;
|
||||
AfterStop = afterStop;
|
||||
}
|
||||
|
||||
// public JumpscareUIElement(UIElement element) : base(element.GetTextures(), element.Bounds.Item1) {}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
// ScaleMultiplier = defaultScaleMultiplier + (float)(random.NextDouble() * twitchScale * new[]{-1, 1}[random.Next(2)]);
|
||||
}
|
||||
|
||||
private Action AfterStop;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue