diff options
Diffstat (limited to 'Oneko.cs')
| -rw-r--r-- | Oneko.cs | 32 |
1 files changed, 8 insertions, 24 deletions
@@ -1,5 +1,4 @@ using System.Numerics; -using OnekoOnline.Net; using Raylib_cs; namespace OnekoOnline; @@ -7,17 +6,13 @@ namespace OnekoOnline; class Oneko : Drawable { public readonly Bitmap SpriteSheet; - Vector2 TargetPosition; + protected Vector2 TargetPosition; OnekoAnimation Animation = ScratchSelf; float updateTimer = 0f; const float updateRate = 1f/5f; int Frame = 0; - public static Oneko? LocalOneko; - - public static Dictionary<int, Oneko> NetNekos = []; - public Oneko() { Size = new(32,32); @@ -32,8 +27,6 @@ class Oneko : Drawable SpriteSheet = Bitmap.FromPNGMemory(EmbeddedResources.GetResource("oneko.png")); } - LocalOneko ??= this; - Drawables.Add(this); } @@ -53,31 +46,22 @@ class Oneko : Drawable public override void Update(float delta) { - if (this == LocalOneko) { - foreach (User user in OnekoOnline.Client!.Users.Values) { - if (user.ExchangedData && !NetNekos.ContainsKey(user.Id)) { - Bitmap spriteSheet = Bitmap.Deserialize(user.SpriteSheet); - NetNekos.Add(user.Id, new Oneko(spriteSheet)); - } - } - } - updateTimer += delta; if (updateTimer < updateRate) return; - if (Raylib.IsWindowFocused()) { - TargetPosition = Raylib.GetMousePosition()/2; - } else { - TargetPosition = new Vector2(320/2, 240/2); - } + OnekoUpdate(delta); + + updateTimer = 0f; + } + + public virtual void OnekoUpdate(float delta) + { Vector2 TargetDirection = (TargetPosition-Position).LimitLength(10f); if (TargetDirection.Length() > 1) Animation = GetDirectionalRun(TargetDirection); else Animation = Idle; Position += TargetDirection; Frame = (Frame + 1) % 2; - - updateTimer = 0f; } public override void Dispose() |
