Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
 public Camera(Vector2 StartPosition, BackingBox T = null, float Speed = 1)
 {
     position   = StartPosition;
     Target     = T;
     speed      = Speed;
     Limits     = null;
     shakeTimer = null;
 }
Exemplo n.º 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);
 }
Exemplo n.º 6
0
 public void PostSerialize()
 {
     backingBox = new BackingBox(
         BackingBox.IType.Static,
         X,
         Y,
         Z,
         Width * TileSize,
         Height * TileSize,
         Depth * TileSize
         );
 }
Exemplo n.º 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;
             }
         }
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 13
0
 public bool IsBoxPushingAgainstWall(BackingBox TargetBox, Vector2 Velocity)
 {
     return(false);
 }
Exemplo n.º 14
0
 public TrackingPoints(BackingBox CentralBox)
 {
     centralBox      = CentralBox;
     availablePoints = new Dictionary <Enums.Direction, BackingBox>(4);
 }
Exemplo n.º 15
0
 public IWorld AddBox(BackingBox B)
 {
     boxes.Add(B);
     boxes.Sort((a, b) => b.Top.CompareTo(a.Top));
     return(this);
 }
Exemplo n.º 16
0
 public IWorld RemoveBox(BackingBox B)
 {
     boxes.Remove(B);
     return(this);
 }
Exemplo n.º 17
0
 public IWorld AddBox(BackingBox B)
 {
     return(this);
 }
Exemplo n.º 18
0
 public IWorld RemoveBox(BackingBox B)
 {
     return(this);
 }
Exemplo n.º 19
0
 public bool IsDirectionClearAtDistance(BackingBox B, Enums.Direction Direction, float Distance, bool ShouldTranslate = false)
 {
     return(true);
 }
Exemplo n.º 20
0
 public bool IsBoxHangingOverCliff(BackingBox TargetBox, Vector2 Velocity)
 {
     return(false);
 }
Exemplo n.º 21
0
 public Vector3 Move(BackingBox TargetBox, Vector3 PositionDelta)
 {
     return(Vector3.One);
 }
Exemplo n.º 22
0
 public bool IsBoxOnGround(BackingBox TargetBox)
 {
     return(true);
 }
Exemplo n.º 23
0
 public Fuel(Vector2 Position)
 {
     backingBox = new BackingBox(BackingBox.IType.Static, Position.X, 0, Position.Y, WIDTH, 0, HEIGHT);
 }
Exemplo n.º 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);
        }