Skip to content

Commit

Permalink
Map fix (#113)
Browse files Browse the repository at this point in the history
* Adjusts map size

* map realignment

---------

Co-authored-by: Caden Maxwell <[email protected]>
  • Loading branch information
MaxEdwards20 and caden-maxwell authored Apr 19, 2024
1 parent 249ff06 commit 3a3a992
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
18 changes: 12 additions & 6 deletions src/Client/Systems/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -193,17 +194,22 @@ private void drawLeaderboard(SpriteBatch spriteBatch, List<Entity> 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,
Expand Down
20 changes: 8 additions & 12 deletions src/Server/GameModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// This is where the server-side simulation takes place. Messages
Expand Down Expand Up @@ -159,23 +158,22 @@ 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
wall = Shared.Entities.Wall.create(new Vector2(0 - wallSize, i * wallSize), wallSize);
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);
}

Expand All @@ -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;
Expand Down Expand Up @@ -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));
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/Shared/Components/MapSize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Shared.Components;

public static class MapSize
{
public static int MAP_SIZE = 4000;
}

0 comments on commit 3a3a992

Please sign in to comment.