Exemple #1
0
 public void SpawnPotion(TileMapData map, int x, int y, float z) //x and y of tile
 {
     if (map.GetTileAt(x - 1, y) == eTile.Floor)
     {
         Instantiate(Potion, new Vector3(x - 1, y, z), Quaternion.identity);
     }
     else if (map.GetTileAt(x + 1, y) == eTile.Floor)
     {
         Instantiate(Potion, new Vector3(x + 1, y, z), Quaternion.identity);
     }
 }
 public void OccupyTiles(BaseBuilding _building, Vector3 _vec)
 {
     for (int x = 0; x < _building.sizeX; x++)
     {
         for (int y = 0; y < _building.sizeY; y++)
         {
             TileData tData = tileMapData.GetTileAt((int)(_vec.z + y), (int)(_vec.x + x));
             tData.SetBuilding(_building);
         }
     }
 }
Exemple #3
0
    public static void SpawnItem(TileMapData map, GameObject Item)
    {
        int countItems = 0;

        while (countItems < 1)
        {
            int     x = Random.Range(0, map.mapData.GetLength(0)), y = Random.Range(0, map.mapData.GetLength(1));
            Vector3 tilePos = new Vector3(x, y, 0);
            if (map.GetTileAt(x, y).Equals(eTile.Floor))
            {
                Instantiate(Item, tilePos, Quaternion.identity);
                countItems++;
            }
        }
    }
Exemple #4
0
    public static void SpawnEnemies(TileMapData map, int numEnemies, GameObject Enemy, GameObject Player)
    {
        int countEnemies = 0;
        int buffer       = 5;

        while (countEnemies < numEnemies)
        {
            int     x = Random.Range(0, map.mapData.GetLength(0)), y = Random.Range(0, map.mapData.GetLength(1));
            Vector3 tilePos = new Vector3(x, y, 0);
            if (map.GetTileAt(x, y).Equals(eTile.Floor) && (x < Player.transform.position.x - buffer || x > Player.transform.position.x + buffer || y < Player.transform.position.y - buffer || y > Player.transform.position.y + buffer))
            {
                Instantiate(Enemy, tilePos, Quaternion.identity);
                countEnemies++;
            }
        }
    }
Exemple #5
0
    public void MoveMap(TileMapData tmd)
    {
        TileMapData map = tmd;
        int         floorIndex = 0, wallIndex = 0;

        GameObject[] activeFloorTiles = GameObject.FindGameObjectsWithTag("Floor");
        GameObject[] activeWallTiles  = GameObject.FindGameObjectsWithTag("Wall");

        foreach (GameObject tile in activeFloorTiles)
        {
            tile.GetComponent <TileSetChanger>().setTile(map.set);
        }
        foreach (GameObject tile in activeWallTiles)
        {
            tile.GetComponent <TileSetChanger>().setTile(map.set);
        }

        if (activeFloorTiles.Length > maxFloors)
        {
            maxFloors = activeFloorTiles.Length;
        }
        if (activeWallTiles.Length > maxWalls)
        {
            maxWalls = activeWallTiles.Length;
        }
        GameObject[] allFloorTiles = new GameObject[maxFloors];
        GameObject[] allWallTiles  = new GameObject[maxWalls];
        //Debug.Log("maxFloors = "+ maxFloors + "; maxWalls = "+ maxWalls);
        for (int i = 0; i < activeFloorTiles.Length; i++)
        {
            allFloorTiles[i] = activeFloorTiles[i];
        }
        for (int i = 0; i < activeWallTiles.Length; i++)
        {
            allWallTiles[i] = activeWallTiles[i];
        }
        for (int y = 0; y < map.sizeY; y++)
        {
            for (int x = 0; x < map.sizeX; x++)
            {
                Vector3 tilePos = new Vector3(x, y, Floor.transform.position.z);
                if (map.GetTileAt(x, y) == eTile.Goal)
                {
                    if (toPrevFloor)
                    {
                        PlayerInstance.transform.position = tilePos;
                    }
                    else
                    {
                        SpawnPotion(map, x, y, Floor.transform.position.z);
                    }
                    GameObject.FindGameObjectWithTag("goal").transform.position = tilePos;
                }
                if (map.GetTileAt(x, y) == eTile.Player)
                {
                    if (!toPrevFloor)
                    {
                        PlayerInstance.transform.position = tilePos;
                    }
                    GameObject.FindGameObjectWithTag("UpStairs").transform.position = tilePos;
                }
                if (map.GetTileAt(x, y) == eTile.Floor)
                {
                    if (floorIndex < allFloorTiles.Length && allFloorTiles[floorIndex] != null)
                    {
                        allFloorTiles[floorIndex].transform.position = tilePos;
                        allFloorTiles[floorIndex].SetActive(true);
                        floorIndex++;
                    }
                    else
                    {
                        (Instantiate(Floor, tilePos, Quaternion.identity) as GameObject).GetComponent <TileSetChanger>().setTile(map.set);
                        if (floorIndex < allFloorTiles.Length)
                        {
                            allFloorTiles[floorIndex] = Floor;
                            floorIndex++;
                        }
                    }
                }
                if (map.GetTileAt(x, y) == eTile.Wall)
                {
                    if (wallIndex < allWallTiles.Length && allWallTiles[wallIndex] != null)
                    {
                        allWallTiles[wallIndex].transform.position = tilePos;
                        allWallTiles[wallIndex].SetActive(true);
                        wallIndex++;
                    }
                    else
                    {
                        (Instantiate(Wall, tilePos, Quaternion.identity) as GameObject).GetComponent <TileSetChanger>().setTile(map.set);
                        if (wallIndex < allWallTiles.Length)
                        {
                            allWallTiles[wallIndex] = Wall;
                            wallIndex++;
                        }
                    }
                }
            }
        }
        for (int i = floorIndex; i < allFloorTiles.Length; i++)
        {
            if (allFloorTiles[i] != null)
            {
                allFloorTiles[i].SetActive(false);
            }
            //Destroy(allFloorTiles[i]);
        }
        for (int i = wallIndex; i < allWallTiles.Length; i++)
        {
            if (allWallTiles[i] != null)
            {
                allWallTiles[i].SetActive(false);
            }
            //Destroy(allWallTiles[i]);
        }
        RefreshEnemies();
        if (!toPrevFloor)
        {
            SpawnItem(map);
        }
    }
Exemple #6
0
    public void PlaceMap(TileMapData tmd)
    {
        TileMapData map          = tmd;
        int         numOldFloors = MapUtilities.getNumTile(map.mapData, eTile.Floor);
        int         numOldWalls  = MapUtilities.getNumTile(map.mapData, eTile.Wall);

        //Debug.Log("numOldFloors = " + numOldFloors);
        //Debug.Log("numOldWalls = " + numOldWalls);
        if (numOldFloors > maxFloors)
        {
            maxFloors = numOldFloors;
        }
        if (numOldWalls > maxWalls)
        {
            maxWalls = numOldWalls;
        }

        for (int y = 0; y < map.sizeY; y++)
        {
            for (int x = 0; x < map.sizeX; x++)
            {
                Vector3 tilePos = new Vector3(x, y, Floor.transform.position.z);
                //if logic instantiates the proper prefab
                GameObject tile = null;
                if (map.GetTileAt(x, y) == eTile.Unknown)
                {
                    tile = Instantiate(Unknown, tilePos, Quaternion.identity) as GameObject;
                }
                else if (map.GetTileAt(x, y) == eTile.Floor)
                {
                    tile = Instantiate(Floor, tilePos, Quaternion.identity) as GameObject;
                }
                else if (map.GetTileAt(x, y) == eTile.Wall)
                {
                    tile = Instantiate(Wall, tilePos, Quaternion.identity) as GameObject;
                }
                else if (map.GetTileAt(x, y) == eTile.Player)
                {
                    if (!toPrevFloor)
                    {
                        PlayerInstance.transform.position = tilePos;
                    }
                    tile = Instantiate(UpStairs, tilePos, Quaternion.identity) as GameObject;
                    /*if(tile != null) {*/ tile.GetComponent <TileSetChanger>().setTile(map.set);                     //}
                    tile = Instantiate(Floor, tilePos, Quaternion.identity) as GameObject;
                }
                else if (map.GetTileAt(x, y) == eTile.Goal)
                {
                    if (toPrevFloor)
                    {
                        PlayerInstance.transform.position = tilePos;
                    }
                    else
                    {
                        SpawnPotion(map, x, y, Floor.transform.position.z);
                    }
                    tile = Instantiate(Goal, tilePos, Quaternion.identity) as GameObject;
                }

                if (tile != null)
                {
                    tile.GetComponent <TileSetChanger>().setTile(map.set);
                }
            }
        }
        if (!toPrevFloor)
        {
            EnemySpawningDifficulty(map, numEnemies);
            SpawnItem(map);
        }
    }