Ejemplo n.º 1
0
        private static void RepositionFromUnit(IMovableUnit movingUnit, IUnit standingUnit)
        {
            var dir = new Vector2(movingUnit.Position.X - standingUnit.Position.X, movingUnit.Position.Y - standingUnit.Position.Y);

            if (dir.Equals(Vector2.Zero))
            {
                dir = new Vector2(0, -1);
            }
            var unstuckDir = new Vector2((float)(0.98 * dir.X - 0.17 * dir.Y), (float)(0.17 * dir.X + 0.98 * dir.Y));

            movingUnit.Reposition(unstuckDir, true, true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// For some reason z of the BoundingBox is y in our game
        /// </summary>
        private void RepositionFromWall(IMovableUnit unit, Point field)
        {
            var boundingBox = unit.GetBoundingBox();

            var unitLeftWall  = Math.Min(boundingBox.Min.X, boundingBox.Max.X);
            var unitUpperWall = Math.Min(boundingBox.Min.Z, boundingBox.Max.Z);
            var unitRightWall = Math.Max(boundingBox.Min.X, boundingBox.Max.X);
            var unitLowerWall = Math.Max(boundingBox.Min.Z, boundingBox.Max.Z);

            var fieldLeftWall  = field.X * mGridSize;
            var fieldUpperWall = field.Y * mGridSize;
            var fieldRightWall = (field.X + 1) * mGridSize;
            var fieldLowerWall = (field.Y + 1) * mGridSize;

            var leftDist  = fieldLeftWall - unitRightWall;
            var upperDist = fieldUpperWall - unitLowerWall;
            var rightDist = fieldRightWall - unitLeftWall;
            var lowerDist = fieldLowerWall - unitUpperWall;

            var xDirection = leftDist;

            if (Math.Abs(rightDist) < Math.Abs(leftDist))
            {
                xDirection = rightDist;
            }

            var yDirection = upperDist;

            if (Math.Abs(lowerDist) < Math.Abs(upperDist))
            {
                yDirection = lowerDist;
            }

            unit.Reposition(Math.Abs(xDirection) < Math.Abs(yDirection)
                    ? new Vector2(xDirection, 0)
                    : new Vector2(0, yDirection),
                            false,
                            false);
        }