Beispiel #1
0
    // Attempt to grow this bud, taking into account possible collisions with the bounding box,
    // existing plants, and the stage. Returns true if the growth was successful, false if the
    // bud died after growing.
    public bool TryToGrow(TilePlant plant)
    {
        // If we split, hijack this update to show the new split tile.
        if (pendingSplit != null)
        {
            nextType = pendingSplit.type;
            travel   = pendingSplit.rotation;
        }
        plant.UpdateLocation(location, phase, nextType, travel);

        var newHeading  = GetNewHeading(nextType);
        var newLocation = Travel(newHeading);
        var newPhase    = GetNewPhase();

        // If we split, try to grow split1, replace heading for the main bud.
        if (pendingSplit != null)
        {
            var splitDirection = pendingSplit.split1;
            var splitLocation  = location + GetDirectionVector(splitDirection);

            if (!FatalLocation(plant, splitLocation, false))
            {
                plant.AddBud(new Bud {
                    location = splitLocation,
                    travel   = splitDirection,
                    phase    = newPhase,
                });
                plant.UpdateLocation(splitLocation, newPhase, PlantTileType.Bud, splitDirection);
            }

            newHeading   = pendingSplit.split2;
            newLocation  = Travel(newHeading);
            pendingSplit = null;
        }

        nextType = PlantTileType.Straight; // May be overridden by CheckCollisions.
        if (FatalLocation(plant, newLocation, true))
        {
            return(false);
        }

        // Needed for checking splitter rotations.
        location = newLocation;
        travel   = newHeading;
        phase    = newPhase;

        CheckForSplitter(plant, newLocation);

        plant.UpdateLocation(newLocation, newPhase, PlantTileType.Bud, newHeading);

        return(true);
    }
Beispiel #2
0
    public void UpdateLocation(Vector3Int location, PlantTilePhase phase, PlantTileType type, TravelDirection direction)
    {
        var tile     = GetTile(phase, type);
        var rotation = Quaternion.Euler(0, 0, (int)direction);

        plantTilemap.SetTransformMatrix(
            location,
            Matrix4x4.Rotate(rotation)
            );

        if (tile is AnimatedTile)
        {
            StartTileAnimation(location, (AnimatedTile)tile, rotation);

            if (type == PlantTileType.Straight)
            {
                if (UnityEngine.Random.Range(0.0f, 1.0f) < 0.75f)
                {
                    AnimatedTile overlayTile;

                    if (phase == PlantTilePhase.A)
                    {
                        overlayTile = (AnimatedTile)(new[] { eyesA, leavesA, spikesA })[UnityEngine.Random.Range(0, 3)];
                    }
                    else
                    {
                        overlayTile = (AnimatedTile)(new[] { eyesB, leavesB, spikesB })[UnityEngine.Random.Range(0, 3)];
                    }

                    StartCoroutine(StartOverlayTileAnimation(location, overlayTile, rotation));
                }
            }
        }
        else
        {
            plantTilemap.SetTile(location, tile);
        }
    }
Beispiel #3
0
 private TileBase GetTile(PlantTilePhase phase, PlantTileType type)
 {
     return(tileLookup[phase][type]);
 }