From 3a3a99239e4c05bf5e560bbe2dfc02b24e8e7c64 Mon Sep 17 00:00:00 2001 From: Maxwell Edwards <93385879+MaxEdwards20@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:17:25 -0600 Subject: [PATCH] Map fix (#113) * Adjusts map size * map realignment --------- Co-authored-by: Caden Maxwell <109488523+caden-maxwell@users.noreply.github.com> --- src/Client/Systems/Renderer.cs | 18 ++++++++++++------ src/Server/GameModel.cs | 20 ++++++++------------ src/Shared/Components/MapSize.cs | 6 ++++++ 3 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 src/Shared/Components/MapSize.cs diff --git a/src/Client/Systems/Renderer.cs b/src/Client/Systems/Renderer.cs index 2081e96..a04fe5f 100644 --- a/src/Client/Systems/Renderer.cs +++ b/src/Client/Systems/Renderer.cs @@ -44,8 +44,9 @@ public Renderer(Systems.Camera camera, GraphicsDeviceManager graphics, SpriteFon eatRenderer.LoadContent(contentManager); deathRenderer.LoadContent(contentManager); - for (int i = 0; i < 6; i++) - for (int j = 0; j < 6; j++) + var numRectangles = MapSize.MAP_SIZE / 500 ; + for (int i = 0; i < numRectangles; i++) + for (int j = 0; j < numRectangles; j++) m_backgroundTiles.Add(new Rectangle(-100 + i * 500, -100 + j * 500, 500, 500)); } @@ -193,17 +194,22 @@ private void drawLeaderboard(SpriteBatch spriteBatch, List heads) scoresToDisplay.Sort((a, b) => b.Item1.CompareTo(a.Item1)); var leaderBoardLocation = new Vector2(m_graphics.PreferredBackBufferWidth *3 / 4, 0); + var lineOffset = 50; if (m_graphics.PreferredBackBufferWidth < 1000) - leaderBoardLocation = new Vector2(m_graphics.PreferredBackBufferWidth * 3 / 5, 0); + { + leaderBoardLocation = new Vector2(800, 0); + lineOffset = 20; + } + 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); + Drawing.CustomDrawString(m_fontSmall, "Leaderboard", leaderBoardLocation, Color.White, spriteBatch, centered: false); // Then we draw the scores for (int i = 0; i < scoresToDisplay.Count; i++) { Drawing.CustomDrawString( - m_font, + m_fontSmall, scoresToDisplay[i].Item2 + ": " + scoresToDisplay[i].Item1.ToString(), - new Vector2(leaderBoardLocation.X + 30, i * 50 + 75), + new Vector2(leaderBoardLocation.X + 30, i * lineOffset + lineOffset * 2), Color.White, spriteBatch, centered: false, diff --git a/src/Server/GameModel.cs b/src/Server/GameModel.cs index 83f7c02..d90ff35 100644 --- a/src/Server/GameModel.cs +++ b/src/Server/GameModel.cs @@ -18,9 +18,8 @@ public class GameModel private readonly CollisionDetection m_systemCollisionDetection = new(); private readonly GrowthHandler m_SystemGrowthHandler = new(); private readonly Network m_systemNetwork = new(); - private readonly SpiceGen m_systemSpiceGen = new(mapSize - 200, 300); + private readonly SpiceGen m_systemSpiceGen = new(MapSize.MAP_SIZE - 200, 300); private const int wallSize = 100; - private const int mapSize = 3000; /// /// This is where the server-side simulation takes place. Messages @@ -159,15 +158,14 @@ private void generateWalls() { // We want to create wall entities around the entire map. 5000x5000 is the size of the map // We'll create a wall every 100 units - - for (int i = 0; i < mapSize / 100; i++) + for (int i = 0; i < MapSize.MAP_SIZE / wallSize; i++) { // Top wall Entity wall = Shared.Entities.Wall.create(new Vector2(i * wallSize, 0 - wallSize), wallSize); addEntity(wall); // Bottom wall - wall = Shared.Entities.Wall.create(new Vector2(i * wallSize, mapSize - wallSize), wallSize); + wall = Shared.Entities.Wall.create(new Vector2(i * wallSize, MapSize.MAP_SIZE - wallSize), wallSize); addEntity(wall); // Left wall @@ -175,7 +173,7 @@ private void generateWalls() addEntity(wall); // Right wall - wall = Shared.Entities.Wall.create(new Vector2(mapSize - wallSize, i * wallSize), wallSize); + wall = Shared.Entities.Wall.create(new Vector2(MapSize.MAP_SIZE - wallSize, i * wallSize), wallSize); addEntity(wall); } @@ -186,7 +184,7 @@ private void generateWalls() private void createNewWorm(int clientId, string name) { - var headStartLocation = getLeastDenseStartLocation(); + var headStartLocation = getRandomStartLocation(); var segmentStartLocation = new Vector2(headStartLocation.X - 75, headStartLocation.Y); var rotationRate = (float) Math.PI / 1000; var moveRate = 0.3f; @@ -247,14 +245,12 @@ private void createNewWorm(int clientId, string name) } } - private Vector2 getLeastDenseStartLocation() + private Vector2 getRandomStartLocation() { - // We want to start the player in the least dense area of the screen - // For now, we'll just start them randomly generated location Random random = new Random(); - var offset = wallSize * 5; + var offset = wallSize * 10; var lowerBound = offset; - var upperBound = mapSize - offset; + var upperBound = MapSize.MAP_SIZE - offset; return new Vector2(random.Next(lowerBound, upperBound), random.Next(lowerBound, upperBound)); } } diff --git a/src/Shared/Components/MapSize.cs b/src/Shared/Components/MapSize.cs new file mode 100644 index 0000000..ca0de23 --- /dev/null +++ b/src/Shared/Components/MapSize.cs @@ -0,0 +1,6 @@ +namespace Shared.Components; + +public static class MapSize +{ + public static int MAP_SIZE = 4000; +} \ No newline at end of file