public Split(TravelDirection split1, TravelDirection split2, TravelDirection rotation, PlantTileType type) { this.split1 = split1; this.split2 = split2; this.rotation = rotation; this.type = type; }
public void Turn(TurnDirection turn) { // If there's a pending split, the player has no control over this bud. if (pendingSplit != null) { return; } this.nextType = GetNextType(turn); }
// 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); }
private TravelDirection GetNewHeading(PlantTileType nextType) { switch (nextType) { case PlantTileType.Straight: return(travel); case PlantTileType.Left: return(GetTurnDirection(TurnDirection.Left)); case PlantTileType.Right: return(GetTurnDirection(TurnDirection.Right)); case PlantTileType.Tee: return(GetTurnDirection(TurnDirection.Right)); default: throw new System.ArgumentOutOfRangeException(string.Format("How did we get here: {0}", nextType)); } }
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); } }
private TileBase GetTile(PlantTilePhase phase, PlantTileType type) { return(tileLookup[phase][type]); }