blob: f01c47873ae168b1ec12be50e35ea38e57393478 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
using System.Numerics;
using Raylib_cs;
namespace OnekoOnline;
abstract class Drawable : IDisposable
{
protected int DrawOrder = 0;
public bool Visible = true;
public Vector2 Position {
get => _position;
set => _position = value.Round();
}
private Vector2 _position;
public Vector2 Size;
public float Rotation = 0f;
public static readonly HashSet<Drawable> Drawables = [];
public Drawable() => Drawables.Add(this);
public static void DrawAll()
{
float delta = Raylib.GetFrameTime();
foreach (Drawable drawable in Drawables.OrderBy(d => d.Position.Y + d.DrawOrder*1000)) {
drawable?.Update(delta);
if (drawable == null || !drawable.Visible) continue;
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 virtual void Dispose() => Drawables.Remove(this);
}
|