コード例 #1
0
        public void Update()
        {
            parent.Velocity.X = fint.zero;
            parent.Velocity.Y = fint.zero;

            radiusNear  = false;
            radiusTouch = false;
            //------------------------------------------------------------------------------------
            unitsNearBy.Clear();
            parent.proximityToken.FindNeighbors(new Point3D(parent.Position.X.ToInt(), 0, parent.Position.Y.ToInt()), NeighborCheckRadius, unitsNearBy);

            DisperseUpdate();


            var dist      = (parent.Position - dest).sqrMagnitude;
            int reachDist = 1;

            if (parent.Orders.Count != 0 && parent.Orders.Peek().type == OrderType.MOVE)
            {
                reachDist = 10;
            }

            if (active)
            {
                fint xxx = fint.zero, yyy = fint.zero;
                //------------------------------------------------------------------------------------

                FVector2 cur2D     = BackgroundGame.MapSpace.WorldToSpace(parent.Position);
                int      id        = cur2D.X.ToInt() + cur2D.Y.ToInt() * BackgroundGame.MapSpace.Width;
                byte     direction = flowfield == null ? (byte)255 : ((id >= 0 && id < flowfield.Length) ? flowfield.Get(id) : (byte)0);

                //if (direction == 255 || dist<(fint)((reachDist+1) * (reachDist+1))) {
                parent.Rotation = FVector2.Angle(dest, parent.Position);

                /*} else {
                 *  if (direction != 0 && direction != 1) {
                 *      if (direction >= 100) direction -= 100;
                 *
                 *      int x = -MapSpace.Direction[direction - 2, 0];
                 *      int y = -MapSpace.Direction[direction - 2, 1];
                 *      parent.Rotation =  FMath.Atan2((fint)y, (fint)x);
                 *  }
                 * }*/



                xxx = FMath.Cos(parent.Rotation) * (fint)Speed;
                yyy = FMath.Sin(parent.Rotation) * (fint)Speed;

                //------------------------------------------------------------------------------------

                if (!BackgroundGame.MapSpace.TestWithDiagonals(parent.Position.X + parent.Velocity.X + xxx, parent.Position.Y + parent.Velocity.Y))
                {
                    xxx = fint.zero;
                }
                if (!BackgroundGame.MapSpace.TestWithDiagonals(parent.Position.X + parent.Velocity.X, parent.Position.Y + parent.Velocity.Y + yyy))
                {
                    yyy = fint.zero;
                }
                if (!BackgroundGame.MapSpace.TestWithDiagonals(parent.Position.X + parent.Velocity.X + xxx, parent.Position.Y + parent.Velocity.Y + yyy))
                {
                    xxx = fint.zero;
                    yyy = fint.zero;
                }

                parent.Velocity.X += xxx;
                parent.Velocity.Y += yyy;
            }


            parent.Velocity.X = GameUtils.Clamp(parent.Velocity.X, -Speed, Speed);
            parent.Velocity.Y = GameUtils.Clamp(parent.Velocity.Y, -Speed, Speed);

            parent.Position += parent.Velocity;
            //if (!active)

            if (active)
            {
                dist = (parent.Position - dest).sqrMagnitude;
                if (dist <= (fint)(reachDist * reachDist))
                {
                    //parent.Position = dest;
                    active        = false;
                    reached       = true;
                    parent.Moving = false;
                }
            }
        }