示例#1
0
    public WallDirection GetDirectionOfSealedDoor()
    {
        WallDirection dir = WallDirection.North;

        if (northWallType == WallType.DoorSealed)
        {
            dir = WallDirection.North;
        }
        else if (eastWallType == WallType.DoorSealed)
        {
            dir = WallDirection.East;
        }
        else if (southWallType == WallType.DoorSealed)
        {
            dir = WallDirection.South;
        }
        else if (westWallType == WallType.DoorSealed)
        {
            dir = WallDirection.West;
        }
        else
        {
            Debug.LogError("No Sealed doors exist in this room: " + name);
        }

        return(dir);
    }
示例#2
0
    public static WallDirection GetRandomWallDirection()
    {
        WallDirection[] allDirs = AllValidWallDirections;
        WallDirection   dir     = allDirs[Random.Range(0, allDirs.Length)];

        return(dir);
    }
示例#3
0
    Vector2 CalculateWallJumpVelocity(WallDirection wallDirection)
    {
        if (jumpInputManager.DetectInput(wallDirection))
        {
            Physics.gravity = new Vector3(0, zeroGravityAugment, 0);

            if (jumpInputManager.HoldTimer == 0 && wallDirection != WallDirection.None)
            {
                // Converts information about nearby walls into an integer multiplier for our x velocity.
                int xDir = ConvertXDirection(wallDirection);

                Vector2 newVelocity = new Vector3(xDir * jumpXVelocity, jumpCumulativeVelocity + playerBody.velocity.y);

                if (newVelocity.y < minJumpVelocity)
                {
                    newVelocity = new Vector3(xDir * jumpXVelocity, minJumpVelocity);
                }
                else if (newVelocity.y > maxJumpVelocity)
                {
                    newVelocity = new Vector3(xDir * jumpXVelocity, maxJumpVelocity);
                }

                return(newVelocity);
            }
        }
        else
        {
            Physics.gravity = new Vector3(0, standardGravityAugment, 0);
        }

        return(new Vector2(0, playerBody.velocity.y));
    }
示例#4
0
 public Wall(Position initialPosition, WallDirection direction, int length)
 {
     this.CurrentPosition = new Position(initialPosition.X, initialPosition.Y);
     this.Direction       = direction;
     this.Length          = length;
     ConstructBody(1, this.Length, this.Direction);
 }
示例#5
0
        private void ConstructBody(int width, int lenght, WallDirection direction)
        {
            int rowMax;
            int colMax;

            if (direction == WallDirection.Horizontal)
            {
                rowMax    = width;
                colMax    = lenght;
                this.Body = new char[rowMax, colMax];
            }
            else
            {
                rowMax    = lenght;
                colMax    = width;
                this.Body = new char[rowMax, colMax];
            }
            for (int row = 0; row < rowMax; row++)
            {
                for (int col = 0; col < colMax; col++)
                {
                    this.Body[row, col] = '█';
                }
            }
        }
示例#6
0
        public void UpdateWall(WallDirection direction)
        {
            wallsList[0].active = false;
            wallsList[0].wall.SetActive(false);
            wallsList[1].active = false;
            wallsList[1].wall.SetActive(false);

            switch (direction)
            {
            case WallDirection.ab:
                wallsList[0].active = true;
                wallsList[0].wall.SetActive(true);
                break;

            case WallDirection.bc:
                wallsList[1].active = true;
                wallsList[1].wall.SetActive(true);
                break;

            case WallDirection.all:
                wallsList[0].active = true;
                wallsList[0].wall.SetActive(true);
                wallsList[1].active = true;
                wallsList[1].wall.SetActive(true);
                break;
            }
            wallDirection = direction;
        }
    protected Vector2Int GetCellInDirection(Vector2Int cell, WallDirection wallDir)
    {
        switch (wallDir)
        {
        case WallDirection.North:
            cell.y += 1;
            break;

        case WallDirection.South:
            cell.y -= 1;
            break;

        case WallDirection.East:
            cell.x += 1;
            break;

        case WallDirection.West:
            cell.x -= 1;
            break;

        default:
            break;
        }
        return(cell);
    }
示例#8
0
 private void Start()
 {
     random = new System.Random();
     ///生成墙体边界
     for (int i = 0; i < sideLength; i++)
     {
         map[0, i] = true;
         Instantiate(wallBox01, new Vector3(0, i, 0), new Quaternion());
         map[sideLength - 1, i] = true;
         Instantiate(wallBox01, new Vector3(sideLength - 1, i, 0), new Quaternion());
     }
     for (int i = 1; i < sideLength - 1; i++)
     {
         map[i, 0] = true;
         Instantiate(wallBox01, new Vector3(i, 0, 0), new Quaternion());
         map[i, sideLength - 1] = true;
         Instantiate(wallBox01, new Vector3(i, sideLength - 1, 0), new Quaternion());
     }
     //创建障碍墙体
     while (curNumOfWall <= numOfWall)
     {
         int           x         = random.Next(1, sideLength - 1);
         int           y         = random.Next(1, sideLength - 1);
         WallDirection direction = random.Next(0, 2) == 1 ? WallDirection.Horizental : WallDirection.Vertical;
         int           wallNum   = random.Next(1, 6);
         CreatWall(x, y, wallNum, direction);
     }
 }
示例#9
0
    public override void Run()
    {
        base.Run();

        List <Vector2Int> queue = new List <Vector2Int>();

        queue.Add(cellOrigen);

        while (queue.Count > 0)
        {
            Vector2Int cellCurrent = queue[0];

            List <WallDirection> openDirections = GetCellOpenNeighbors(cellCurrent);

            if (openDirections.Count > 0)
            {
                openDirections.Shuffle();

                WallDirection direction = openDirections[0];

                Vector2Int cellTarget = GetCellInDirection(cellCurrent, direction);

                SetCellWall(cellCurrent, direction, false);

                SetCell(cellTarget, false);

                queue.Insert(0, cellTarget);
            }
            else
            {
                queue.RemoveAt(0);
            }
        }
    }
示例#10
0
 public Wall(Vector3 position, WallDirection direction, WallInfo info)
 {
     this.Length           = 1;
     this.Info             = info;
     this.buildingPosition = position;
     this.direction        = direction;
 }
    protected Vector2Int GetCellWallNode(Vector2Int cell, WallDirection wallDir)
    {
        Vector2Int nodeWall = CellToNode(cell);

        switch (wallDir)
        {
        case WallDirection.North:
            nodeWall.y += 1;
            break;

        case WallDirection.South:
            nodeWall.y -= 1;
            break;

        case WallDirection.East:
            nodeWall.x += 1;
            break;

        case WallDirection.West:
            nodeWall.x -= 1;
            break;

        default:
            break;
        }
        return(nodeWall);
    }
示例#12
0
        /// <summary>
        /// Erzeugt eine neue Isntanz einer Wande
        /// </summary>
        /// <param name="x">X Position der Wand</param>
        /// <param name="y">Y Position der Wand</param>
        /// <param name="length">So lang wird die Wand</param>
        /// <param name="direction">In diese Richtung besitzt die Wand die angegebene Länge</param>
        public MazeWall(int x, int y, int length, WallDirection direction)
        {
            // da es sich bei den Wänden beim Zeichnen um Rechtecke handeln wird, müssen
            // die Werte für die Ecken berechnet werden. Außerdem muss abhängig von der Richtung
            // die Länge und die Dicke den entsprechenden Eigenschaften zugeordnet werden
            switch (direction)
            {
            case WallDirection.Horizontal:
                // Bei einer horizontalen Wand entspricht Width der Länge. Es muss zusätzlich die Dicke
                // Addiert werden. Dadurch werden angrenzende Senkrechte Wände direkt angeschlossen.
                // Es ahndelt sich hierbei jedoch eher um eine kosmetische Anpassung
                Width  = length + Thickness;
                Height = Thickness;
                // Bei der Berechnung der Positionen ist zu beachten, dass die Position der Wandangegeben wurde.
                // Zum Zeichnen muss jedoch die Ecke angegeben werden. Deshalb muss in der Richtung, in der die
                // Wand nur die Dicke besitzt, die Eckposition so angepasst werden, dass sich die Mitte der Wand
                // an der angegebenen Position befindet. Ansonsten könnte es hier zu behinderungen an einer
                // Seite der Wand kommen.
                LeftCornerX = x - Thickness / 2 - 1;
                LeftCornerY = y;
                break;

            case WallDirection.Vertical:
                Width       = Thickness;
                Height      = length + Thickness;
                LeftCornerX = x - Thickness / 2 - 1;
                LeftCornerY = y;
                break;
            }
        }
示例#13
0
文件: Move.cs 项目: JJnova/Project_B
    // 수평 방향 벽 감지
    void CalculateHorizontal()
    {
        // Ray 간격
        float hRayOffset = boxCollider.size.y / (hRayCount - 1);
        // Ray 방향
        float xSign = moveVector.x <= 0 ? -1 : 1;

        if (moveVector.x == 0)
        {
            xSign = flip;
        }

        for (int i = 0; i < hRayCount; i++)
        {
            // Ray 발사 지점
            hRayOrigins[i] = new Vector3(xSign * height * 0.5f,
                                         hRayOffset * (i - hRayCount / 2) + moveVector.y);

            // 발사
            RaycastHit2D hit = Physics2D.Raycast(transform.position + hRayOrigins[i],
                                                 Vector2.right,
                                                 moveVector.x + bufferDist * xSign, // 현재 프레임에서 움직이는 거리 + 버퍼
                                                 ignoreLayer);

            // DEBUG
            Debug.DrawLine(transform.position + hRayOrigins[i],
                           transform.position + hRayOrigins[i] + new Vector3((moveVector.x + bufferDist * xSign), 0),
                           Color.yellow);

            // 벽에 닿음
            if (hit)
            {
                internalXSpeed = 0;

                // 이동 거리가 버퍼를 침범하는 경우
                if (Mathf.Abs(hit.distance - bufferDist) <= Mathf.Abs(moveVector.x))
                {
                    moveVector.x = (hit.distance - bufferDist) * xSign;
                }

                // 벽 슬라이딩
                if (isGrounded == false && xInput != 0)
                {
                    isOnWall = true;

                    if (xSign < 0)
                    {
                        wallDirection = WallDirection.LEFT;
                    }
                    else
                    {
                        wallDirection = WallDirection.RIGHT;
                    }
                }
            }
        }
    }
 protected void SetCellWall(Vector2Int cell, WallDirection wallDir, bool wall)
 {
     if (IsCellInBounds(GetCellInDirection(cell, wallDir)) == false)
     {
         Debug.LogError("Trying to set wall to out of bounds cell");
         return;
     }
     SetNode(GetCellWallNode(cell, wallDir), wall);
 }
示例#15
0
    public TileBase  GetWall(WallDirection direction)
    {
        switch (direction)
        {
        case WallDirection.North:
            return(NorthFacingWall);

        case WallDirection.Northwest:
            return(NorthwestFacingWall);

        case WallDirection.Northeast:
            return(NortheastFacingWall);

        case WallDirection.West:
            return(WestFacingWall);

        case WallDirection.East:
            return(EastFacingWall);

        case WallDirection.South:
            return(SouthFacingWall);

        case WallDirection.Southwest:
            return(SouthwestFacingWall);

        case WallDirection.Southeast:
            return(SoutheastFacingWall);

        case WallDirection.InnerNorthWest:
            return(InnerNorthWestFacingWall);

        case WallDirection.InnerNorthEast:
            return(InnerNorthEastFacingWall);

        case WallDirection.InnerSouthEast:
            return(InnerSouthEastFacingWall);

        case WallDirection.InnerSouthWest:
            return(InnerSouthWestFacingWall);

        case WallDirection.UpperLeftCorner:
            return(UpperLeftCorner);

        case WallDirection.UpperRightCorner:
            return(UpperRightCorner);

        case WallDirection.LowerRightCorner:
            return(LowerRightCorner);

        case WallDirection.LowerLeftCorner:
            return(LowerLeftCorner);

        default:
            return(null);
        }
    }
示例#16
0
    void SpawnRandomWall()
    {
        float         rand = Random.Range(0.0f, 1.0f);
        WallDirection dir  = rand < 0.5f ? WallDirection.xAxis : WallDirection.zAxis;

        int randX = Random.Range(0, gridWidth);
        int randZ = Random.Range(0, gridHeight);

        SpawnWall(randX, randZ, dir);
    }
示例#17
0
 public Wall(WallDirection direction, Cell topOrLeftCell, Cell bottomOrRightCell, float point1X, float point1Y, float point2X, float point2Y)
 {
     this.direction         = direction;
     this.topOrLeftCell     = topOrLeftCell;
     this.bottomOrRightCell = bottomOrRightCell;
     this.point1X           = point1X;
     this.point1Y           = point1Y;
     this.point2X           = point2X;
     this.point2Y           = point2Y;
 }
示例#18
0
 private void FixedUpdate()
 {
     if (detectWalls != null)
     {
         currentWalls = detectWalls();
     }
     else
     {
         Debug.LogWarning("detectWalls Delegate has no functionality assigned to it.");
     }
 }
示例#19
0
 void SetWallSprite(WallDirection wallDirection)
 {
     foreach (var wallSprite in WallSprites)
     {
         if (wallDirection.Equals(wallSprite.WallDirection))
         {
             SpriteRenderer.sprite = wallSprite.Sprite;
             break;
         }
     }
 }
示例#20
0
    Vector2 CalculateWallJumpVelocity(WallDirection wallDirection)
    {
        // Player started on ground, and intentionally pressed jump again when on the ground
        if (Input.GetButtonDown("Jump"))
        {
            currentHoldTime  = 0;
            lastJumpReleased = false;
            Physics.gravity  = new Vector3(0, gravity * gravityAugment, 0);
            characterController.PrioritiseWallJump = true;
        }

        if (Input.GetButtonUp("Jump"))
        {
            lastJumpReleased = true;

            characterController.PrioritiseWallJump = false;

            currentHoldTime = 0;
        }

        // Player still has some airtime left, and they're still holding Jump down
        if (currentHoldTime < maxHoldTime && !lastJumpReleased)
        {
            // Implies this is the first frame after the jump
            if (currentHoldTime == 0)
            {
                // So we give a little horizontal kick off of the relevant wall
                if (wallDirection == WallDirection.Left)
                {
                    wallJumpVelocity = new Vector2(jumpXVelocity, jumpVelocity);
                }
                else if (wallDirection == WallDirection.Right)
                {
                    wallJumpVelocity = new Vector2(-jumpXVelocity, jumpVelocity);
                }
            }
            else
            {
                wallJumpVelocity = new Vector2(0, jumpVelocity);
            }

            currentHoldTime += Time.deltaTime;
            //lastKnownWall = wallDirection;

            return(wallJumpVelocity);
        }
        // Player has exceeded max hold time - so we no longer increase the Y Velocity
        else
        {
            Physics.gravity = new Vector3(0, gravity, 0);
            //lastKnownWall = wallDirection;
            return(new Vector2(0, playerBody.velocity.y));
        }
    }
示例#21
0
    private void SetTurnParams(Transform box)
    {
        float offsetY = (box.localScale.y + transform.localScale.y) * 0.5f;

        wallDirection = box.GetComponent <SCR_Box>().wallDirection;
        turnDirection = box.GetComponent <SCR_Corner>().turnDirection;

        float directionSign = 0;

        if (turnDirection == TurnDirection.LEFT)
        {
            directionSign = -1;
        }
        if (turnDirection == TurnDirection.RIGHT)
        {
            directionSign = 1;
        }

        if (wallDirection == WallDirection.NEGATIVE_X)
        {
            turnRadius = box.localScale.z * 0.5f;
            turnStart  = new Vector3(box.position.x + box.localScale.x * 0.5f - turnRadius, box.position.y + offsetY, box.position.z);

            turnCenter = new Vector3(box.position.x + box.localScale.x * 0.5f - turnRadius, box.position.y + offsetY, box.position.z - turnRadius * directionSign);
            turnEnd    = new Vector3(box.position.x + box.localScale.x * 0.5f, box.position.y + offsetY, box.position.z - turnRadius * directionSign);
        }

        if (wallDirection == WallDirection.POSITIVE_Z)
        {
            turnRadius = box.localScale.x * 0.5f;
            turnStart  = new Vector3(box.position.x, box.position.y + offsetY, box.position.z - box.localScale.z * 0.5f + turnRadius);

            turnCenter = new Vector3(box.position.x - turnRadius * directionSign, box.position.y + offsetY, box.position.z - box.localScale.z * 0.5f + turnRadius);
            turnEnd    = new Vector3(box.position.x - turnRadius * directionSign, box.position.y + offsetY, box.position.z - box.localScale.z * 0.5f);
        }

        if (wallDirection == WallDirection.POSITIVE_X)
        {
            turnRadius = box.localScale.z * 0.5f;
            turnStart  = new Vector3(box.position.x - box.localScale.x * 0.5f + turnRadius, box.position.y + offsetY, box.position.z);

            turnCenter = new Vector3(box.position.x - box.localScale.x * 0.5f + turnRadius, box.position.y + offsetY, box.position.z + turnRadius * directionSign);
            turnEnd    = new Vector3(box.position.x - box.localScale.x * 0.5f, box.position.y + offsetY, box.position.z + turnRadius * directionSign);
        }

        if (wallDirection == WallDirection.NEGATIVE_Z)
        {
            turnRadius = box.localScale.x * 0.5f;
            turnStart  = new Vector3(box.position.x, box.position.y + offsetY, box.position.z + box.localScale.z * 0.5f - turnRadius);

            turnCenter = new Vector3(box.position.x + turnRadius * directionSign, box.position.y + offsetY, box.position.z + box.localScale.z * 0.5f - turnRadius);
            turnEnd    = new Vector3(box.position.x + turnRadius * directionSign, box.position.y + offsetY, box.position.z + box.localScale.z * 0.5f);
        }
    }
示例#22
0
    bool CheckWallHold(WallDirection wallDirection, float xInput)
    {
        /*if (lockedOntoWall != WallDirection.None)
         * {
         *  // First we check if the player is still near a wall in the correct direction
         *  if (lockedOntoWall != wallDirection)
         *  {
         *      lockedOntoWall = WallDirection.None;
         *      return false;
         *  }
         *  // We then check if the xInput of the player is in the opposite direction of the wall they're locked onto
         *  else if ((xInput > 0 && wallDirection == WallDirection.Left) || (xInput < 0 && wallDirection == WallDirection.Right))
         *  {
         *      lockedOntoWall = WallDirection.None;
         *      return false;
         *  }
         *  // We check if the player jumped off the wall
         *  else if (Input.GetButtonDown("Jump"))
         *  {
         *      lockedOntoWall = WallDirection.None;
         *      return false;
         *  }
         *  // And if none of that has happened, they must still be on the wall!
         *  else
         *  {
         *      return true;
         *  }
         * }
         * else
         * {
         *  // We check if the xInput of the player is in the same direction as a nearby wall
         *  if ((xInput < 0 && wallDirection == WallDirection.Left) || (xInput > 0 && wallDirection == WallDirection.Right))
         *  {
         *      lockedOntoWall = wallDirection;
         *      return true;
         *  }
         *  else
         *  {
         *      return false;
         *  }
         * }*/


        // We check if the xInput of the player is in the same direction as a nearby wall
        if ((xInput < 0 && wallDirection == WallDirection.Left) || (xInput > 0 && wallDirection == WallDirection.Right))
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
示例#23
0
文件: Move.cs 项目: JJnova/Project_B
    void CalculateMove()
    {
        wallDirection = WallDirection.NONE;
        isGrounded    = false;
        isOnWall      = false;

        // Vertical
        CalculateVertical();

        // Horizontal
        CalculateHorizontal();
    }
示例#24
0
 public void ToggleDirection()
 {
     if (selectedDirection == WallDirection.xAxis)
     {
         selectedDirection = WallDirection.zAxis;
         GameObject.Find("ToggleButton").GetComponent <Image>().sprite = zAxisSprite;
     }
     else
     {
         selectedDirection = WallDirection.xAxis;
         GameObject.Find("ToggleButton").GetComponent <Image>().sprite = xAxisSprite;
     }
 }
示例#25
0
        public void AddWallDirection(Vector2Int coords, WallDirection direction, bool isDestructible)
        {
            if (_walls[coords.x, coords.y] == null)
            {
                _walls[coords.x, coords.y] = new List <WallDirection>();
            }

            if (!_walls[coords.x, coords.y].Contains(direction))
            {
                _walls[coords.x, coords.y].Add(direction);
            }

            _isDestructible[coords.x, coords.y] &= isDestructible;
        }
示例#26
0
        /// <summary>
        /// Casts a capsule to find a wall on right or left
        /// </summary>
        /// <returns></returns>
        private bool FoundWall()
        {
            if (m_System.ActiveAbility == m_ClimbJump)// && (m_Engine.LastAbility is ThirdPersonAbstractClimbing || m_Engine.LastAbility is LadderAbility))
            {
                if (m_ClimbJump.JumpType == ClimbJumpType.Right ||
                    m_ClimbJump.JumpType == ClimbJumpType.Left)
                {
                    RaycastHit forwardHit;
                    if (CastSide(out forwardHit, transform.forward, transform.right))
                    {
                        wallHit       = forwardHit;
                        wallDirection = m_ClimbJump.JumpType == ClimbJumpType.Right ?
                                        WallDirection.Left : WallDirection.Right;

                        return(true);
                    }
                }
                else
                {
                    return(false);
                }
            }

            RaycastHit leftHit;

            if (CastSide(out leftHit, -transform.right))
            {
                wallHit = leftHit;
                if (!Active)
                {
                    wallDirection = WallDirection.Left;
                }
                return(true);
            }

            RaycastHit rightHit;

            if (CastSide(out rightHit, transform.right))
            {
                wallHit = rightHit;
                if (!Active)
                {
                    wallDirection = WallDirection.Right;
                }
                return(true);
            }

            return(false);
        }
示例#27
0
    void ShowGhostWall(int x, int z, WallDirection dir)
    {
        if (dir == WallDirection.zAxis)
        {
            ghostWall.transform.localPosition = GetLocalPosFromGridPos(x, gridHeight / 2, 0.5f);
            ghostWall.transform.rotation      = Quaternion.Euler(0.0f, 90.0f, 0.0f);
        }
        else
        {
            ghostWall.transform.localPosition = GetLocalPosFromGridPos(gridWidth / 2, z, 0.5f);
            ghostWall.transform.rotation      = Quaternion.Euler(0.0f, 0.0f, 0.0f);
        }

        ghostWall.SetActive(true);
    }
示例#28
0
    public void SetWallTypeForDirection(WallDirection direction, WallType type)
    {
        switch (direction)
        {
        case WallDirection.North: northWallType = type; break;

        case WallDirection.East: eastWallType = type; break;

        case WallDirection.South: southWallType = type; break;

        case WallDirection.West: westWallType = type; break;

        default: break;
        }
    }
示例#29
0
    /// <summary>
    /// Considers the nearby walls and either returns 1 or -1. This int describes the direction the character needs to jump in.
    /// </summary>
    /// <param name="wallDirection">The position of the wall the character is jumping off of, relative to the player.</param>
    /// <returns>Either 1 or -1, depending on the direction the player needs to jump in response.</returns>
    int ConvertXDirection(WallDirection wallDirection)
    {
        if (wallDirection == WallDirection.Left)
        {
            // Character must jump right off of a wall on their left.
            return(1);
        }
        else if (wallDirection == WallDirection.Right)
        {
            // Character must jump left off of a wall on their right.
            return(-1);
        }

        return(0);
    }
示例#30
0
    WallDirection DetermineWallDirection()
    {
        RaycastHit2D hitTop    = Physics2D.Raycast(transform.position, Vector2.up, 1);
        RaycastHit2D hitRight  = Physics2D.Raycast(transform.position, Vector2.right, 1);
        RaycastHit2D hitBottom = Physics2D.Raycast(transform.position, Vector2.down, 1);
        RaycastHit2D hitLeft   = Physics2D.Raycast(transform.position, Vector2.left, 1);

        WallDirection wallDirection = new WallDirection()
        {
            Up    = hitTop.collider != null && hitTop.collider.GetComponent <WallController>() != null,
            Right = hitRight.collider != null && hitRight.collider.GetComponent <WallController>() != null,
            Down  = hitBottom.collider != null && hitBottom.collider.GetComponent <WallController>() != null,
            Left  = hitLeft.collider != null && hitLeft.collider.GetComponent <WallController>() != null
        };

        return(wallDirection);
    }
示例#31
0
 public WallCollider(Vector2 pos, WallDirection dir)
 {
     position = pos;
     direction = dir;
 }
示例#32
0
 public WallNode(int pos, WallDirection dir)
     : base()
 {
     this.Intialize(pos, dir);
 }
示例#33
0
 private void Intialize(int pos, WallDirection dir)
 {
     position = pos;
     orientation = dir;
 }