/**
     * <summary>
     * Generate bottom chunk
     * </summary>
     *
     * <returns>
     * GameObject
     * </returns>
     */
    public GameObject GenerateBottomChunk()
    {
        Vector3 referencePosition = new Vector3(
            this.transform.position.x - 100,
            this.transform.position.y,
            this.transform.position.z - 100
            );

        GameObject chunk = MonoBehaviour.Instantiate(
            Resources.Load("Prefabs/Map/Map Generator") as GameObject,
            referencePosition,
            Quaternion.identity
            );

        Vector2 initPosition = new Vector2(
            referencePosition.x,
            referencePosition.z
            );

        ProceduralMapGenerator chunkGenerator = chunk.GetComponent <ProceduralMapGenerator>();

        chunkGenerator.Generate(initPosition);

        return(chunk);
    }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        ProceduralMapGenerator gen = (ProceduralMapGenerator)target;

        if (GUILayout.Button("Generate new map"))
        {
            gen.Initialize();
        }
    }
Пример #3
0
    // Initialzing some variables and calling various methods
    public void PopulateMap()
    {
        mapData   = GetComponent <ProceduralMapGenerator>();
        distances = mapData.distances;
        vertices  = mapData.vertices;

        // Populates the dungeon with each item at a time.
        OrientMap();
        SpawnPlayer();
        SpawnSkeletons();
        SpawnKeysAndDoors();
        SpawnSkeletrax();
        SpawnHealth();
        SpawnSpikes();
    }
Пример #4
0
    private void Start()
    {
        _generator = GameObject.FindGameObjectWithTag("MapGenerator").GetComponent <ProceduralMapGenerator>();
        _menuAnimator.GetComponentInChildren <Animator>();

        _menuAnimator.SetBool("Enabled", true);
        _panelArrow.rotation = Quaternion.Euler(new Vector3(0, 0, -90));

        // Make sure text changes when the slider does
        _mapLengthSlider.onValueChanged.AddListener(delegate { SetSliderText(_mapLengthSlider, _mapLengthText); });
        _maxHeightSlider.onValueChanged.AddListener(delegate { SetSliderText(_maxHeightSlider, _maxHeightText); });
        _maxDepthSlider.onValueChanged.AddListener(delegate { SetSliderText(_maxDepthSlider, _maxDepthText); });
        _levelHeightSlider.onValueChanged.AddListener(delegate { SetSliderText(_levelHeightSlider, _levelHeightText); });


        SetSliderText(_mapLengthSlider, _mapLengthText);
        SetSliderText(_maxHeightSlider, _maxHeightText);
        SetSliderText(_maxDepthSlider, _maxDepthText);
        SetSliderText(_levelHeightSlider, _levelHeightText);
    }
        // Method that creates a rectangular room within the leaf.
        public void CreateRooms(ProceduralMapGenerator bspTree)
        {
            if (child1 != null || child2 != null)
            {
                if (child1 != null)
                {
                    child1.CreateRooms(bspTree);
                }
                if (child2 != null)
                {
                    child2.CreateRooms(bspTree);
                }
            }
            else
            {
                int w = Mathf.RoundToInt(Random.Range(min_width, Mathf.Min(bspTree.maxRoomSize, this.width - 2))) - 3;
                int h = Mathf.RoundToInt(Random.Range(min_height, Mathf.Min(bspTree.maxRoomSize, this.height - 2))) - 3;
                int x = Mathf.RoundToInt(Random.Range(this.x, this.x + (this.width - 2) - w)) + 2;
                int y = Mathf.RoundToInt(Random.Range(this.y, this.y + (this.height - 2) - h)) + 2;

                this.room = new RectInt(x, y, w, h);
                bspTree.CreateRoom(this.room);
            }
        }
Пример #6
0
 private void Start()
 {
     _cam       = GetComponent <Camera>();
     _generator = GameObject.FindGameObjectWithTag("MapGenerator").GetComponent <ProceduralMapGenerator>();
 }
Пример #7
0
    /**
     * <summary>
     * Watch neighbours based on
     * top left, top right, bottom left,
     * bottom right, top, left, bottom and right.
     * </summary>
     *
     * <returns>
     * void
     * </returns>
     */
    public void WatchNeighbours()
    {
        if (this.GetCenterChunk())
        {
            ProceduralMapGenerator mapGeneratorBehaviour = this.GetCenterChunk()
                                                           .GetComponent <ProceduralMapGenerator>();

            int x = (int)mapGeneratorBehaviour.GetPosition().x;
            int y = (int)mapGeneratorBehaviour.GetPosition().y;

            // Vertical
            if (!TilesManager.Chunks.ContainsKey(x))
            {
                TilesManager.Chunks[x] = new Dictionary <int, GameObject>();
            }

            if (!TilesManager.Chunks.ContainsKey(x + 1))
            {
                TilesManager.Chunks[x + 1] = new Dictionary <int, GameObject>();
            }

            if (!TilesManager.Chunks.ContainsKey(x - 1))
            {
                TilesManager.Chunks[x - 1] = new Dictionary <int, GameObject>();
            }

            // Center
            this.activeTiles[4] = this.GetCenterChunk();

            // Top Left
            if (!TilesManager.Chunks[x].ContainsKey(y + 1))
            {
                Vector2 position = new Vector2(x, y + 1);

                GameObject topLeft = mapGeneratorBehaviour.GenerateTopLeftChunk();
                topLeft.GetComponent <ProceduralMapGenerator>().SetPosition(position);

                TilesManager.Chunks[x][y + 1] = topLeft;
            }
            // Show top left tiles if exists
            else
            {
                GameObject topLeft = TilesManager.Chunks[x][y + 1];

                // Top left
                this.activeTiles[0] = topLeft;
            }

            // Bottom Right
            if (!TilesManager.Chunks[x].ContainsKey(y - 1))
            {
                Vector2 position = new Vector2(x, y - 1);

                GameObject bottomRight = mapGeneratorBehaviour.GenerateBottomRightChunk();
                bottomRight.GetComponent <ProceduralMapGenerator>().SetPosition(position);
                TilesManager.Chunks[x][y - 1] = bottomRight;
            }
            // Show bottom right tiles if exists
            else
            {
                GameObject bottomRight = TilesManager.Chunks[x][y - 1];

                // Bottom right
                this.activeTiles[8] = bottomRight;
            }

            // Top Right
            if (!TilesManager.Chunks[x + 1].ContainsKey(y))
            {
                Vector2 position = new Vector2(x + 1, y);

                GameObject topRight = mapGeneratorBehaviour.GenerateTopRightChunk();
                topRight.GetComponent <ProceduralMapGenerator>().SetPosition(position);
                TilesManager.Chunks[x + 1][y] = topRight;
            }
            // Show top right tiles if exists
            else
            {
                GameObject topRight = TilesManager.Chunks[x + 1][y];

                // Top right
                this.activeTiles[2] = topRight;
            }

            // Bottom Left
            if (!TilesManager.Chunks[x - 1].ContainsKey(y))
            {
                Vector2 position = new Vector2(x - 1, y);

                GameObject bottomLeft = mapGeneratorBehaviour.GenerateBottomLeftChunk();
                bottomLeft.GetComponent <ProceduralMapGenerator>().SetPosition(position);
                TilesManager.Chunks[x - 1][y] = bottomLeft;
            }
            // Show bottom left tiles if exists
            else
            {
                GameObject bottomLeft = TilesManager.Chunks[x - 1][y];

                // Bottom left
                this.activeTiles[6] = bottomLeft;
            }

            // Left
            if (!TilesManager.Chunks[x - 1].ContainsKey(y + 1))
            {
                Vector2 position = new Vector2(x - 1, y + 1);

                GameObject left = mapGeneratorBehaviour.GenerateLeftChunk();
                left.GetComponent <ProceduralMapGenerator>().SetPosition(position);
                TilesManager.Chunks[x - 1][y + 1] = left;
            }
            // Show left tiles if exists
            else
            {
                GameObject left = TilesManager.Chunks[x - 1][y + 1];

                // Left
                this.activeTiles[3] = left;
            }

            // Right
            if (!TilesManager.Chunks[x + 1].ContainsKey(y - 1))
            {
                Vector2 position = new Vector2(x + 1, y - 1);

                GameObject right = mapGeneratorBehaviour.GenerateRightChunk();
                right.GetComponent <ProceduralMapGenerator>().SetPosition(position);
                TilesManager.Chunks[x + 1][y - 1] = right;
            }
            // Show right tiles if exists
            else
            {
                GameObject right = TilesManager.Chunks[x + 1][y - 1];

                // Right
                this.activeTiles[5] = right;
            }

            // Bottom
            if (!TilesManager.Chunks[x - 1].ContainsKey(y - 1))
            {
                Vector2 position = new Vector2(x - 1, y - 1);

                GameObject bottom = mapGeneratorBehaviour.GenerateBottomChunk();
                bottom.GetComponent <ProceduralMapGenerator>().SetPosition(position);
                TilesManager.Chunks[x - 1][y - 1] = bottom;
            }
            // Show bottom tiles if exists
            else
            {
                GameObject bottom = TilesManager.Chunks[x - 1][y - 1];

                // Bottom
                this.activeTiles[7] = bottom;
            }

            // Top
            if (!TilesManager.Chunks[x + 1].ContainsKey(y + 1))
            {
                Vector2 position = new Vector2(x + 1, y + 1);

                GameObject top = mapGeneratorBehaviour.GenerateTopChunk();
                top.GetComponent <ProceduralMapGenerator>().SetPosition(position);
                TilesManager.Chunks[x + 1][y + 1] = top;
            }
            // Show top tiles if exists
            else
            {
                GameObject top = TilesManager.Chunks[x + 1][y + 1];

                // Top
                this.activeTiles[1] = top;
            }
        }
    }