/// <summary> /// Restarts the game. /// </summary> /// <param name="displayIntro">If set to <c>true</c> display intro.</param> void RestartGame(bool displayIntro) { gameIsOver = false; U9Transition t; t = U9T.S(U9T.P(displayIntro ? introView.GetDisplayTransition() : null)); t.Begin(); }
public U9Transition FireEvent(string eventID, object source, params object[] args) { //Debug.Log ("FIRE EVENT: " + eventID); U9Event e; U9Transition transition = U9T.Null(); if (events.TryGetValue(eventID, out e)) { U9EventArgs eventArgs = e.OnFired(source, args); if (eventArgs != null && eventArgs.Transitions.Count > 0) { transition = U9T.P(eventArgs.Transitions.ToArray()); } } return(transition); }
U9Transition CreateCompositeTransition(U9Transition[] ts) { switch (compositionType) { case CompositionType.Parallel: return(U9T.P(ts)); case CompositionType.Serial: return(U9T.S(ts)); case CompositionType.Stagger: return(U9T.Stagger(0.1f, ts)); default: return(null); } }
/// <summary> /// Creates a transition which shifts blocks away from the given edge, checks for any matched blocks, and triggers game over if the board is full. /// </summary> /// <returns>The shift blocks transition.</returns> /// <param name="edge">Edge.</param> public U9Transition CreatePlayerMoveTransition(Edge edge) { if (_IntroLogo != null) { MoveIntro(edge); } for (int i = 1, ni = gridSize - 1; i < ni; i++) { for (int j = 1, nj = gridSize - 1; j < nj; j++) { Block b = blocks [i, j]; } } newScoreView.GetHideTransition().Begin(); highScoreView.GetHideTransition().Begin(); // If already gameover then ignore this request and return a null transition. if (gameIsOver) { RestartGame(false); } // If the intro is displaying then hide it. if (introView != null && introView.IsDisplaying) { introView.GetHideTransition().Begin(); } U9Transition t = U9T.P(CreateShiftBlocksTransition(edge)); // After the player move transition, if the game is over then start a new game, otherwise spawn blocks on the side that was just shifted t.Ended += (transition) => { U9Transition d = CreateMatchesTransition(); U9Transition gameOver = IsGameOver() ? CreateGameOverTransition() : null; if (gameOver != null) { gameOver.Ended += (transitionOver) => { if (gameIsOver) { if (Platform == Platform.Web) { Application.ExternalCall("SetHighScore", HighScore); Application.ExternalCall("GameOver"); } //!!! haxForSideBlocksNotSpawningInCorrectNumber = true; //!!! score = 0; scoresToAdd = 0; newScore = 0; _Timer = 0; StartGame(); currentScoreLabel.text = "0"; _ECurrentView = View.Game; } }; gameOver.Begin(); } else { if (d != null) { d.Begin(); } SpawnBlocks(edge); } }; return(t); }
/// <summary> /// Spawns new blocks on the specified side /// </summary> /// <param name="side">Side.</param> void SpawnBlocks(Edge edge) { // Create a list of possible spawn points List <int> possibleSpawnPoints = new List <int> (); int numEdgeSpawnsRequired = numberOfEdgeSpawns; if (haxForSideBlocksNotSpawningInCorrectNumber == false) { #region What should be done switch (edge) { case Edge.Top: for (int i = 1, ni = gridSize - 1; i < ni; i++) { if (blocks [i, gridSize - 1]) { numEdgeSpawnsRequired--; } else { possibleSpawnPoints.Add(i); } } break; case Edge.Bottom: for (int i = 1, ni = gridSize - 1; i < ni; i++) { if (blocks [i, 0]) { numEdgeSpawnsRequired--; } else { possibleSpawnPoints.Add(i); } } break; case Edge.Left: for (int i = 1, ni = gridSize - 1; i < ni; i++) { if (blocks [0, i]) { numEdgeSpawnsRequired--; } else { possibleSpawnPoints.Add(i); } } break; case Edge.Right: for (int i = 1, ni = gridSize - 1; i < ni; i++) { if (blocks [gridSize - 1, i]) { numEdgeSpawnsRequired--; } else { possibleSpawnPoints.Add(i); } } break; } #endregion } else { #region What i am forced to do... for (int i = 1, ni = gridSize - 1; i < ni; i++) { possibleSpawnPoints.Add(i); } #endregion } // Select a subset of spawn points from the list of possible spawns. List <int> spawnPoints = GetRandomSubset <int> (possibleSpawnPoints, numEdgeSpawnsRequired); // Create a list of transitions for each of the spawns List <U9Transition> transitions = new List <U9Transition> (); switch (edge) { case Edge.Top: for (int i = 0, ni = spawnPoints.Count; i < ni; i++) { transitions.Add(SpawnBlock(spawnPoints [i], gridSize - 1)); } break; case Edge.Bottom: for (int i = 0, ni = spawnPoints.Count; i < ni; i++) { transitions.Add(SpawnBlock(spawnPoints [i], 0)); } break; case Edge.Left: for (int i = 0, ni = spawnPoints.Count; i < ni; i++) { transitions.Add(SpawnBlock(0, spawnPoints [i])); } break; case Edge.Right: for (int i = 0, ni = spawnPoints.Count; i < ni; i++) { transitions.Add(SpawnBlock(gridSize - 1, spawnPoints [i])); } break; } U9T.P(transitions.ToArray()).Begin(); }
/// <summary> /// Returns a transiton that animates and removes blocks, and grants a score for them /// </summary> /// <returns>The matches transition.</returns> U9Transition CreateMatchesTransition() { List <U9Transition> transitions = new List <U9Transition> (); newScore = Score; //layer (14-9) int layer = 14; // For every block in the grid that is not on an edge for (int i = 1, ni = gridSize - 1; i < ni; i++) { for (int j = 1, nj = gridSize - 1; j < nj; j++) { Block b = blocks [i, j]; if (b) { List <Block> matchingBlocks = FindAdjacentMatchingBlocks(b.Color, i, j); if (matchingBlocks.Count >= 3) { // The player receives score for each block, equal to the number of blocks matched int tScore = matchingBlocks.Count; newScore += tScore * tScore; GameObject onScore = (GameObject)Instantiate(_OnScore, matchingBlocks[matchingBlocks.Count / 2].transform.position, Quaternion.identity); OnScoreTransition onT = onScore.GetComponent <OnScoreTransition>(); //!! transitions.Add(onT.CreateOnScoreTransition(matchingBlocks, layer, tScore)); // Add transitions to dissapear all matching blocks and display the score per block in their place foreach (Block m in matchingBlocks) { blocks [m.I, m.J] = null; m.gameObject.layer = layer; GameObject BB = GetBackgroundBlock(m); if (BB != null) { BB.gameObject.layer = layer; } } layer--; } // Reset all blocks so that they can be checked again ResetCheckedForMatchesFlags(); } } } // Creates a stagger transition so that each subsequent match has a slight delay if (transitions.Count > 0) { U9Transition t = U9T.P(transitions.ToArray()); // Only update the score once all animations are completed t.Ended += (transition) => { Score = newScore; if (Platform == Platform.Web) { Application.ExternalCall("ScoreUpdate", Score); } }; return(t); } return(null); }