public override void Draw(SpriteBatch spriteBatch, Rectangle screenBounds) { if (countToBeginning < 120 && !gameOver) { string text = "esc to exit"; Vector2 measure = MeasureText(text); ComputerUI.DrawFontText(spriteBatch, new Vector2(screenBounds.Width / 2, (screenBounds.Height / 2) - (measure.Y / 2) - 1) - (measure / 2), text); text = "arrow keys or wasd to move"; measure = MeasureText(text); ComputerUI.DrawFontText(spriteBatch, new Vector2(screenBounds.Width / 2, (screenBounds.Height / 2) + (measure.Y / 2) + 1) - (measure / 2), text); } else if (!gameOver) { for (int i = 24; i < screenBounds.Height - 16; i += 8) { spriteBatch.Draw(whiteSquare, screenBounds.GetPos() + new Vector2(screenBounds.Width / 2, i) - new Vector2(3, 3), Color.White * 0.6f); } spriteBatch.Draw(paddleTexture, screenBounds.GetPos() + yourPaddle.position, Color.White); spriteBatch.Draw(paddleTexture, screenBounds.GetPos() + aiPaddle.position, Color.White); spriteBatch.Draw(ballTexture, screenBounds.GetPos() + ball.position, Color.White); ComputerUI.DrawFontText(spriteBatch, new Vector2((screenBounds.Width / 2) - 16, 32), yourScore.ToString()); ComputerUI.DrawFontText(spriteBatch, new Vector2((screenBounds.Width / 2) + 6, 32), aiScore.ToString()); } if (gameOver) { string text = yourScore == 10 ? "you win" : "you lose"; Vector2 measure = MeasureText(text); ComputerUI.DrawFontText(spriteBatch, new Vector2(screenBounds.Width / 2, screenBounds.Height / 2) - (measure / 2), text); } }
public override void Draw(SpriteBatch spriteBatch, Rectangle screenBounds) { if (countToBeginning < 120 && !gameOver) { string text = "esc to exit"; Vector2 measure = MeasureText(text); ComputerUI.DrawFontText(spriteBatch, new Vector2(screenBounds.Width / 2, (screenBounds.Height / 2) - (measure.Y / 2) - 1) - (measure / 2), text); text = "arrow keys or wasd to move"; measure = MeasureText(text); ComputerUI.DrawFontText(spriteBatch, new Vector2(screenBounds.Width / 2, (screenBounds.Height / 2) + (measure.Y / 2) + 1) - (measure / 2), text); } else if (!gameOver) { foreach (Vector2 pos in snake.segments) { spriteBatch.Draw(ComputerUI.snakeTexture, pos, Color.White); } if (snakeFood != null) { spriteBatch.Draw(ComputerUI.snakeFoodTexture, snakeFood.position, Color.White); } } if (gameOver) { if (endText == null) { string text = "game over"; Vector2 measure = MeasureText(text); ComputerUI.DrawFontText(spriteBatch, new Vector2(screenBounds.Width / 2, (screenBounds.Height / 2) - (measure.Y * 1.5f) - 1) - (measure / 2), text); ScorePlayer sPlayer = Main.LocalPlayer.GetModPlayer <ScorePlayer>(); if (score > sPlayer.highScore) { sPlayer.highScore = score; } text = $"your high score is {sPlayer.highScore}"; measure = MeasureText(text); ComputerUI.DrawFontText(spriteBatch, new Vector2(screenBounds.Width / 2, (screenBounds.Height / 2) + (measure.Y * 1.5f) + 1) - (measure / 2), text); text = $"you scored {score}"; measure = MeasureText(text); ComputerUI.DrawFontText(spriteBatch, new Vector2(screenBounds.Width / 2, screenBounds.Height / 2) - (measure / 2), text); } else { ComputerUI.DrawFontText(spriteBatch, new Vector2(screenBounds.Width / 2, screenBounds.Height / 2) - (MeasureText(endText) / 2), endText); } } }