示例#1
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="addPotDelegate">The function that gets called whenever the player retreives a pot</param>
    /// <param name="addCrabDelegate">The function that gets called whenever the player gains crab</param>
    public void LiftAllPots(AddPotDelegate addPotDelegate, AddCrabDelegate addCrabDelegate)
    {
        /**
         * First make each number tile from previous round a little grayer (previousRoundColor).
         * This is to help the player read which tiles they just lifted pots up from.
         */
        foreach (var location in numberTilemap.cellBounds.allPositionsWithin)
        {
            var numberTile = (Tile)numberTilemap.GetTile(location);

            if (numberTile != null && numberTile.sprite != null)
            {
                SetNumberTileInOffsetCoordinates(location, numberTile.sprite, previousRoundColor);
            }
        }

        /**
         * Next, take each tile that has a pot in it, find out how many crab that contains, and place
         * a tile that marks the number of crab the player lifted.
         * */
        foreach (var location in markerTilemap.cellBounds.allPositionsWithin)
        {
            Tile potTile = (Tile)markerTilemap.GetTile(location);

            if (potTile != null && potTile.sprite != null && potTile.sprite.name == potSprite.name)
            {
                int liftedCrab = swarmController.GetCrab(location);

                addCrabDelegate(liftedCrab);
                addPotDelegate();

                ClearMarkerTile(location);
                SetNumberTileInOffsetCoordinates(location, liftedCrab, Color.white);
            }
        }
    }
示例#2
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();
        }
    }