generateMap() private method

private generateMap ( int sizeX, int sizeZ, int squaresToGenerate, GameObject player, GameObject player2 ) : ].int[
sizeX int
sizeZ int
squaresToGenerate int
player GameObject
player2 GameObject
return ].int[
Ejemplo n.º 1
0
    /*
     * with the tile array created, this will instantiate all the different tile types on the screen
     * */
    void GenerateMapVisuals()
    {
        mapGenerator.generateMap(tiles);
        GameObject mapParent = (GameObject)Instantiate(new GameObject("MapParent"));

        for (int x = 0; x < mapSizeX; x++)
        {
            for (int y = 0; y < mapSizeY; y++)
            {
                TileType   tt = tileTypes [tiles [x, y]];
                GameObject go = (GameObject)Instantiate(tt.tilePrefab, new Vector3(x, y, 0), Quaternion.identity);
                go.name             = tt.name + " " + x + " " + y;
                go.transform.parent = mapParent.transform;
                TilePositions tp = go.GetComponent <TilePositions> ();
                tp.tileX = x;
                tp.tileY = y;
            }
        }
        // add the newly generated map to the list of the total map
        MapCoordinates newMap = new MapCoordinates(mapParent, playerTotalPositionX, playerTotalPositionY);

        mapCoordinates.Add(newMap);
        System.Random rand = new System.Random();

        // spawn all enemies here
        // instantiate the enemy and save as game object
        for (int i = 0; i < maxEnemies; i++)
        {
            for (int j = 0; j < enemyArray.Length; j++)
            {
                int randomX = rand.Next(0, mapSizeX);
                int randomY = rand.Next(0, mapSizeY);
                // enemies will spawn on a random tile in the map
                if (tileTypes [tiles [randomX, randomY]].isWalkable && (randomX != player.transform.position.x && randomY != player.transform.position.y))
                {
                    GameObject enemySpawn = (GameObject)Instantiate(enemyArray [j], new Vector3(randomX, randomY, 0), Quaternion.identity);
                    enemy.Add(enemySpawn);
                    enemySpawn.transform.parent = mapParent.transform;
                }
                else
                {
                    j--;
                }
            }
        }
        numberOfEnemies = enemy.Count;
        GeneratePathfindingGraph();
        for (int i = 0; i < pickupList.Count(); i++)
        {
            int randomX = rand.Next(0, mapSizeX);
            int randomY = rand.Next(0, mapSizeY);
            if (tileTypes [tiles [randomX, randomY]].isWalkable && (randomX != player.transform.position.x && randomY != player.transform.position.y))
            {
                GameObject item = (GameObject)Instantiate(pickupList.ElementAt(i), new Vector3(randomX, randomY, -0.5f), Quaternion.identity);
                item.transform.parent = mapParent.transform;
            }
            else
            {
                i--;
            }
        }
    }