void StartNewLevel() { pillSpawnState = PillSpawnState.Done; level++; if (pill != null && pill.obj != null) { pill.obj.active = false; } if (pillNext != null && pillNext.obj != null) { pillNext.obj.active = false; } pill = null; pillNext = null; int i = 0; int j = 0; while (i < gridHeight) { j = 0; while (j < gridWidth) { if (room[j, i] != null) { if (room[j, i].obj != null) { room[j, i].obj.active = false; } room[j, i] = null; } j++; } i++; } foreach (Tile tile in animateDestroy) { tile.obj.active = false; } animateDestroy = new List <Tile>(); while (GameObject.Find("Spawned") != null) { GameObject.Find("Spawned").active = false; } FillBottleWithViruses(); }
void UpdateRoom() { if (pill != null && pillSpawnState == PillSpawnState.Done) { ReposPill(pill); } AnimateDestroy(); if (pillSpawnState == PillSpawnState.Up && pill != null) { pill.obj.transform.Translate(0, Time.deltaTime * 10f, 0); Hand.transform.rotation = Quaternion.Euler(0, 0, 45); if (pill.obj.transform.position.y >= 5.05f) { pillSpawnState = PillSpawnState.Down; pill.obj.transform.position = new Vector3(bottle.transform.position.x, 5.1f, 0); } } if (pillSpawnState == PillSpawnState.Down && pill != null) { pill.obj.transform.position = new Vector3( pill.obj.transform.position.x, pill.obj.transform.position.y * 0.8f + Repos(3, 1).y * 0.2f , 0); if (Hand.transform.rotation.z > -13) { Hand.transform.Rotate(0, 0, -Time.deltaTime * 60f); } if (pill.obj.transform.position.y <= Repos(3, 1).y + 0.05f) { pillSpawnState = PillSpawnState.Done; ReposPill(pill); } } int i = 0; int j = 0; while (i < gridWidth) { j = 0; while (j < gridHeight) { var tile = room[i, j]; j++; if (tile == null) { continue; } if (!tile.obj.active) { tile.obj.active = true; } if (!tileIsPill(tile)) { tile.obj.transform.position = Towards(tile.obj.transform.position, Repos(tile.x, tile.y)); } else { ReposPill(tile); } } i++; } }
void GameStep() { if (Input.GetKeyDown("space") && keyDown == false) { paused = !paused; keyDown = true; } if (!Input.GetKeyDown("space") && keyDown == true) { keyDown = false; } if (paused) { return; } if (pillNext != null && pillNext.obj != null) { pillNext.obj.transform.position = SpawnPoint.transform.position; } var canControl = !(pill != null && pillSpawnState != PillSpawnState.Done); if (canControl) { GlobalMouseState(); } if (canControl) { if (pillNext == null) { SpawnNextPill(); } } singlesWait -= Time.deltaTime; if (singlesWait > 0f) { stepDelay = 0.1f; return; } var falls = FallSingles(); if (FallDoubles() || falls) { singlesWait = 0.15f; return; } if (!canControl) { return; } MoveHorizontal(); PillRotate(); stepDelay -= Time.deltaTime; if (stepDelay > 0f) { return; } stepDelay = 0.75f; if (pill == null && !IsFree(3, 0)) { Debug.Log("Wasted!"); Looser.active = true; Looser.transform.localScale = new Vector3(popupScale * 0.7f, popupScale * 0.7f, 1); GameObject.Find("TextLooserScore").GetComponent <Text>().text = score.ToString() + (best > 0? "\nBest: " + best.ToString() : ""); } if (pill == null) { pill = pillNext; pillNext = null; pillSpawnState = PillSpawnState.Up; pill.obj.transform.position = SpawnPoint.transform.position; } PillCheck(); if (!WillPillFall()) { stepDelay = 0.35f; } Match(); if (IsLevelComplete()) { Debug.Log("Well Done!"); Winner.active = true; Winner.transform.localScale = new Vector3(popupScale * 0.7f, popupScale * 0.7f, 1); GameObject.Find("TextWinnerScore").GetComponent <Text>().text = score.ToString(); } }