/// <summary> /// If a transition is passed in, then that means we have extra scene configurations to add... this is handy /// for when we're going into shops. We have a default Shop file that has the border, but then the transition /// config contains what character is in there/what items are shown /// </summary> /// <param name="screenId"></param> /// <param name="transition"></param> private IEnumerator BuildScreen(ViewModel.Grid transition) { var screenId = GetScreenId(transition); PreviousScreen = CurrentScreen; var parent = GetScreen(screenId); // Parent has not been built, so let's build and cache it if (parent == null) { parent = Instantiate(Manager.Game.Graphics.WorldScreen, ScreensContainer); CurrentScreen = parent.gameObject.GetComponent <Screen>(); yield return(CurrentScreen.Initialize(screenId, transition)); } else { CurrentScreen = parent.gameObject.GetComponent <Screen>(); } if (CurrentScreen.GroundColor.HasValue) { Camera.main.backgroundColor = CurrentScreen.GroundColor.Value; } Manager.Game.Pathfinder.Grid = CurrentScreen.Grid; CurrentScreen.ToggleActive(true); }
public void Initialize(ViewModel.Grid transition) { ViewModel = transition; if (transition.Name != Constants.TransitionBack) { // We have to make sure our position gets the offset by the x and y transition values... this is because we want // the transition just outside of the world space, really in the "negative" world space transform.position += new Vector3(transition.X, transition.Y); } }
private IEnumerator ExitDoor(ViewModel.Grid transition) { SetScreenLoading(true); yield return(BuildScreen(transition)); PreviousScreen.ToggleActive(); Manager.Game.Player.transform.position = OverworldPosition; Manager.Game.Audio.PlayFX(FX.Stairs); yield return(StartCoroutine(Manager.Game.Player.AnimateExit())); CurrentScreen.ToggleDoor(false); SetScreenLoading(false); }
private IEnumerator EnterDoor(ViewModel.Grid transition) { SetScreenLoading(true); Manager.Game.Audio.PlayFX(FX.Stairs); yield return(StartCoroutine(Manager.Game.Player.AnimateEnter())); // Save off the player's current position, so we can restore it later OverworldPosition = Manager.Game.Player.transform.position; yield return(BuildScreen(transition)); PreviousScreen.ToggleActive(); Manager.Game.Player.transform.position = CurrentScreen.Grid.GetWorldPosition(7f, TransitionPadding); SetScreenLoading(false); }
private string GetScreenId(ViewModel.Grid transition) { var screenId = transition.Name; if (transition.IsCastle) { InCastle = true; CurrentCastle = screenId; CurrentX = transition.X; CurrentY = transition.Y; screenId = $"{CurrentX}{CurrentY}"; SetCastleMaterial(); } if (string.IsNullOrEmpty(screenId)) { CurrentX += transition.X; CurrentY += transition.Y; screenId = $"{CurrentX}{CurrentY}"; } else if (screenId == Constants.TransitionBack) { InCastle = false; if (CurrentScreen.ViewModel.IsFloating) { CurrentX = CurrentScreen.ViewModel.X; CurrentY = CurrentScreen.ViewModel.Y; } else { CurrentX = transition.X; CurrentY = transition.Y; } screenId = $"{CurrentX}{CurrentY}"; } if (InCastle) { screenId = $"{Constants.PathCastle}{CurrentCastle}_{screenId}"; } else { InCastle = false; screenId = $"{Constants.PathOverworld}{screenId}"; } return(screenId); }
/// <summary> /// This is the transitioning effect that takes place between screens... it slides the next screen into view /// </summary> /// <param name="transition"></param> /// <returns></returns> public IEnumerator PanScreen(ViewModel.Grid transition) { SetScreenLoading(true); yield return(BuildScreen(transition)); if (PreviousScreen != null) { var grid = PreviousScreen.Grid; var x = transition.X; var y = transition.Y; var currentTransform = CurrentScreen.transform; var previousTransform = PreviousScreen.transform; var player = Manager.Game.Player.transform; var previousX = 0f; var previousY = 0f; var position = player.position; var playerX = position.x; var playerY = position.y; // Moving to right screen if (x == 1) { previousX = -Constants.GridColumns; playerX = grid.GetWorldPositionX(TransitionPadding); } // Moving to left screen else if (x == -1) { previousX = Constants.GridColumns; playerX = grid.GetWorldPositionX(Constants.GridColumnsZero - TransitionPadding); } // Moving to top screen if (y == 1) { previousY = -Constants.GridRows; playerY = grid.GetWorldPositionY(TransitionPadding); } // Moving to bottom screen else if (y == -1) { previousY = Constants.GridRows; playerY = grid.GetWorldPositionY(Constants.GridRowsZero - TransitionPadding); } var previousDestination = new Vector3(previousX, previousY); var playerDestination = new Vector3(playerX, playerY); currentTransform.position = new Vector3(-previousX, -previousY); while (previousTransform.position != previousDestination && currentTransform.position != Vector3.zero) { player.position = Vector3.MoveTowards(player.position, playerDestination, Time.deltaTime * PanSpeed); previousTransform.position = Vector3.MoveTowards(previousTransform.position, previousDestination, Time.deltaTime * PanSpeed); currentTransform.position = Vector3.MoveTowards(currentTransform.position, Vector3.zero, Time.deltaTime * PanSpeed); yield return(null); } PreviousScreen.ToggleActive(); } CurrentScreen.SpawnEnemies(); SetScreenLoading(false); }
public void StartPanScreen(ViewModel.Grid transition) { StartCoroutine(PanScreen(transition)); }
public void StartEnterDoor(ViewModel.Grid transition) { StartCoroutine(EnterDoor(transition)); }
public void Initialize(Color groundColor, ViewModel.Grid transition) { Transition = transition; HiddenDoor = Instantiate(Manager.Game.Graphics.DoorBlock, transform); HiddenDoor.GetComponent <SpriteRenderer>().color = groundColor; }