private void Initialize() { rotationEnabled = (PlayerPrefs.GetInt("3dMode", 1) == 1); int appleCount = PlayerPrefs.GetInt("AppleCount", 20); lastResult = GameGrid.MoveResult.NONE; inputCoolDown = DEFAULT_INPUT_COOLDOWN; guiController.SetTopScore(PlayerPrefs.GetInt("TopScore", 0)); gameGrid.SetupGrid(rotationEnabled, appleCount); SetupCamera(); }
void Update() { if (!playing) { return; } GridCube.Direction dir = ReadInput(); if (dir == GridCube.Direction.NONE || AreOpposite(dir, lastMovedDirection)) { dir = lastDirection; } if (lastResult == GameGrid.MoveResult.ROTATING) { dir = lastMovedDirection; } lastDirection = dir; lastInputTime += Time.deltaTime * speed; if (lastInputTime > inputCoolDown) { lastInputTime = 0; GameGrid.MoveResult result = gameGrid.MoveHead(dir); if (result == GameGrid.MoveResult.MOVED || result == GameGrid.MoveResult.ATE) { lastMovedDirection = dir; } switch (result) { case GameGrid.MoveResult.DIED: playing = false; int topScore = PlayerPrefs.GetInt("TopScore", 0); if (score > topScore) { PlayerPrefs.SetInt("TopScore", score); } guiController.RemoveNotifications(); guiController.SetGameOverPanelActive(true); break; case GameGrid.MoveResult.ERROR: Debug.Log("An error occured."); gameObject.SetActive(false); break; case GameGrid.MoveResult.ATE: gameGrid.PlaceNewApple(); if (rotationEnabled && Random.value < NEW_HOLE_PROBABILITY) { gameGrid.PlaceNewHole(); } //TODO: Win if no more space is available speed += speedFactor; score++; guiController.SetScore(score); inputCoolDown -= COOLDOWN_STEP; if (inputCoolDown < MIN_INPUT_COOLDOWN) { inputCoolDown = MIN_INPUT_COOLDOWN; } break; case GameGrid.MoveResult.ROTATING: default: // pass break; } lastResult = result; } }