public override void Update() { if (PlayerDeathListener.TryReceive()) { GameGlobals.GameOverEventKey.Broadcast(); } if (GameOverListener.TryReceive()) { if (Score > CurrentHighScore) { GameGlobals.SetHighScore(Score); } BackgroundMusicInstance.Stop(); Content.Unload(SceneSystem.SceneInstance.RootScene); SceneSystem.SceneInstance.RootScene = Content.Load <Scene>("GameOver"); //GameOverText.Visibility = Visibility.Visible; } if (EnemyDeathListener.TryReceive()) { Score++; } if (Game.IsRunning) { ScoreText.Text = $"Score: {Score}"; HealthText.Text = $"Health: {PlayerEntity.Get<PlayerScript>().HitPoints}"; if (Score > CurrentHighScore) { UpdateHighScoreText(Score); } EnemySpawnCountdown -= (float)Game.UpdateTime.Elapsed.TotalSeconds; if (EnemySpawnCountdown <= 0) { SpawnEnemy(); EnemySpawnCountdown = EnemySpawnInterval; } HealthUpSpawnCountdown -= (float)Game.UpdateTime.Elapsed.TotalSeconds; if (HealthUpSpawnCountdown <= 0) { SpawnHealthUp(); HealthUpSpawnCountdown = HealthUpSpawnInterval; } } else { } }
public void Initialize() { BackgroundMusicInstance.Volume = 0.25f; BackgroundMusicInstance.Stop(); BackgroundMusicInstance.IsLooping = true; BackgroundMusicInstance.Play(); Score = 0; SpawnPlayer(); CurrentHighScore = GameGlobals.GetHighScore(); UpdateHighScoreText(CurrentHighScore); }