Beispiel #1
0
        public void Update(float dt)
        {
            if (MapCoord != Target)
            {
                Direction = MapCoord.DirectionTo(Target);
            }

            if (CurrentAnimation != null)
            {
                CurrentAnimation.Update(dt);
                CurrentAnimation.Direction = Direction;
            }

            if (!Walking)
            {
                return;
            }

            var targetF = Target.ToCoordF() + new CoordF(0.5f, 0.5f);

            var d   = targetF - Position;
            var len = d.Length;

            if (len < 0.01)
            {
                Position = targetF;
                MapCoord = Position.ToCoord();
                Walking  = false;
                return;
            }

            const float speed      = 3;
            float       moveAmount = speed * dt;

            if (moveAmount > len)
            {
                moveAmount = len;
            }
            d.Normalize();
            Position = Position + (d * moveAmount);
        }