Пример #1
0
    public Vector3Int GetRandomSwarmPlacementInCubic()
    {
        var locations = new List <Vector3Int>();

        foreach (var location in randomizerTilemap.cellBounds.allPositionsWithin)
        {
            Tile tile = (Tile)randomizerTilemap.GetTile(location);

            if (tile != null && tile.sprite != null)
            {
                locations.Add(location);
            }
        }
        int random = randomizer.Next(0, locations.Count);

        return(CubicCrabGrid.OffsetToCubic(locations[random]));
    }
Пример #2
0
    public int GetCrab(Vector3Int locationInOffsetCoord)
    {
        Vector3Int locationInCubic = CubicCrabGrid.OffsetToCubic(locationInOffsetCoord);

        if (crabPopulation.TryGetValue(locationInCubic, out int crabAmount))
        {
            Debug.Log("Area " + locationInCubic + " contained " + crabAmount + " crab");

            if (crabAmount > 1)
            {
                crabPopulation[locationInCubic] = 1;
            }
            else if (crabAmount >= 1)
            {
                crabPopulation[locationInCubic] = 0;
            }

            return(crabAmount);
        }
        Debug.Log("Area " + locationInCubic + " contained no crab");
        return(0);
    }
Пример #3
0
    public void PlaceOrRemovePot(Vector3 worldPos, bool playerHasPotsLeft, ThrowPotDelegate throwPotDelegate, AddPotDelegate addPotDelegate)
    {
        var  terrainCoordinate  = terrainGrid.WorldToCell(worldPos);
        bool terrainIsWaterTile = HasWaterTileInOffset(terrainCoordinate);

        Vector3Int markerCoordinate = markerGrid.WorldToCell(worldPos);
        var        markerTile       = (Tile)markerTilemap.GetTile(markerCoordinate);

        bool markerGridHasPlacedPotTile = TileHasSpriteWithName(markerTile, potSprite.name);

        bool       allowedToPlace  = terrainIsWaterTile && !markerGridHasPlacedPotTile;
        bool       allowedToRemove = terrainIsWaterTile && markerGridHasPlacedPotTile;
        Vector3Int location        = markerCoordinate;

        /**
         * Not all of the information gathered above is actually necessary if playerHasPotsLeft equals 'false'.
         * This function could be "optimized", but what's the point? The execution is lightning-fast anyway.
         * */
        if (allowedToPlace && playerHasPotsLeft)
        {
            Tile tile = ScriptableObject.CreateInstance <Tile>();
            tile.sprite = potSprite;
            markerTilemap.SetTile(location, tile);

            Debug.LogFormat("Placed pot at offset {0}, cubic {1}", location, CubicCrabGrid.OffsetToCubic(location));

            throwPotDelegate();
        }
        else if (allowedToRemove)
        {
            Tile tile = ScriptableObject.CreateInstance <Tile>();
            markerTilemap.SetTile(location, tile);

            addPotDelegate();
        }
    }