Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
EarthquakeEffect.cs
1using System.Drawing;
4
5namespace Gondwana.Effects;
6
10public sealed class EarthquakeEffect : DisplayEffect
11{
12 private readonly Random _random;
13 private PointF _originalFactor;
14 private PointF _originalPixels;
15
22 float durationSeconds,
23 float intensityPx = 8f,
24 bool decay = true,
25 int? randomSeed = null)
26 : base(durationSeconds, EasingKind.Linear)
27 {
28 if (intensityPx < 0f)
29 throw new ArgumentOutOfRangeException(nameof(intensityPx));
30
31 IntensityPx = intensityPx;
32 Decay = decay;
33 _random = new Random(randomSeed ?? Random.Shared.Next());
34 }
35
37 public float IntensityPx { get; }
38
40 public bool Decay { get; }
41
42 internal override EffectChannel Channel => EffectChannel.Transform;
43
44 internal override bool SupportsTarget(object target) => target is View;
45
47 private protected override void OnStarting()
48 {
49 _originalFactor = EffectTargetAccess.GetOffsetFactor(Target);
50 _originalPixels = EffectTargetAccess.GetOffsetPixels(Target);
51 }
52
54 private protected override void ApplyProgress(float progress)
55 {
56 if (progress >= 1f || IntensityPx <= 0f)
57 {
58 EffectTargetAccess.SetTransform(
59 Target,
60 _originalFactor,
61 _originalPixels);
62
63 return;
64 }
65
66 float amplitude = Decay
67 ? IntensityPx * (1f - progress)
69
70 float x = ((float)_random.NextDouble() * 2f - 1f) * amplitude;
71 float y = ((float)_random.NextDouble() * 2f - 1f) * amplitude;
72
73 EffectTargetAccess.SetTransform(
74 Target,
75 _originalFactor,
76 new PointF(
77 _originalPixels.X + x,
78 _originalPixels.Y + y));
79 }
80
82 private protected override void RestoreOriginalState() =>
83 EffectTargetAccess.SetTransform(Target, _originalFactor, _originalPixels);
84}
DisplayEffect(float durationSeconds, EasingKind easing=EasingKind.Linear)
Initializes a new instance of the DisplayEffect class.
float IntensityPx
Gets the maximum shake displacement in screen pixels.
override void ApplyProgress(float progress)
EarthquakeEffect(float durationSeconds, float intensityPx=8f, bool decay=true, int? randomSeed=null)
Creates a camera-shake effect.
override void OnStarting()
Captures or prepares target state before the effect starts.
override void RestoreOriginalState()
bool Decay
Gets whether shake intensity falls to zero over the effect duration.
Represents a rendered view of a scene, combining a camera position with a viewport configuration to c...
Definition View.cs:14
EasingKind
Enumeration of all supported easing functions for animation and movement interpolation....
Definition EasingKind.cs:9
@ Linear
Linear easing with constant velocity throughout the transition. No acceleration or deceleration is ap...
Definition EasingKind.cs:15