示例#1
0
 public override void useTool()
 {
     if (SceneManager.GetActiveScene().name == "Farmland")
     {
         Dictioary = GameObject.FindGameObjectWithTag("TileMapManager").GetComponent <TileDictionaryClass>();
         //TODO - when we add more grids and tilemaps, this will break
         // Get the mouse positon in world
         Vector3    pos    = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         Vector3Int posInt = grid.LocalToCell(pos);
         // check if the key is already on the Dictioary
         if (!Dictioary.TileMapData.ElementAt(0).Value.ContainsKey(posInt))
         {
             /*Play the sound effects*/
             AudioSource Audio = gameObject.GetComponentInParent <AudioSource>();
             Audio.clip = GetSoundEffect();
             Audio.Play();
             /***************************/
             Debug.Log("This is hoeing");
             ToolUsed = true;
             /* Added the edited tile to the Dictioary*/
             TileDataClass Temp = new TileDataClass();
             Dictioary.TileMapData.ElementAt(0).Value.Add(posInt, Temp);
             Dictioary.TileMapData.ElementAt(0).Value[posInt].TileMap.SetTile(posInt, GetTile());
             Dictioary.TileMapData.ElementAt(0).Value[posInt].Tile = tileMap.GetTile(posInt);
             /********************************************************/
         }
         else
         {
             Debug.Log(tileMap.GetTile(posInt).name);
             Debug.Log("This is already hoed");
         }
     }
 }
示例#2
0
    // Same as the above but with a few edits
    public void PlaceRocks()
    {
        // we want to have a index so determine what level we are on
        int INDEX = 0;

        if (SceneManager.GetActiveScene().name == "Mines")
        {
            INDEX = 1;
        }
        else if (SceneManager.GetActiveScene().name == "Mines1")
        {
            INDEX = 2;
        }
        else if (SceneManager.GetActiveScene().name == "Mines2")
        {
            INDEX = 3;
        }

        Vector3 worldMin = tileMap.transform.TransformPoint(tileMap.localBounds.min);
        Vector3 worldMax = tileMap.transform.TransformPoint(tileMap.localBounds.max);


        for (int x = (int)worldMin.x; x < (int)worldMax.x; x++)
        {
            for (int y = (int)worldMin.y; y < (int)worldMax.y; y++)
            {
                Vector3    pos    = new Vector3(x, y, 0);
                Vector3Int posInt = grid.WorldToCell(pos);
                if (Random.Range(1, 100) <= 40 && tileMap.GetSprite(posInt) == dirtSprite)
                {
                    //nonWalkableTileMap.SetTile(posInt, treeTile);
                    // Create a new slot
                    TileDataClass Temp = new TileDataClass();
                    // Added the new slot
                    Dictioary.TileMapData.ElementAt(INDEX).Value.Add(posInt, Temp);
                    // Set that tile sprite
                    Dictioary.TileMapData.ElementAt(INDEX).Value[posInt].TileMap.SetTile(posInt, treeTile);
                    // Set the tile to be the one we set
                    Dictioary.TileMapData.ElementAt(INDEX).Value[posInt].Tile = tileMap.GetTile(posInt);
                    // Generate two random numbers, one for what ore will spawn and then what amount will spawn with it.
                    int ItemIndex  = Random.Range(36, 44);
                    int RandAmount = Random.Range(1, 5);
                    Ore Item       = new Ore();
                    Item = this.gameObject.AddComponent <Ore>() as Ore;
                    // Sets up and ore item
                    Item.SetUpThisItem(XML.items.ElementAt(ItemIndex).Value.bItemType, XML.items.ElementAt(ItemIndex).Value.bName, RandAmount,
                                       XML.items.ElementAt(ItemIndex).Value.bStackable, XML.items.ElementAt(ItemIndex).Value.bSrcImage, XML.items.ElementAt(ItemIndex).Value.bSoundEffect,
                                       XML.items.ElementAt(ItemIndex).Value.bTile, XML.items.ElementAt(ItemIndex).Value.bPrefab, XML.items.ElementAt(ItemIndex).Value.bSellPrice, XML.items.ElementAt(ItemIndex).Value.bCustomData,
                                       XML.items.ElementAt(ItemIndex).Value.GetDesc());
                    // Set up the item in the rock at the given location.
                    Dictioary.TileMapData.ElementAt(INDEX).Value[posInt].SetOre(Item);
                    //DataBase.Add(posInt, Item);
                }
            }
        }
    }
示例#3
0
    // Loop through the max and mines of the tilemap and set the tile to a tree if we can. (random chance)
    public void PlaceTrees()
    {
        Vector3 worldMin = tileMap.transform.TransformPoint(tileMap.localBounds.min);
        Vector3 worldMax = tileMap.transform.TransformPoint(tileMap.localBounds.max);


        for (int x = (int)worldMin.x; x < (int)worldMax.x; x++)
        {
            for (int y = (int)worldMin.y; y < (int)worldMax.y; y++)
            {
                Vector3    pos    = new Vector3(x, y, 0);
                Vector3Int posInt = grid.WorldToCell(pos);
                if (Random.Range(1, 100) <= 40 && tileMap.GetSprite(posInt) == dirtSprite)
                {
                    //nonWalkableTileMap.SetTile(posInt, treeTile);
                    // Create a new slot
                    TileDataClass Temp = new TileDataClass();
                    // Added the new slot
                    Dictioary.TileMapData.ElementAt(4).Value.Add(posInt, Temp);
                    // Set that tile sprite
                    Dictioary.TileMapData.ElementAt(4).Value[posInt].TileMap.SetTile(posInt, treeTile);
                    // Set the tile to be the one we set
                    Dictioary.TileMapData.ElementAt(4).Value[posInt].Tile = tileMap.GetTile(posInt);
                    ItemBase Item = new ItemBase();
                    Item = this.gameObject.AddComponent <ItemBase>() as ItemBase;
                    // Sets up and ore item
                    Item.SetUpThisItem(XML.items.ElementAt(45).Value.bItemType, XML.items.ElementAt(45).Value.bName, 1,
                                       XML.items.ElementAt(45).Value.bStackable, XML.items.ElementAt(45).Value.bSrcImage, XML.items.ElementAt(45).Value.bSoundEffect,
                                       XML.items.ElementAt(45).Value.bTile, XML.items.ElementAt(45).Value.bPrefab, XML.items.ElementAt(45).Value.bSellPrice, XML.items.ElementAt(45).Value.bCustomData,
                                       XML.items.ElementAt(45).Value.GetDesc());
                    // Set up the item in the rock at the given location.
                    Dictioary.TileMapData.ElementAt(4).Value[posInt].SetItem(Item);
                    //DataBase.Add(posInt, Item);
                }
            }
        }
    }