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
MovementController.cs
1using System.Numerics;
5
7
19public sealed partial class MovementController : IDisposable
20{
21 private readonly ISceneLayerCoordinates? _coords;
22 private readonly SceneLayer? _sceneLayer;
23 private readonly IMovable _mover;
24 private MovementState _state;
25
30 public event Action<ScriptedMovement>? ScriptedMovementStarted;
31
36 public event Action<ScriptedMovement>? ScriptedMovementStopped;
37
38 // Bind to one target + initial state. Optional layer when you need Grid↔Pixel & wrapping.
39 internal MovementController(
40 IMovable mover,
41 MovementState initial,
42 SceneLayer? layer = null)
43 {
44 _mover = mover;
45 _state = initial;
46
47 if (layer is not null)
48 {
49 _sceneLayer = layer;
50
51 _coords = layer.CoordinateSystem
52 ?? throw new ArgumentException(
53 "SceneLayer must have a CoordinateSystem.",
54 nameof(layer));
55 }
56 }
57
72 internal bool AdvanceMovement(float dt)
73 {
74 // Follow owns the frame if engaged.
75 if (AdvanceFollow())
76 return true;
77
78 // Scripted tween/toward runs next.
79 if (AdvanceScripted(dt))
80 return true;
81
82 // Finally, physics integration.
83 return AdvanceIntegrated(dt);
84 }
85
90 public MovementState MovementState => _state;
91
97 public bool IsFollowing =>
98 _followHard ||
99 _followPixel is not null ||
100 _followGridTarget is not null;
101
105 public bool IsScripted =>
106 _state.Script.Type != MovementScriptType.None;
107
113 public bool IsIntegratedActive =>
114 !IsFollowing &&
115 !IsScripted &&
116 _state.HasMotion;
117
124 public bool WrapX { get; set; }
125
132 public bool WrapY { get; set; }
133
139 public void StopAllMovement()
140 {
141 Unfollow();
142
143 _state.Velocity = Vector2.Zero;
144 _state.Acceleration = Vector2.Zero;
145 }
146
150 public void Dispose()
151 {
152 _scriptCompleted = null;
153
156 }
157}
bool WrapX
Enables or disables horizontal world wrapping. When enabled, movement crossing the left/right edges w...
bool IsScripted
Indicates whether a scripted movement (tween or MoveToward) is currently active.
bool WrapY
Enables or disables vertical world wrapping. When enabled, movement crossing the top/bottom edges wra...
Action< ScriptedMovement >? ScriptedMovementStarted
Raised when a scripted movement (tween or MoveToward) begins. Subscribers are notified exactly once p...
bool IsIntegratedActive
Indicates whether physics-style integration is currently active. Returns true when the controller is ...
MovementState MovementState
Gets the current MovementState containing velocity, acceleration, and motion flags for the controlled...
void Dispose()
Releases resources and detaches all event handlers.
Action< ScriptedMovement >? ScriptedMovementStopped
Raised when a scripted movement (tween or MoveToward) completes or is explicitly cancelled....
void StopAllMovement()
Immediately stops all forms of movement — follow, scripted, and integrated. Cancels active scripted m...
bool IsFollowing
Indicates whether the controller is currently engaged in a follow behavior. Returns true if a pixel o...
void Unfollow()
Stop following any target and clear all follow/tween state (targets, speeds, offsets,...
Represents a single layer within a Scene, containing a grid of tiles and supporting various coordinat...
Definition SceneLayer.cs:40
Defines an object that can be moved within a specific coordinate space.
Definition IMovable.cs:12
MovementScriptType
Defines the type of scripted movement behavior applied to an object. Movement scripts control how an ...