// 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); }
private bool CheckForSplitter(TilePlant plant, Vector3Int location) { var tile = plant.stageTilemap.GetTile(location); if (!tile) { return(false); } if (tile.name.StartsWith("splitter_")) { plant.branchAudioSource.Play(); nextType = PlantTileType.Tee; pendingSplit = GetSplit(tile.name, travel); return(true); } return(false); }
// Returns true if the specified location will kill buds. If playSound is true, will play an // appropriate sound for the poor, poor plant. private bool FatalLocation(TilePlant plant, Vector3Int location, bool playSound) { // First, worry about the world boundaries... if ( location.x < StageConstants.leftLimit || location.x > StageConstants.rightLimit || location.y < StageConstants.bottomLimit ) { if (playSound) { plant.hitLowAudioSource.Play(); } return(true); } // Next, plant self-collisions... if (plant.plantTilemap.GetTile(location) != null) { if (playSound) { plant.hitAudioSource.Play(); } return(true); } // Finally, stage collisions. var tile = plant.stageTilemap.GetTile(location); if (!tile || tile.name != "spike") { return(false); } // tile.name == "spike" if (playSound) { plant.hitAudioSource.Play(); } return(true); }
// Start is called before the first frame update void Start() { vine = GetComponent <TilePlant>(); startingHeight = camera.transform.position.y; camera.SendMessage("MoveCamera", camera.transform.position); }