Example #1
0
    private void SpawnWalls(int width, int height)
    {
        for (int i = 0; i < height; i++)                // Spawn Vertical Walls
        {
            for (int j = 0; j < width - 1; j++)
            {
                WallStruct newWall = new WallStruct
                {
                    firstAdjacentNode  = nodes[i, j],
                    secondAdjacentNode = nodes[i, j + 1],
                    gameObject         = BuildWall(i, j, Side.Right),
                    horizontal         = false
                };

                walls.Add(newWall);
            }
        }

        for (int i = 0; i < height - 1; i++)                // Spawn Horizontal Walls
        {
            for (int j = 0; j < width; j++)
            {
                WallStruct newWall = new WallStruct
                {
                    firstAdjacentNode  = nodes[i, j],
                    secondAdjacentNode = nodes[i + 1, j],
                    gameObject         = BuildWall(i, j, Side.Down),
                    horizontal         = true
                };

                walls.Add(newWall);
            }
        }
    }
Example #2
0
            public static WallStruct CreateWallStruct(ref FileStruct.TSWedWall tsWedWall)
            {
                WallStruct ss = new WallStruct();

                ss.wallPoly = new PolygonStruct[tsWedWall.wallPolyRefCount];
                return(ss);
            }
Example #3
0
 void UpdateWallStatus(WallStruct wallStruct)
 {
     if (wallStruct.parentObj != null)
     {
         Destroy(wallStruct.parentObj.transform.GetChild(wallStruct.isDoor ? 0 : 1).gameObject);
     }
 }
Example #4
0
 private void DeconstructWall(WallStruct wall)
 {
     Destroy(wall.gameObject);
     if (wall.horizontal)
     {
         wall.firstAdjacentNode.GetComponent <Node>().RemoveWall(Side.Down);
         wall.secondAdjacentNode.GetComponent <Node>().RemoveWall(Side.Up);
     }
     else
     {
         wall.firstAdjacentNode.GetComponent <Node>().RemoveWall(Side.Right);
         wall.secondAdjacentNode.GetComponent <Node>().RemoveWall(Side.Left);
     }
 }
Example #5
0
    public void OnClickApply(float noise, float competenceValue)
    {
        int w = 0;

        while (w < wallStructList.Count)
        {
            WallStruct W = wallStructList [w];
            Destroy(W.wall);
            w++;
        }
        wallStructList.Clear();

        GenerateNewWalls(noise, competenceValue);
    }
Example #6
0
    public void GenerateMaze(NodesModel nodesModel)
    {
        ResetMap();

        GenerateOuterWalls(nodesModel.width, nodesModel.height);

        UnpackNodesModel(nodesModel);

        player.transform.position = startNode.transform.position;
        finish.transform.position = finishNode.transform.position;
        player.GetComponent <PlayerMovement>().currI = startNode.GetComponent <Node>().i;
        player.GetComponent <PlayerMovement>().currJ = startNode.GetComponent <Node>().j;

        for (int i = 0; i < nodesModel.height; i++)                // Spawn Vertical Walls
        {
            for (int j = 0; j < nodesModel.width - 1; j++)
            {
                if (nodesModel.walls[i, j, 1])
                {
                    WallStruct newWall = new WallStruct
                    {
                        firstAdjacentNode  = nodes[i, j],
                        secondAdjacentNode = nodes[i, j + 1],
                        gameObject         = BuildWall(i, j, Side.Right),
                        horizontal         = false
                    };

                    walls.Add(newWall);
                }
            }
        }

        for (int i = 0; i < nodesModel.height - 1; i++)                // Spawn Horizontal Walls
        {
            for (int j = 0; j < nodesModel.width; j++)
            {
                if (nodesModel.walls[i, j, 3])
                {
                    WallStruct newWall = new WallStruct
                    {
                        firstAdjacentNode  = nodes[i, j],
                        secondAdjacentNode = nodes[i + 1, j],
                        gameObject         = BuildWall(i, j, Side.Down),
                        horizontal         = true
                    };

                    walls.Add(newWall);
                }
            }
        }

        List <GameObject> list = new List <GameObject>();           // Assign every node to one set

        for (int i = 0; i < nodes.GetLength(0); i++)
        {
            for (int j = 0; j < nodes.GetLength(1); j++)
            {
                list.Add(nodes[i, j]);
            }
        }
        sets.Add(0, list);
        UpdateNodesSetNumbers(sets);

        if (Utilities.ShowConstruction)
        {
            StartCoroutine(Step());
        }
        else
        {
            foreach (var wall in walls)
            {
                if (wall.firstAdjacentNode.GetComponent <Node>().setNumber != wall.secondAdjacentNode.GetComponent <Node>().setNumber)
                {
                    sets[wall.firstAdjacentNode.GetComponent <Node>().setNumber].AddRange(sets[wall.secondAdjacentNode.GetComponent <Node>().setNumber]);
                    sets.Remove(wall.secondAdjacentNode.GetComponent <Node>().setNumber);
                    UpdateNodesSetNumbers(sets);
                    DeconstructWall(wall);
                }
            }
            mapIsGenerated = true;
        }

        PushNeighbors();
    }
Example #7
0
    void GenerateNewWalls(float noise, float competenceValue)
    {
        totalBrickHeight = 0;
        //brickStackLimit should be a function of competence slider.
        float tempBrickStackLimit = brickStackLimit * competenceValue;

        tempBrickStackLimit = Mathf.CeilToInt(tempBrickStackLimit);
        brickHeight         = brick.GetComponent <SpriteRenderer> ().sprite.bounds.size.y *brick.transform.localScale.y;
        float brickWidthExtent = brick.GetComponent <BoxCollider2D> ().bounds.extents.x;



        GameObject tempBrick = null;

        brickX = UnityEngine.Random.Range(leftBound.transform.position.x + 5f, leftBound.transform.position.x + 10f);

        //"i" limit should depend on competence
        int iCount = Mathf.CeilToInt(competenceValue * 5) * GlobalConstants.levelLength;

        //Debug.Log (competenceValue + " slider ");
        //Debug.Log (iCount + " i Count");
        for (int i = 1; i <= iCount; i++)
        {
            //brickX = brickX + UnityEngine.Random.Range (5, 15);
            brickX = brickX + noise * 10f;
            //Debug.Log ("platorm end count"+platformSpawner.platformEndsList.Count);
            bool brickPopulationFlag = true;

            for (int g = 0; g < platformSpawner.platformEndsList.Count; g += 2)
            {
                Transform currentTransform = platformSpawner.platformEndsList [g];

                float platformGapLeftBound  = currentTransform.position.x;
                float platformGapRightBound = platformSpawner.platformEndsList [g + 1].position.x;
                //Debug.Log ("platfrom left index " + g + " gap left start " + platformGapLeftBound);
                //Debug.Log ("platfrom right index " + g + 1 + " gap right start " + platformGapRightBound);
                //currentTransform.gameObject.GetComponent<BoxCollider2D>().bounds.extents.x
                if ((brickX > platformGapLeftBound && brickX < platformGapRightBound) ||
                    (brickX + brickWidthExtent > platformGapLeftBound && brickX + brickWidthExtent < platformGapRightBound) ||
                    (brickX - brickWidthExtent > platformGapLeftBound && brickX - brickWidthExtent < platformGapRightBound))
                {
                    //Debug.Log ("do not populate");
                    brickPopulationFlag = false;
                    break;
                    //do not populate
                }
            }

            if (brickPopulationFlag)
            {
                int brickStackHeight = UnityEngine.Random.Range(0, Mathf.CeilToInt(tempBrickStackLimit));

                GameObject wall = new GameObject();
                WallStruct W    = new WallStruct(wall, brickStackHeight);
                for (int j = 1; j <= brickStackHeight; j++)
                {
                    tempBrick = GameObject.Instantiate(brick);
                    Vector3 initialPosition = new Vector3(brickX, GlobalConstants.bankHeight + (j - 1) * brickHeight);
                    tempBrick.transform.position = initialPosition;
                    tempBrick.transform.parent   = W.wall.transform;
                    totalBrickHeight             = totalBrickHeight + brickHeight;
                }
                if (tempBrick != null)
                {
                    GameObject tempTop            = GameObject.Instantiate(top);
                    Vector3    initialTopPosition = new Vector3(tempBrick.transform.position.x, tempBrick.transform.position.y + brickHeight);
                    tempTop.transform.position = initialTopPosition;
                    tempTop.transform.parent   = W.wall.transform;
                }

                wallStructList.Add(W);
                brickPopulationFlag = true;
            }
        }
        //Debug.Log ("total brick Height" + totalBrickHeight);
    }