private void BackToMenu() { // Update game state, enable menu game object and reset its transparency state = GameplayStates.MENU; currentScore = 0; // Fix menu interface values menuGroup.gameObject.SetActive(true); menuGroup.alpha = 1f; bubbleParticles.Play(); // Show intersticial advertisement for each amount of played times if (intersticialTimes >= timesForIntersticial && gameManager.NoAds == 0) { ADSManager.Instance.ShowVideo(); // Reset played times amount intersticialTimes = 0; } // Enable watch and win button for each amount of played times with a random factor int random = Random.Range(0, 2); if (random == 1 && rewardedTimes >= timesForWatch) { // Reset played times amount rewardedTimes = 0; rewardButton.SetActive(true); } // Instantiate a new player after finish delay gameplayController.RestartPlayer(); // Disable menu game object after transition Invoke("DisableGameplay", 2f); }
// ------------------------------------------------------------------------------- private void OnGameStateChanged(GameplayStates prevState, GameplayStates newState) { if (newState == GameplayStates.InsideSeedShip) { Owner.SetSeedPhysicsEnabled(true); } else if (prevState == GameplayStates.InsideSeedShip) { RenderTextureCamera.enabled = true; DelayedOptimisations(); } }
// ------------------------------------------------------------------------------- public void ChangeGameplayState(GameplayStates newGameplayState) { if (CurrentGameplayState != newGameplayState) { if (OnGameStateChanged != null) { OnGameStateChanged.Invoke(CurrentGameplayState, newGameplayState); } CurrentGameplayState = newGameplayState; } }
private float ratioInit; // Background material ratio on start #endif #endregion #region Main Methods private void Start() { #if DEBUG_INFO Debug.Log("GameplayManager: initializing gameplay manager"); #endif // Get references skillButtons = new GameObject[skillButtonsRoot.childCount]; for (int i = 0; i < skillButtons.Length; i++) { skillButtons[i] = skillButtonsRoot.GetChild(i).gameObject; } // Initialize values state = GameplayStates.MENU; gameManager = GameManager.Instance; currentScore = 0; rewardedTimes = 0; intersticialTimes = 0; initColorT = backgroundMat.GetColor("_TopColor"); initColorB = backgroundMat.GetColor("_BottomColor"); bonusCounter = 0f; extraCounter = 0f; isTop = false; newRecord = false; bannerDown = false; canHability = false; #if UNITY_EDITOR ratioInit = backgroundMat.GetFloat("_Ratio"); #endif if (Application.targetFrameRate != 60) { Application.targetFrameRate = 60; } // Initialize gameplay manager InitMenuUI(); InitGameplayUI(); InitAds(); // Initialize gameplay controller gameplayController.Initialize(this); }
private void ExitGame() { #if DEBUG_INFO Debug.Log("GameplayManager: attempting to exit game"); #endif // Update game state to exit state = GameplayStates.EXIT; // Update current gameplay controller state gameplayController.ExitGame(); // Disable all menu buttons to avoid game flow bugs for (int i = 0; i < menuButtons.Length; i++) { menuButtons[i].interactable = false; } // Quit app after tap sound and menu fade out finishes Invoke("QuitApp", 1f); }
/// <summary> /// Changes the scene state. /// </summary> /// <param name="state">The state.</param> public void SetState(GameplayStates state) { var previousState = this.currentState; this.currentState = state; switch (state) { case GameplayStates.Intro: this.IsScoreVisible = false; foreach (Entity obstaclePair in this.EntityManager.FindAllByTag("OBSTACLE")) { obstaclePair.Enabled = false; } this.kiteBehavior.SetState(KiteStates.TakeOff); break; case GameplayStates.Gameplay: this.IsScoreVisible = true; this.CurrentScore = 0; this.kiteBehavior.SetState(KiteStates.Gameplay); this.ResetScene(); this.SetScrollEnable(true); this.Owner.Scene.Resume(); break; case GameplayStates.GameOver: WaveServices.TimerFactory.CreateTimer("GameoverTimer", TimeSpan.FromMilliseconds(200), this.GameOverTransition, false); break; default: break; } }
public void StartGame() { if (state == GameplayStates.MENU) { #if DEBUG_INFO Debug.Log("GameplayManager: starting new game"); #endif // Update gameplay manager values state = GameplayStates.GAME; currentScore = 0; intersticialTimes++; newRecord = false; gameplayGroup.gameObject.SetActive(true); bubbleParticles.Stop(); bonusCounter = 0f; extraCounter = 0f; canHability = false; // Disable all menu buttons to avoid game flow bugs for (int i = 0; i < menuButtons.Length; i++) { menuButtons[i].interactable = false; } // Check if it is the first player gameplay if (gameManager.AlreadyPlayed == 0) { // Enable tutorial interface game object tutorialObject.SetActive(true); // Disable tutorial interface after animation delay Invoke("DisableTutorial", 5f); // Update already played state and save data gameManager.AlreadyPlayed = 1; gameManager.SaveData(); // Update banner down state bannerDown = false; } else { bannerDown = (gameManager.NoAds == 0); } // Initialize gameplay skill buttons interface for (int i = 0; i < skillButtons.Length; i++) { skillButtons[i].SetActive(false); } skillButtons[gameManager.CurrentShip].SetActive(true); // Load intersticial advertisement for each amount of played times if (intersticialTimes >= timesForIntersticial && gameManager.NoAds == 0) { #if !UNITY_EDITOR // Load intersticial advertisement gameManager.LoadIntersticial(); #endif #if DEBUG_INFO Debug.Log("GameplayManager: attempting to load intersticial advertisement"); #endif } // Play start game audio source startSource.Play(); // Update gameplay controller state gameplayController.SetGame(); // Disable menu game object after transition Invoke("DisableMenu", 1.1f); } #if DEBUG_INFO else { Debug.LogWarning("GameplayManager: attempting to call StartGame() when state is not expected"); } #endif }
private void BackToMenu() { // Update game state, enable menu game object and reset its transparency state = GameplayStates.MENU; currentScore = 0; // Fix menu interface values menuGroup.gameObject.SetActive(true); menuGroup.alpha = 1f; bubbleParticles.Play(); #if !UNITY_EDITOR // Hide banner advertisement if needed if (bannerDown) { gameManager.HideBanner(); #if DEBUG_INFO Debug.Log("GameplayManager: attempting to hide banner advertisement"); #endif } // Show rate game dialog if needed if (gameManager.TotalTimes == timesForRate) { gameManager.ShowRatePopUp(ProjectManager.rateTitle, ProjectManager.rateMessage); #if DEBUG_INFO Debug.Log("GameplayManager: attempting to show rate app pop up"); #endif } #endif // Show intersticial advertisement for each amount of played times if (intersticialTimes >= timesForIntersticial && gameManager.NoAds == 0) { // Reset played times amount intersticialTimes = 0; #if !UNITY_EDITOR // Show intersticial advertisement gameManager.ShowIntersticial(); #endif #if DEBUG_INFO Debug.Log("GameplayManager: attempting to show intersticial advertisement"); #endif } // Enable watch and win button for each amount of played times with a random factor int random = Random.Range(0, 2); if (random == 1 && rewardedTimes >= timesForWatch) { // Reset played times amount rewardedTimes = 0; rewardButton.SetActive(true); #if !UNITY_EDITOR // Load rewarded video to avoid waiting when pressing button gameManager.LoadRewardedVideo(); #endif } // Instantiate a new player after finish delay gameplayController.RestartPlayer(); // Disable menu game object after transition Invoke("DisableGameplay", 2f); }
// ------------------------------------------------------------------------------- public bool IsCurrentGameplayState(GameplayStates state, bool falseifTransitioning = true) { return((!falseifTransitioning || !IsTransitioning) && CurrentGameplayState == state); }
/// <summary> /// Changes the scene state. /// </summary> /// <param name="state">The state.</param> public void SetState(GameplayStates state) { var previousState = this.currentState; this.currentState = state; switch (state) { case GameplayStates.Intro: this.IsScoreVisible = false; foreach (Entity obstaclePair in this.EntityManager.FindAllByTag("OBSTACLE")) { obstaclePair.Enabled = false; } this.kiteBehavior.SetState(KiteStates.TakeOff); break; case GameplayStates.Gameplay: this.IsScoreVisible = true; this.CurrentScore = 0; this.kiteBehavior.SetState(KiteStates.Gameplay); this.ResetScene(); this.SetScrollEnable(true); this.Owner.Scene.Resume(); break; case GameplayStates.GameOver: WaveServices.TimerFactory.CreateTimer("GameoverTimer", TimeSpan.FromMilliseconds(200), this.GameOverTransition, false); break; default: break; } }
public override void Draw(GameTime gameTime) { var spriteBatch = GameRef.spriteBatch; spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend); { base.Draw(gameTime); // Draw the scrolling background in the back (of course) scrollingBackground.Draw(spriteBatch); switch (gameplayState) { case GameplayStates.PLAYING: { player.Draw(spriteBatch, gameTime); foreach (Shot s in shots) s.Draw(spriteBatch, gameTime); asteroids.Draw(spriteBatch, gameTime); break; } case GameplayStates.GAMEOVER: { gameOverMessage.Display(new Vector2(AsteroidGame.ScreenBounds.Width / 2 - font.MeasureString(gameOverMessage.Message).X / 2, AsteroidGame.ScreenBounds.Height / 2 - 100), spriteBatch, gameTime); if (gameOverMessage.finished) { gameplayState = GameplayStates.PLAYING; gameOverMessage.finished = false; ResetGameFull(); } break; } } // Draw information to the screen spriteBatch.DrawString(font, "S C O R E : " + GetScore(), new Vector2((AsteroidGame.ScreenBounds.Width / 2) - (font.MeasureString("S C O R E : " + GetScore()).X / 2), 10), Color.White); spriteBatch.DrawString(font, "L I V E S : " + player.lives, new Vector2(10, AsteroidGame.ScreenBounds.Height - 30), Color.White); spriteBatch.DrawString(font, "L E V E L : " + level, new Vector2(10, AsteroidGame.ScreenBounds.Height - 100), Color.White); FadeOutRect.Draw(spriteBatch, Vector2.Zero, FadeOutColor); } spriteBatch.End(); }
public override void Update(GameTime gameTime) { // Calculates updates per second and outputs it to the console Console.WriteLine("UPS: " + AsteroidGame.CalculateFPS(gameTime, ref lastTime)); // Update the scrolling background scrollingBackground.Update((float)gameTime.ElapsedGameTime.TotalSeconds * 10); // Checks the state of the game switch (gameplayState) { case GameplayStates.PLAYING: { if (AsteroidManager.asteroids.Count == 0) LevelUp(); asteroids.Update(gameTime); if (player.gameOver) { gameplayState = GameplayStates.GAMEOVER; return; } player.Update(gameTime); shots.ForEach(delegate(Shot s) { s.Update(gameTime); }); break; } case GameplayStates.GAMEOVER: { break; } } base.Update(gameTime); }