public void Draw(SpriteBatch b) { b.Draw(squareTexture, new Rectangle(0, 0, GetScreenWidth(), GetScreenWidth()), null, Color.Black); if (started || starting) { foreach (INonReactiveCollideable collideable in nonReactiveCollideables) { collideable.Draw(b); } ball.Draw(b); scoreDisplay.Draw(b); if (paused) { SpriteText.drawStringHorizontallyCenteredAt(b, "Press P to resume", GetScreenWidth() / 2, GetScreenHeight() / 2, 999999, -1, 999999, 1f, 0.88f, false, SpriteText.color_White); } else if (starting) { SpriteText.drawStringHorizontallyCenteredAt(b, $"{(startTimer < 60 ? 1 : (startTimer < 120 ? 2 : 3))}", GetScreenWidth() / 2, (int)(GetScreenHeight() / 2 - Game1.tileSize * 1.5), 999999, -1, 999999, 1f, 0.88f, false, SpriteText.color_White); } else { SpriteText.drawString(b, "P to pause", 50, 150, 999999, -1, 999999, 1f, 0.88f, false, -1, "", SpriteText.color_White); } if (!starting) { SpriteText.drawString(b, "Esc to exit", 50, 100, 999999, -1, 999999, 1f, 0.88f, false, -1, "", SpriteText.color_White); } } else { int centerHeight = SpriteText.getHeightOfString("Press Space to start"); SpriteText.drawStringHorizontallyCenteredAt(b, "Pong", GetScreenWidth() / 2, GetScreenHeight() / 2 - centerHeight * 5, 999999, -1, 999999, 1f, 0.88f, false, SpriteText.color_White); SpriteText.drawStringHorizontallyCenteredAt(b, "By Cat", GetScreenWidth() / 2, GetScreenHeight() / 2 - centerHeight * 4, 999999, -1, 999999, 1f, 0.88f, false, SpriteText.color_White); SpriteText.drawStringHorizontallyCenteredAt(b, "Press Space to start", GetScreenWidth() / 2, GetScreenHeight() / 2, 999999, -1, 999999, 1f, 0.88f, false, SpriteText.color_White); int escHeight = SpriteText.getHeightOfString("Press Esc to exit"); SpriteText.drawString(b, "Press Esc to exit", 0, GetScreenHeight() - escHeight, 999999, -1, 999999, 1f, 0.88f, false, -1, "", SpriteText.color_White); } b.Draw(Game1.mouseCursors, new Rectangle(Game1.oldMouseState.X, Game1.oldMouseState.Y, Game1.tileSize / 2, Game1.tileSize / 2), new Rectangle(146, 384, 9, 9), Color.White); }
/// <summary> /// Draw all of the world entities to the window /// </summary> public override void Draw() { if (IsInitialMapLoad) { InitialMapLoad(); } else if (_madeItToEnd && _loading == false) { WorldMap.BgMusic.Stop(); PrepareNextMap(); } else if (_madeItToEnd && _loading) { if (GameMaster.IsThemePlaying == false) { GameMaster.PlayTheme(); } WinInstance.Clear(GameMaster.ThemeColor); WinInstance.Draw(LoadingText); } else if (_madeItToEnd == false && _loading == false && IsInitialMapLoad == false) { if (GameMaster.IsThemePlaying) { GameMaster.StopTheme(); } if (WorldMap.BgMusic != null && WorldMap.BgMusic.Status != SoundStatus.Playing) { WorldMap.BgMusic.Play(); } _worldView.Center = WorldPlayer.Position; WinInstance.SetView(_worldView); _healthBar.SetPosition(new Vector2f((_worldView.Center.X - _worldView.Size.X / 2.0f) + 30, _worldView.Center.Y - 350)); _scoreDisp.SetPosition(new Vector2f((_worldView.Center.X + (_worldView.Size.X / 4.0f)), _worldView.Center.Y - 350)); WinInstance.Clear(WorldMap.BgColor); WinInstance.Draw(WorldMap); if (WorldMap.FloorObjects != null) { foreach (var floor in WorldMap.FloorObjects) { WinInstance.Draw(floor); } } if (EnemiesRendered != null && EnemiesRendered.Any()) { var allEneMove = false; foreach (var enemy in EnemiesRendered) { enemy.Play(); enemy.Update(); foreach (var shot in enemy.ShotsFired) { shot.Draw(); } allEneMove = enemy.CanMove; } if (allEneMove) { foreach (var enemy in EnemiesOnMap) { enemy.SetWaitToMax(); } } } else { if (EnemiesOnMap != null) { var center = _worldView.Center; var size = new Vector2f(_worldView.Size.X / 2, _worldView.Size.Y / 2); var leftX = center.X - size.X; var rightX = center.X + size.X; var topY = center.Y - size.Y; var bottomY = center.Y + size.Y; foreach (var enemy in EnemiesOnMap) { var enePos = enemy.Position; if ((enePos.Y < topY) || (enePos.Y + enemy.Height > bottomY) || (enePos.X > rightX) || (enePos.X < leftX)) { enemy.Stop(); continue; } enemy.Play(); foreach (var shot in enemy.ShotsFired) { shot.Draw(); } enemy.Update(); } } } if (_displayLives && IsInitialMapLoad == false) { DisplayLives(); _timeToDisp += GameMaster.Delta.AsSeconds(); if (_timeToDisp >= _maxTimeToDisp) { _displayLives = false; _dispControllerTime = false; _timerStarted = false; _countDownTimer.Stop(); _timeToDisp = 0.0f; } } if (_dispControllerTime && IsInitialMapLoad == false) { InitDisplayCountDownTimer(); if (_countDownText != null) { WinInstance.Draw(_countDownText); } } foreach (var item in WorldMap.ItemsOnMap) { WinInstance.Draw(item.Item); } if (_localPause == false) { WorldPlayer.Update(); } _healthBar.UpdateHealth(WorldPlayer.Health); _scoreDisp.UpdateScore(Score); _healthBar.Draw(); _scoreDisp.Draw(); foreach (var shot in WorldPlayer.ShotsFired) { shot.Draw(); } } foreach (var npc in NpCsOnMap) { npc.Update(); } }