public void TransitionToRoom(Room nextRoom, RoomTransition transition, GameState exitState, GameState enterState, EventTileDataInstance warpTile) { // Create the new room control. RoomControl newControl = new RoomControl(); newControl.gameManager = gameManager; newControl.room = nextRoom; newControl.roomLocation = nextRoom.Location; // [Exit] [Enter] // [RoomOld] -> [RoomOld] -> [Transition] -> [RoomNew] -> [RoomNew] // Create the sequence of game states for the transition. GameState postTransitionState = new GameStateAction(delegate(GameStateAction actionState) { gameManager.PopGameState(); // Pop the queue state. gameManager.PushGameState(newControl); // Push the new room control state. // Find the warp event were warping to and grab its enter-state. if (warpTile != null) { WarpEvent eventTile = newControl.FindEventTile(warpTile) as WarpEvent; if (eventTile != null) { enterState = eventTile.CreateEnterState(); } } if (enterState != null) { gameManager.PushGameState(enterState); // Push the enter state. } }); GameState preTransitionState = new GameStateAction(delegate(GameStateAction actionState) { GameControl.RoomControl = newControl; gameManager.PopGameState(); // Pop the queue state. gameManager.PopGameState(); // Pop the room control state. gameManager.PushGameState(new GameStateQueue(transition, postTransitionState)); newControl.FindEventTile(warpTile); }); if (warpTile != null) { transition.NewRoomSetup += delegate(RoomControl roomControl) { // Find the warp event were warping to. WarpEvent eventTile = newControl.FindEventTile(warpTile) as WarpEvent; if (eventTile != null) { eventTile.SetupPlayerInRoom(); } }; } // Create the game state for the transition sequence. GameState state = preTransitionState; if (exitState != null) { state = new GameStateQueue(exitState, preTransitionState); } // Begin the transition. transition.OldRoomControl = this; transition.NewRoomControl = newControl; gameManager.PushGameState(state); }