示例#1
0
        public BackingBox SpawnSticky(float X, float Y, float Z, float Width, float Height, float Depth)
        {
            BackingBox box = new BackingBox(BackingBox.IType.Sticky, X, Y, Z, Width, Height, Depth);

            boxes.Add(box);
            return(box);
        }
示例#2
0
        public bool IsDirectionClearAtDistance(BackingBox B, Enums.Direction Direction, float Distance, bool ShouldTranslate = false)
        {
            Box adjustedBox;

            if (ShouldTranslate)
            {
                adjustedBox = B.B;
                adjustedBox.GetTranslation(GraphicsHelper.GetVector3FromDirection(Direction) * Distance);
            }
            else
            {
                adjustedBox = B.B.GetDirectionalExpansion(Direction, Distance, -2, -4);
            }
            foreach (BackingBox b in boxes)
            {
                if (b == B || b.InteractionType != BackingBox.IType.Static)
                {
                    continue;
                }
                if (b.B.DoesIntersect(adjustedBox))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#3
0
        public Enums.Direction?TryClaimNearestPoint(BackingBox SeekingBox, float TargetDistance)
        {
            Enums.Direction?nearestDirection = null;
            float           minDistance      = 0;

            foreach (Enums.Direction dir in Enum.GetValues(typeof(Enums.Direction)))
            {
                if (availablePoints.ContainsKey(dir))
                {
                    if (availablePoints[dir] != SeekingBox)
                    {
                        continue;
                    }
                    else
                    {
                        availablePoints.Remove(dir);
                    }
                }
                Vector3 potentialTrackingPoint = centralBox.GetCenterPoint() + GraphicsHelper.GetVector3FromDirection(dir) * TargetDistance;
                float   currentDistance        = Vector3.Distance(potentialTrackingPoint, SeekingBox.GetCenterPoint());
                if (nearestDirection == null || currentDistance < minDistance)
                {
                    minDistance      = currentDistance;
                    nearestDirection = dir;
                }
            }
            if (nearestDirection.HasValue)
            {
                availablePoints[nearestDirection.Value] = SeekingBox;
            }
            return(nearestDirection);
        }
示例#4
0
 public Camera(Vector2 StartPosition, BackingBox T = null, float Speed = 1)
 {
     position   = StartPosition;
     Target     = T;
     speed      = Speed;
     Limits     = null;
     shakeTimer = null;
 }
示例#5
0
 public virtual void PostSerialize()
 {
     if (textureKey != null)
     {
         texture = GameService.GetService <IContentService>().GetxAsset <Texture2D>(textureKey);
     }
     BackingBox = new BackingBox(interactionType, x, y, z, w * sourceTileWidth, h * sourceTileHeight, d * sourceTileDepth, SortMode: BackingBox.SortingMode.Box);
 }
示例#6
0
 public void PostSerialize()
 {
     backingBox = new BackingBox(
         BackingBox.IType.Static,
         X,
         Y,
         Z,
         Width * TileSize,
         Height * TileSize,
         Depth * TileSize
         );
 }
示例#7
0
 public void RelinquishPoint(BackingBox SeekingBox)
 {
     foreach (Enums.Direction dir in Enum.GetValues(typeof(Enums.Direction)))
     {
         if (availablePoints.ContainsKey(dir))
         {
             if (availablePoints[dir] == SeekingBox)
             {
                 availablePoints.Remove(dir);
                 return;
             }
         }
     }
 }
示例#8
0
        protected Vector3 MoveSticky(BackingBox TargetBox, Vector3 PositionDelta)
        {
            TargetBox.Move(new Vector3(0, 1, 0));
            foreach (BackingBox box in boxes)
            {
                if (box != TargetBox && TargetBox.B.DoesIntersect(box.B))
                {
                    box.Move(PositionDelta);
                }
            }
            TargetBox.Move(new Vector3(0, -1, 0) + PositionDelta);

            return(Vector3.One);
        }
示例#9
0
        public Vector3 Move(BackingBox TargetBox, Vector3 PositionDelta)
        {
            switch (TargetBox.InteractionType)
            {
            case BackingBox.IType.Static:
            case BackingBox.IType.Free:
                return(MoveFree(TargetBox, PositionDelta));

            case BackingBox.IType.None:
                TargetBox.Move(PositionDelta);
                break;

            case BackingBox.IType.Sticky:
                return(MoveSticky(TargetBox, PositionDelta));
            }
            return(Vector3.One);
        }
示例#10
0
        public bool IsBoxHangingOverCliff(BackingBox TargetBox, Vector2 Velocity)
        {
            BackingBox offsetTargetBox = BackingBox.Build(
                BackingBox.IType.None,
                TargetBox.Left + Velocity.X,
                TargetBox.Bottom,
                TargetBox.Back + Velocity.Y,
                TargetBox.Width,
                TargetBox.Height,
                TargetBox.Depth
                );
            List <Vector3> corners = new List <Vector3>
            {
                new Vector3(offsetTargetBox.Left, offsetTargetBox.Bottom - 1, offsetTargetBox.Back),
                new Vector3(offsetTargetBox.Right, offsetTargetBox.Bottom - 1, offsetTargetBox.Back),
                new Vector3(offsetTargetBox.Right, offsetTargetBox.Bottom - 1, offsetTargetBox.Front),
                new Vector3(offsetTargetBox.Left, offsetTargetBox.Bottom - 1, offsetTargetBox.Front),
            };

            foreach (BackingBox box in boxes)
            {
                if (TargetBox == box)
                {
                    continue;
                }
                for (int i = 0; i < corners.Count;)
                {
                    Vector3 corner = corners[i];
                    if (box.B.DoesContainPoint(corner))
                    {
                        corners.RemoveAt(i);
                        continue;
                    }
                    i++;
                }
                if (corners.Count == 0)
                {
                    BackingBox.Return(offsetTargetBox);
                    return(false);
                }
            }
            BackingBox.Return(offsetTargetBox);
            return(true);
        }
示例#11
0
        public bool IsBoxOnGround(BackingBox TargetBox)
        {
            if (TargetBox.InteractionType == BackingBox.IType.None)
            {
                return(false);
            }
            TargetBox.Move(new Vector3(0, -1, 0));
            bool isOnGround = false;

            foreach (BackingBox box in boxes)
            {
                if (TargetBox != box && box.IsInteractive() && TargetBox.B.DoesIntersect(box.B))
                {
                    isOnGround = true;
                    break;
                }
            }
            TargetBox.Move(new Vector3(0, 1, 0));
            return(isOnGround);
        }
示例#12
0
        public bool IsBoxPushingAgainstWall(BackingBox TargetBox, Vector2 Velocity)
        {
            BackingBox offsetTargetBox = BackingBox.Build(
                BackingBox.IType.None,
                TargetBox.Left + Velocity.X,
                TargetBox.Bottom,
                TargetBox.Back + Velocity.Y,
                TargetBox.Width,
                TargetBox.Height,
                TargetBox.Depth
                );

            foreach (BackingBox box in boxes)
            {
                if (TargetBox != box && box.IsInteractive() && offsetTargetBox.B.DoesIntersect(box.B))
                {
                    BackingBox.Return(offsetTargetBox);
                    return(true);
                }
            }
            BackingBox.Return(offsetTargetBox);
            return(false);
        }
示例#13
0
 public bool IsBoxPushingAgainstWall(BackingBox TargetBox, Vector2 Velocity)
 {
     return(false);
 }
示例#14
0
 public TrackingPoints(BackingBox CentralBox)
 {
     centralBox      = CentralBox;
     availablePoints = new Dictionary <Enums.Direction, BackingBox>(4);
 }
示例#15
0
 public IWorld AddBox(BackingBox B)
 {
     boxes.Add(B);
     boxes.Sort((a, b) => b.Top.CompareTo(a.Top));
     return(this);
 }
示例#16
0
 public IWorld RemoveBox(BackingBox B)
 {
     boxes.Remove(B);
     return(this);
 }
示例#17
0
 public IWorld AddBox(BackingBox B)
 {
     return(this);
 }
示例#18
0
 public IWorld RemoveBox(BackingBox B)
 {
     return(this);
 }
示例#19
0
 public bool IsDirectionClearAtDistance(BackingBox B, Enums.Direction Direction, float Distance, bool ShouldTranslate = false)
 {
     return(true);
 }
示例#20
0
 public bool IsBoxHangingOverCliff(BackingBox TargetBox, Vector2 Velocity)
 {
     return(false);
 }
示例#21
0
 public Vector3 Move(BackingBox TargetBox, Vector3 PositionDelta)
 {
     return(Vector3.One);
 }
示例#22
0
 public bool IsBoxOnGround(BackingBox TargetBox)
 {
     return(true);
 }
示例#23
0
文件: Fuel.cs 项目: dxprog/warlocked
 public Fuel(Vector2 Position)
 {
     backingBox = new BackingBox(BackingBox.IType.Static, Position.X, 0, Position.Y, WIDTH, 0, HEIGHT);
 }
示例#24
0
        protected Vector3 MoveFree(BackingBox TargetBox, Vector3 PositionDelta, bool ShouldHugTerrain = true)
        {
            if (PositionDelta.LengthSquared() == 0)
            {
                return(Vector3.One);
            }
            bool isOnGroundPreMove = false;

            if (ShouldHugTerrain && PositionDelta.Y == 0)
            {
                isOnGroundPreMove = IsBoxOnGround(TargetBox);
            }
            TargetBox.Move(PositionDelta);
            if (isOnGroundPreMove)
            {
                if (!IsBoxOnGround(TargetBox))
                {
                    // Ramps are only oriented north south for now
                    TargetBox.Move(new Vector3(0, -Math.Abs(PositionDelta.Z), 0));
                }
            }

            bool    hasCollided;
            Vector3 velocityAdjustments = Vector3.One;

            do
            {
                hasCollided = false;
                foreach (BackingBox box in boxes)
                {
                    if (!box.IsInteractive() || TargetBox == box || !TargetBox.B.DoesIntersect(box.B))
                    {
                        continue;
                    }
                    hasCollided = true;
                    float xIntersectRatio = -1;
                    float yIntersectRatio = -1;
                    float zIntersectRatio = -1;
                    if (PositionDelta.X > 0)
                    {
                        xIntersectRatio = Math.Abs(
                            TargetBox.GetFaceIntersectDistance(box, BackingBox.Face.Left) / PositionDelta.X
                            );
                    }
                    else if (PositionDelta.X < 0)
                    {
                        xIntersectRatio = Math.Abs(
                            TargetBox.GetFaceIntersectDistance(box, BackingBox.Face.Right) / PositionDelta.X
                            );
                    }
                    if (PositionDelta.Y > 0)
                    {
                        yIntersectRatio = Math.Abs(
                            TargetBox.GetFaceIntersectDistance(box, BackingBox.Face.Bottom) / PositionDelta.Y
                            );
                    }
                    else if (PositionDelta.Y < 0)
                    {
                        yIntersectRatio = Math.Abs(
                            TargetBox.GetFaceIntersectDistance(box, BackingBox.Face.Top) / PositionDelta.Y
                            );
                    }
                    else
                    {
                        yIntersectRatio = Math.Abs(
                            TargetBox.GetFaceIntersectDistance(box, BackingBox.Face.Top) / new Vector2(PositionDelta.X, PositionDelta.Z).Length()
                            );
                    }
                    if (PositionDelta.Z > 0)
                    {
                        zIntersectRatio = Math.Abs(
                            TargetBox.GetFaceIntersectDistance(box, BackingBox.Face.Back) / PositionDelta.Z
                            );
                    }
                    else if (PositionDelta.Z < 0)
                    {
                        zIntersectRatio = Math.Abs(
                            TargetBox.GetFaceIntersectDistance(box, BackingBox.Face.Front) / PositionDelta.Z
                            );
                    }
                    if (
                        (yIntersectRatio == -1 || (xIntersectRatio != -1 && xIntersectRatio <= yIntersectRatio)) &&
                        (zIntersectRatio == -1 || (xIntersectRatio != -1 && xIntersectRatio <= zIntersectRatio))
                        )
                    {
                        TargetBox.MatchFace(box, PositionDelta.X > 0 ? BackingBox.Face.Left : BackingBox.Face.Right);
                        velocityAdjustments.X = 0;
                    }
                    else if (
                        (xIntersectRatio == -1 || (yIntersectRatio != -1 && yIntersectRatio <= xIntersectRatio)) &&
                        (zIntersectRatio == -1 || (yIntersectRatio != -1 && yIntersectRatio <= zIntersectRatio))
                        )
                    {
                        if (box.B.isRamp)
                        {
                            if (PositionDelta.Z > 0)
                            {
                                velocityAdjustments.Z = 1f;
                            }
                            else if (PositionDelta.Z < 0)
                            {
                                velocityAdjustments.Z = 0.4f;
                            }
                        }

                        TargetBox.MatchFace(box, PositionDelta.Y > 0 ? BackingBox.Face.Bottom : BackingBox.Face.Top);
                        velocityAdjustments.Y = 0;
                    }
                    else if (
                        (xIntersectRatio == -1 || (zIntersectRatio != -1 && zIntersectRatio <= xIntersectRatio)) &&
                        (yIntersectRatio == -1 || (zIntersectRatio != -1 && zIntersectRatio <= yIntersectRatio))
                        )
                    {
                        TargetBox.MatchFace(box, PositionDelta.Z > 0 ? BackingBox.Face.Back : BackingBox.Face.Front);
                        velocityAdjustments.Z = 0;
                    }
                }
            } while (hasCollided);

            return(velocityAdjustments);
        }