Example #1
0
    public Grid.MoveResult Move(Block block, int direction)
    {
      lastMove = new Grid.MoveResult();

      if (block == null)
      {
        Log.Error("Cannot move null block.");
        return lastMove;
      }

      if (isGameOver == false && isPaused == false)
      {
        lastMove = grid.Move(block, direction);
        if (lastMove.success)
        {
          moves++;
          OnMove.Raise(this, BlockToWorld(block.position, Vector2.zero), moves);
        }

        return lastMove;
      }

      return lastMove;
    }
Example #2
0
    private void ComboDetected(List<Block> comboBlocks, int currentComboIndex, int totalCombosCount)
    {
      int blocksCount = comboBlocks.Count;
      if (blocksCount < 3) return;

      bypassFrozen = false;

      // Light columns
      for (int b = 0; b < blocksCount; b++)
      {
        int x = comboBlocks[b].x + 1;
        columnSprites[x].color = new Color(1f, 1f, 1f, 0.75f);
      }

      // Shake shake shake
      GridShakerScript.Shake(this, 0.15f, 0.05f);

      // Reset Game Over timer
      timeBeforeGameOverCurrent = timeBeforeGameOverMax;

      totalCombos++;

      // Update chains
      bool isChain = false;
      if (PonGameScript.instance == null || PonGameScript.instance.Settings.disableChains == false)
      {
        // -- A chain is combo where at least one block is falling and it is not the latest block moved
        bool blocksAreChainable = true;
        foreach (var b in comboBlocks)
        {
          blocksAreChainable &= b.Chainable;

          if (!blocksAreChainable) break;
        }

        // -- Also a chain is never the first combo
        isChain = ComboMultiplier >= 1 && blocksAreChainable;
        if (isChain)
        {
          chainCount++;
          totalChains++;
          Log.Info("CHAIN! chainCount=" + chainCount);
        }
      }

      if (currentComboIndex >= totalCombosCount - 1)
      {
        lastMove = new Grid.MoveResult();
      }

      if (blocksCount == 4)
      {
        total4Combos++;
      }
      else if (blocksCount == 5)
      {
        total5Combos++;
      }
      else if (blocksCount > 5)
      {
        total6Combos++;
      }

      CheckForNextLevel();

      // Update combo
      IncreaseMultiplier(isChain ? 2 : 1);

      // Compute score
      long points = GetScore(blocksCount, isChain);
      AddPoints(points);

      // Add some power
      AddPower(blocksCount);

      // Combo feedback
      Vector3 loc = BlockToWorld(comboBlocks[Mathf.CeilToInt(comboBlocks.Count / 2f)].position, Vector2.zero);
      var locs = comboBlocks.Select(b =>
          BlockToWorld(b.position, Vector2.zero) + new Vector2(0.50f, 0.5f))
        .ToArray();
      OnCombo.Raise(this,
        new ComboData(blocksCount, isChain ? chainCount : comboMultiplier, isChain, loc, comboBlocks[0].Definition));

      // Center
      loc += new Vector3(0.60f, 0.5f);

      GameUIScript.DisplayComboWidget(this, comboMultiplier, blocksCount, points, comboBlocks[0].Definition,
        loc, locs);
      if (isChain)
      {
        GameUIScript.DisplayChainWidget(this, chainCount, points, comboBlocks[0].Definition.color, loc);
      }
    }