diff options
| author | Sarah Bradley <git@sarahduck.ca> | 2023-12-01 20:33:42 -0800 |
|---|---|---|
| committer | Sarah Bradley <git@sarahduck.ca> | 2023-12-01 20:33:42 -0800 |
| commit | 2793b94040a473538f01723d5ca5f53c4535e2af (patch) | |
| tree | cb30f0dae20bda6ef9d1c005325bfd9c986b3c8f /Drawable.cs | |
What I've got so far
Diffstat (limited to 'Drawable.cs')
| -rw-r--r-- | Drawable.cs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Drawable.cs b/Drawable.cs new file mode 100644 index 0000000..f6e5e1b --- /dev/null +++ b/Drawable.cs @@ -0,0 +1,38 @@ +using System.Numerics; +using Raylib_cs; + +namespace OnekoOnline; + +abstract class Drawable : IDisposable +{ + public Vector2 Position { + get => _position; + set => _position = value.Round(); + } + private Vector2 _position; + + public Vector2 Size; + public float Rotation = 0f; + + public static readonly List<Drawable> Drawables = []; + + public static void DrawAll() + { + float delta = Raylib.GetFrameTime(); + foreach (Drawable drawable in Drawables.OrderBy(d => -d.Position.Y)) { + drawable?.Update(delta); + drawable?.Draw(); + } + } + + public static void DisposeAll() + { + foreach (Drawable drawable in Drawables.ToArray()) drawable?.Dispose(); + } + + public abstract void Draw(); + + public abstract void Update(float delta); + + public abstract void Dispose(); +}
\ No newline at end of file |
