コード例 #1
0
        public override void OnTick(BaseTilemap <CropTileData> tilemap, int x, int y)
        {
            // Increment the age of the crop.
            CropTileData crop = tilemap[x, y];

            crop.Age++;
            tilemap[x, y] = crop;

            // If the age is greater than or equal to the death age, unset the tile.
            if (crop.Age >= deathAge)
            {
                tilemap.SetTile(x, y, tilemap.Tileset.EmptyTileName);
            }
            // Otherwise; handle ageing the crop and spawning creatures.
            else
            {
                // Scale the plant.
                scalePlant(tilemap, x, y, crop);

                // If the age is greater than or equal to the mature age, spawn creatures.
                if (crop.Age >= matureAge)
                {
                    CropTilemap cropTilemap = tilemap as CropTilemap;

                    // Spawn the amount of creatures for this plant.
                    for (int i = 0; i < creaturesPerTick; i++)
                    {
                        cropTilemap.CreatureManager.SpawnCreature(cropTilemap.GetCropSeed(x, y), creaturePrefab, x, y);
                    }
                }
            }
        }
コード例 #2
0
 /// <summary> Tries to spread the given <paramref name="tile"/> to the given <paramref name="x"/> and <paramref name="y"/> positions. </summary>
 /// <param name="tilemap"> The tilemap. </param>
 /// <param name="tile"> The tile that is being spread. </param>
 /// <param name="x"> The x position that is being spread to. </param>
 /// <param name="y"> The y position that is being spread to. </param>
 /// <returns> True if the tile spread, otherwise; false. </returns>
 private bool trySpreadToTile(BaseTilemap <FloorTileData> tilemap, Tile <FloorTileData> tile, int x, int y)
 {
     // If the tile is the spreadable material, can be placed, and the random roll was successful, spread the grass and return true.
     if (tilemap.IsTile(x, y, spreadableTile) && tile.CanPlace(tilemap, x, y) && Random.value <= spreadChance)
     {
         tilemap.SetTile(x, y, tile);
         return(true);
     }
     // Otherwise; return false as no grass was spread.
     else
     {
         return(false);
     }
 }