void GotAHit(GameObject animal) { if (GameData.gameState != "playing") { return; } int scoreAmount = 10 * GameData.dungeonLevel; // larger points for higher levels // see if any matching animals are touching and collect them GetConnected(myGridPos); // give bonus for more connecting blocks if (connectedBlocks.Count > 0) { scoreAmount = (connectedBlocks.Count + 1) * 100 * GameData.dungeonLevel; } GameData.score += scoreAmount; dt.MakeDriftingText(scoreAmount.ToString(), transform.position); if ((connectedBlocks.Count + 1) >= 3) { //print("Bonus: " + (connectedBlocks.Count+1)/3 + " added to " + GameData.shooter.GetComponent<Shooter>().numberSwaps); GameData.shooter.GetComponent <Shooter>().numberSwaps += (connectedBlocks.Count + 1) / 3; //a swap for every 3 GameData.shooter.GetComponent <Shooter>().UpdateSwaps(); dt.MakeDriftingText("Extra Swap!", transform.position + Vector3.right, 2.0f); GameObject extraSwap = CFX_SpawnSystem.GetNextObject(extraSwapPrefab); extraSwap.transform.position = swapButtonPos; SoundManager.PlaySFX("Swish 2"); } else { SoundManager.PlaySFX("Hit 1"); // sound for just a single or double match. } // set the to-be-deleted blocks to null in the grid foreach (GameObject gObj in connectedBlocks) { Int2 pos = gObj.GetComponent <Block>().myGridPos; GameData.gridBlocks[pos] = null; } // show particles for each to-be-deleted block and destroy it. foreach (GameObject gObj in connectedBlocks) { dt.MakeDriftingText(scoreAmount.ToString(), gObj.transform.position); GameObject leaves1 = CFX_SpawnSystem.GetNextObject(hitPrefab); leaves1.transform.position = gObj.transform.position; Destroy(gObj, 0.2f); GameData.score += scoreAmount; } // update the score on the screen if (scoreText != null) { scoreText.text = GameData.score.ToString("N0"); } GameData.gridBlocks[myGridPos] = null; GameObject leaves2 = CFX_SpawnSystem.GetNextObject(hitPrefab); leaves2.transform.position = gameObject.transform.position; SpriteRenderer[] spriteRenderers; spriteRenderers = gameObject.GetComponentsInChildren <SpriteRenderer>(); foreach (SpriteRenderer spr in spriteRenderers) { spr.enabled = false; } Destroy(gameObject, 0.5f); // delay killing us so other code can get finished //Invoke("MoveBlocksDown", 0.2f); //Invoke("MoveBlocksLeft", 0.2f); GameObject.Find("SceneManager").GetComponent <ShiftBlocks>().ShiftDown(); GameObject.Find("SceneManager").GetComponent <ShiftBlocks>().ShiftLeft(); CountRemainingBlocks(); }
public void TwoCoversTurned() { GameData.numTries++; // look for a match matched = IsThereAMatch(); // if we match half a good sprite with a dynamite sprite, count it as no match if (atLeastOneGood && dynamiteFound) { dynamiteFound = false; } // don't match the skulls // yes, match them because they may be the last two pieces //if (skullFound) // matched = false; float pause = GameData.noMatchPause; if (matched) { pause = GameData.matchPause; } // do this if we found a match if (twoHalves) // found two halves of a whole { GameData.matchesFound++; randY = Random.Range(-2, 2); coversTurned[0].transform.DOMove(new Vector3(0f, randY, 0f), 0.5f); coversTurned[0].GetComponent <SpriteRenderer>().DOFade(0f, 0.5f).OnComplete(() => scoring.AddToScore(100, true)); StartCoroutine(DestroyCell(coversTurned[0], 1.5f)); coversTurned[1].transform.DOMove(new Vector3(0f, randY, 0f), 0.5f); coversTurned[1].GetComponent <SpriteRenderer>().DOFade(0f, 0.5f).OnComplete(() => scoring.AddToScore(100, true)); StartCoroutine(DestroyCell(coversTurned[1], 1.5f)); firstCardTurned = false; secondCardTurned = false; skullFound = false; dynamiteFound = false; atLeastOneGood = false; SoundManager.PlaySFX("mergehalvesalt"); Invoke("MakeNewSwimmer", 0.5f); if (tutorial != null) { Destroy(tutorial); } GameData.canClick = true; CheckForFinish(); } else if (matched) { skullFound = false; // no swapping if skulls were matched GameData.matchesFound++; dt.MakeDriftingText("50", coversTurned[0].transform.position, 2f); dt.MakeDriftingText("50", coversTurned[1].transform.position, 2f); coversTurned[0].GetComponent <Rigidbody2D>().DORotate(359f, 0.25f).SetDelay(0.2f); coversTurned[1].GetComponent <Rigidbody2D>().DORotate(359f, 0.25f).SetDelay(0.2f); Invoke("HandleMatchedPair", GameData.matchPause); } else // there was no match { if (!skullFound && !dynamiteFound) { if (GameData.playAudio) { SoundManager.PlaySFX("sinkDrain1"); } if (scoring.score > 0) { dt.MakeDriftingText("-20", new Vector2(1f, 3.33f), 1f, -0.5f); } scoring.AddToScore(-20); coversTurned[0].transform.DOShakeRotation(0.7f, 40f).SetDelay(0.2f); coversTurned[1].transform.DOShakeRotation(0.7f, 40f).SetDelay(0.2f); Invoke("HideObjects", pause); } } if (skullFound) { // get the row & col of the other object int2 posOne = coversTurned[0].GetComponent <GridCell>().gridPos; int2 posTwo = coversTurned[1].GetComponent <GridCell>().gridPos; bool swapRows = true; if (posOne.y == posTwo.y) //int2 x/y is row/col { swapRows = false; } SwapCells(swapRows, posOne, posTwo); firstCardTurned = false; secondCardTurned = false; skullFound = false; dynamiteFound = false; atLeastOneGood = false; Invoke("HideObjects", pause); } else if (dynamiteFound) { // get the color of the other object and see string nameOne = coversTurned[0].name; string nameTwo = coversTurned[1].name; string colorToGrab = nameOne; if (nameOne == "dynamite") { colorToGrab = nameTwo; } if (nameOne == nameTwo) { Invoke("HideObjects", pause); } else { StartCoroutine(KillAllMatchingGems(colorToGrab, "dynamite")); //Destroy(coversTurned[0]); //Destroy(coversTurned[1]); firstCardTurned = false; secondCardTurned = false; skullFound = false; dynamiteFound = false; atLeastOneGood = false; } } }