Quellcode durchsuchen

Add creature animation

WangJun vor 8 Jahren
Ursprung
Commit
330e589e40

+ 62 - 0
src/MineCase.Algorithm/Game/Entity/Ai/Action/CreatureAction.cs

@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Numerics;
+using System.Text;
+using MineCase.World;
+
+namespace MineCase.Algorithm.Game.Entity.Ai.Action
+{
+    public class CreatureActionDistance
+    {
+        public float Yaw { get; set; }
+
+        public float Pitch { get; set; }
+
+        public Vector3 Position { get; set; }
+
+        public static CreatureActionDistance operator /(CreatureActionDistance lhs, float n)
+        {
+            CreatureActionDistance result = new CreatureActionDistance();
+            result.Yaw = lhs.Yaw / n;
+            result.Pitch = lhs.Pitch / n;
+            result.Position = new Vector3(lhs.Position.X / n, lhs.Position.Y / n, lhs.Position.Z / n);
+            return result;
+        }
+
+        public static CreatureActionDistance operator *(CreatureActionDistance lhs, float n)
+        {
+            CreatureActionDistance result = new CreatureActionDistance();
+            result.Yaw = lhs.Yaw * n;
+            result.Pitch = lhs.Pitch * n;
+            result.Position = new Vector3(lhs.Position.X * n, lhs.Position.Y * n, lhs.Position.Z * n);
+            return result;
+        }
+    }
+
+    public class CreatureAction
+    {
+        public float Yaw { get; set; }
+
+        public float Pitch { get; set; }
+
+        public EntityWorldPos Position { get; set; }
+
+        public static CreatureActionDistance operator -(CreatureAction lhs, CreatureAction rhs)
+        {
+            CreatureActionDistance result = new CreatureActionDistance();
+            result.Yaw = lhs.Yaw - rhs.Yaw;
+            result.Pitch = lhs.Pitch - rhs.Pitch;
+            result.Position = new Vector3(lhs.Position.X - rhs.Position.X, lhs.Position.Y - rhs.Position.Y, lhs.Position.Z - rhs.Position.Z);
+            return result;
+        }
+
+        public static CreatureAction operator +(CreatureAction lhs, CreatureActionDistance rhs)
+        {
+            CreatureAction result = new CreatureAction();
+            result.Yaw = lhs.Yaw + rhs.Yaw;
+            result.Pitch = lhs.Pitch + rhs.Pitch;
+            result.Position = new EntityWorldPos(lhs.Position.X + rhs.Position.X, lhs.Position.Y + rhs.Position.Y, lhs.Position.Z + rhs.Position.Z);
+            return result;
+        }
+    }
+}

+ 42 - 0
src/MineCase.Algorithm/Game/Entity/Ai/Action/CreatureAnimation.cs

@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace MineCase.Algorithm.Game.Entity.Ai.Action
+{
+    public abstract class CreatureAnimation
+    {
+        protected CreatureAction _begin;
+        protected CreatureAction _end;
+        protected int _time;
+        protected int _curtime;
+        protected CreatureActionDistance _step;
+
+        public CreatureAnimation(CreatureAction begin, CreatureAction end, int time)
+        {
+            _begin = begin;
+            _end = end;
+            _time = time;
+            _curtime = 0;
+            _step = (_end - _begin) / _time;
+        }
+
+        public abstract CreatureAction Step(int time);
+    }
+
+    public class CreatureAnimationLinear : CreatureAnimation
+    {
+        public CreatureAnimationLinear(CreatureAction begin, CreatureAction end, int time)
+            : base(begin, end, time)
+        {
+        }
+
+        public override CreatureAction Step(int time)
+        {
+            CreatureAction result = new CreatureAction();
+            _curtime += time;
+            result = _begin + _step * _curtime;
+            return result;
+        }
+    }
+}