private void GroundPair() { currentPair[0].transform.parent = fruitContainer; currentPair[1].transform.parent = fruitContainer; int pairX = Mathf.CeilToInt(currentPair.transform.localPosition.x / CellSize); int pairY = Mathf.CeilToInt(-1f * currentPair.transform.localPosition.y / CellSize) + 1; currentPair[0].xPos += pairX; currentPair[0].yPos *= -1; currentPair[0].yPos += pairY; currentPair[1].xPos += pairX; currentPair[1].yPos *= -1; currentPair[1].yPos += pairY; if (currentPair[0].yPos < 1 || currentPair[1].yPos < 1) { Lose(); } else { playfield[currentPair[0].xPos, currentPair[0].yPos] = currentPair[0]; playfield[currentPair[1].xPos, currentPair[1].yPos] = currentPair[1]; } float jellyIntensity = Input.GetButtonDown("InstantDrop-P" + (int)slot) ? 0.5f : 0.1f; currentPair[0].Jelly(jellyIntensity); currentPair[1].Jelly(jellyIntensity); tumbling = true; Destroy(currentPair.gameObject); currentPair = null; }
void Update() { UpdatePosition(); if (GameManager.Instance.Paused) { return; } elapsedTime += Time.deltaTime * speed; // Handle player input HandleInput(); if (elapsedTime >= TickTime && !lost && !won) { elapsedTime -= TickTime; CheckForNearDefeat(); if (!tumbling) { if (currentPair == null) { currentPair = nextPair; if (currentPair != null) { currentPair.MakeCurrent(); } GenerateNewPair(); } else { // Apply gravity currentPair.ApplyGravity(); if (currentPair.transform.localPosition.y <= 0) { nextPair.MakeVisible(); } if (currentPair.Grounded) { GroundPair(); } } } else { Tumble(); } } else if (won && !winSpew.gameObject.activeSelf) { Win(); } }
private void GenerateNewPair() { Transform newPair = Instantiate(fruitControllerPrefab) as Transform; newPair.parent = fruitContainer.transform; nextPair = newPair.gameObject.GetComponent<FruitPairController>(); crashChance = Mathf.MoveTowards(crashChance, MaxCrashChance, CrashTickSize); for (int i=0; i<2; i++) { Transform newFruit = Instantiate(fruitPrefab) as Transform; newFruit.parent = nextPair.transform; FruitController newFruitController = newFruit.gameObject.GetComponent<FruitController>(); newFruitController.color = (FruitController.FruitColor)(rng.Next((int)FruitController.FruitColor.MAX)); if (rng.NextDouble() < crashChance) { newFruitController.type = FruitController.FruitType.Crash; } else { newFruitController.type = FruitController.FruitType.Standard; } nextPair[i] = newFruitController; } if (nextPair[0].type == FruitController.FruitType.Crash || nextPair[1].type == FruitController.FruitType.Crash) { crashChance = 0.0f; } }