Skip to content

Commit

Permalink
Adds some formatting for bigger and smaller screens (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxEdwards20 authored Apr 18, 2024
1 parent 10262cd commit 768be16
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/Client/ClientMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public ClientMain()
protected override void Initialize()
{
// For Graders: You can change the resolution here
m_graphics.PreferredBackBufferWidth = 1920;
m_graphics.PreferredBackBufferHeight = 1080;
// m_graphics.PreferredBackBufferWidth = 1000;
// m_graphics.PreferredBackBufferHeight = 750;
// m_graphics.PreferredBackBufferWidth = 1920;
// m_graphics.PreferredBackBufferHeight = 1080;
m_graphics.PreferredBackBufferWidth = 1920/2;
m_graphics.PreferredBackBufferHeight = 1080/2;
m_graphics.ApplyChanges();

// Load the controls
Expand Down
20 changes: 4 additions & 16 deletions src/Client/Menu/HowToPlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class HowToPlayView : GameStateView
private SpriteFont font;

private string howToPlayMessage =
"How to Play\n\n" +
"Control a worm to eat spice and grow.\nUse configured keys for movement." +
"\nAvoid walls and other players!\nTry to beat the high score!" +
"\n(Custom controls in Main Menu)\n";
Expand Down Expand Up @@ -74,25 +75,12 @@ public override void update(GameTime gameTime)
public override void render(GameTime gameTime)
{
m_spriteBatch.Begin();

// Define text scale
Vector2 textScale = new Vector2(0.5f, 0.5f);

// Background Rectangle
var recPosition = new Vector2(m_graphics.PreferredBackBufferWidth / 5 - 20,
m_graphics.PreferredBackBufferHeight / 4 - 50);
Drawing.DrawBlurredRectangle(m_spriteBatch, recPosition, new Vector2(700, 400), 5, 0.9f);


// Title
Vector2 titlePosition = new Vector2(m_graphics.PreferredBackBufferWidth / 2, m_graphics.PreferredBackBufferHeight / 4);

Vector2 titleOrigin = font.MeasureString(titleMessage) / 2;
Drawing.CustomDrawString(font, titleMessage, titlePosition, Colors.displayColor, m_spriteBatch, true, false, scale: 1.0f);
// m_spriteBatch.DrawString(font, titleMessage, titlePosition - (titleOrigin * textScale), Colors.displayColor, 0f, Vector2.Zero, textScale, SpriteEffects.None, 0f);

// How to Play Instructions
Vector2 instructionsPosition = new Vector2(m_graphics.PreferredBackBufferWidth / 5, m_graphics.PreferredBackBufferHeight / 2.5f);
Vector2 instructionsPosition = new Vector2(m_graphics.PreferredBackBufferWidth / 5, m_graphics.PreferredBackBufferHeight / 6);
Drawing.DrawBlurredRectangle(m_spriteBatch, instructionsPosition, new Vector2(m_graphics.PreferredBackBufferWidth * 2/3, m_graphics.PreferredBackBufferHeight * 4 / 5), 5, 0.9f);

string[] lines = howToPlayMessage.Split('\n');
foreach (string line in lines)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Client/Menu/MainMenuView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public override void render(GameTime gameTime)
renderSound = false; // reset the flag
}
// I split the first one's parameters on separate lines to help you see them better
Drawing.DrawBlurredRectangle(m_spriteBatch, new Vector2(m_graphics.PreferredBackBufferWidth / 4, 150), new Vector2(m_graphics.PreferredBackBufferWidth / 2, 500), 5 );
Drawing.DrawBlurredRectangle(m_spriteBatch, new Vector2(m_graphics.PreferredBackBufferWidth / 4, 100), new Vector2(m_graphics.PreferredBackBufferWidth / 2, 500), 5 );
float bottom = drawMenuItem(
m_currentSelection == MenuState.NewGame ? m_fontMenuSelect : m_fontMenu,
"New Game",
200,
150,
m_currentSelection == MenuState.NewGame ? Colors.selectedColor : Colors.displayColor);
bottom = drawMenuItem(m_currentSelection == MenuState.HighScores ? m_fontMenuSelect : m_fontMenu, "High Scores", bottom, m_currentSelection == MenuState.HighScores ? Colors.selectedColor : Colors.displayColor);
bottom = drawMenuItem(m_currentSelection == MenuState.Controls ? m_fontMenuSelect : m_fontMenu, "Controls", bottom, m_currentSelection == MenuState.Controls ? Colors.selectedColor : Colors.displayColor);
Expand Down
10 changes: 6 additions & 4 deletions src/Client/Systems/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,18 @@ private void drawLeaderboard(SpriteBatch spriteBatch, List<Entity> heads)
// Then we sort the scores by the first element of each tuple, the score
scoresToDisplay.Sort((a, b) => b.Item1.CompareTo(a.Item1));


Drawing.DrawBlurredRectangle(spriteBatch, new Vector2(m_graphics.PreferredBackBufferWidth - 350, 0), new Vector2(350, scoresToDisplay.Count * 50 + 100), 7);
Drawing.CustomDrawString(m_font, "Leaderboard", new Vector2(m_graphics.PreferredBackBufferWidth - 300, 0), Color.White, spriteBatch, centered: false);
var leaderBoardLocation = new Vector2(m_graphics.PreferredBackBufferWidth *3 / 4, 0);
if (m_graphics.PreferredBackBufferWidth < 1000)
leaderBoardLocation = new Vector2(m_graphics.PreferredBackBufferWidth * 3 / 5, 0);
Drawing.DrawBlurredRectangle(spriteBatch, leaderBoardLocation, new Vector2(m_graphics.PreferredBackBufferWidth * 3/ 4, scoresToDisplay.Count * 50 + 100), 7);
Drawing.CustomDrawString(m_font, "Leaderboard", leaderBoardLocation, Color.White, spriteBatch, centered: false);
// Then we draw the scores
for (int i = 0; i < scoresToDisplay.Count; i++)
{
Drawing.CustomDrawString(
m_font,
scoresToDisplay[i].Item2 + ": " + scoresToDisplay[i].Item1.ToString(),
new Vector2(m_graphics.PreferredBackBufferWidth - 300, i * 50 + 75),
new Vector2(leaderBoardLocation.X + 30, i * 50 + 75),
Color.White,
spriteBatch,
centered: false,
Expand Down

0 comments on commit 768be16

Please sign in to comment.