protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); m_SpriteBatch.Begin(); m_SpriteBatch.Draw(m_TextureBackground, m_PositionBackground, m_TintBackground); // tinting with alpha channel m_Player1.Draw(m_SpriteBatch); m_Player2.Draw(m_SpriteBatch); m_MotherShip.Draw(m_SpriteBatch); m_SpriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// The in-game loop. /// </summary> private async Task GameLoopAsync() { // Score/lives Pen = Colors.Blue; Print(0, 1, "Score:"); Print(0, 51, "Lives:"); Pen = Colors.Cyan; Print(0, 8, _score.ToString().PadLeft(5, '0')); Print(0, 58, _lives.ToString()); _forceField.Draw(); _mothership.Draw(); _playerShip.Draw(); // Ground Pen = Colors.Yellow; for (var c = 0; c < ScreenCols; c++) { Print(39, c, "¬K"); } if (LastKeyPress == Key.X) { _state = GameState.PlayerWins; _score = -730; } // Hit test friendly missile, if one is in flight if (_playerShip.Missile != null) { var hitResult = _forceField.HitTest(_playerShip.Missile); if (!hitResult.ProjectileStopped) { hitResult = _mothership.HitTest(_playerShip.Missile); } _score += hitResult.Score; if (hitResult.ProjectileStopped) { _playerShip.StopMissile(); } if (hitResult.HitEnemyReactor) { HandlePlayerWins(); } } // Hit test enemy bombs foreach (var bomb in _mothership.Bombs) { var hitResult = _playerShip.HitTest(bomb); if (hitResult.PlayerHit) { await HandlePlayerDeathAsync(); break; } } // ************ test - remove ************** if (LastKeyPress == Key.C) { HandlePlayerWins(); } }