Skip to content

Commit

Permalink
38 map generation (#40)
Browse files Browse the repository at this point in the history
* add single tile

* orientation is radians

* zoom out + bigger tile
  • Loading branch information
caden-maxwell authored Apr 7, 2024
1 parent 872020d commit 0c66a0b
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 76 deletions.
114 changes: 62 additions & 52 deletions src/Client/Content/Content.mgcb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,45 @@

#---------------------------------- Content ---------------------------------#

#begin Textures/playerShip1_blue.png
#begin Audio/backgroundMusic.mp3
/importer:Mp3Importer
/processor:SongProcessor
/processorParam:Quality=Best
/build:Audio/backgroundMusic.mp3

#begin Audio/menu.mp3
/importer:Mp3Importer
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:Audio/menu.mp3

#begin Audio/menuSelect.mp3
/importer:Mp3Importer
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:Audio/menuSelect.mp3

#begin Audio/success.mp3
/importer:Mp3Importer
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:Audio/success.mp3

#begin Fonts/menu-select.spritefont
/importer:FontDescriptionImporter
/processor:FontDescriptionProcessor
/processorParam:PremultiplyAlpha=True
/processorParam:TextureFormat=Compressed
/build:Fonts/menu-select.spritefont

#begin Fonts/menu.spritefont
/importer:FontDescriptionImporter
/processor:FontDescriptionProcessor
/processorParam:PremultiplyAlpha=True
/processorParam:TextureFormat=Compressed
/build:Fonts/menu.spritefont

#begin Images/background.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
Expand All @@ -23,9 +61,9 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/playerShip1_blue.png
/build:Images/background.png

#begin Textures/playerShip1_red.png
#begin Images/MenuBackground.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
Expand All @@ -35,9 +73,9 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/playerShip1_red.png
/build:Images/MenuBackground.png

#begin Textures/head.png
#begin Textures/body.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
Expand All @@ -47,9 +85,9 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/head.png
/build:Textures/body.png

#begin Textures/body.png
#begin Textures/head.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
Expand All @@ -59,9 +97,9 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/body.png
/build:Textures/head.png

#begin Textures/tail.png
#begin Textures/playerShip1_blue.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
Expand All @@ -71,24 +109,21 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/tail.png


#begin Fonts/menu.spritefont
/importer:FontDescriptionImporter
/processor:FontDescriptionProcessor
/processorParam:PremultiplyAlpha=True
/processorParam:TextureFormat=Compressed
/build:Fonts/menu.spritefont
/build:Textures/playerShip1_blue.png

#begin Fonts/menu-select.spritefont
/importer:FontDescriptionImporter
/processor:FontDescriptionProcessor
#begin Textures/playerShip1_red.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:TextureFormat=Compressed
/build:Fonts/menu-select.spritefont
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/playerShip1_red.png

#begin Images/MenuBackground.png
#begin Textures/SandTile.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
Expand All @@ -98,9 +133,9 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Images/MenuBackground.png
/build:Textures/SandTile.png

#begin Images/background.png
#begin Textures/tail.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
Expand All @@ -110,30 +145,5 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Images/background.png

#begin Audio/success.mp3
/importer:Mp3Importer
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:Audio/success.mp3

#begin Audio/backgroundMusic.mp3
/importer:Mp3Importer
/processor:SongProcessor
/processorParam:Quality=Best
/build:Audio/backgroundMusic.mp3

#begin Audio/menuSelect.mp3
/importer:Mp3Importer
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:Audio/menuSelect.mp3

#begin Audio/menu.mp3
/importer:Mp3Importer
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:Audio/menu.mp3

/build:Textures/tail.png

Binary file added src/Client/Content/Textures/SandTile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 9 additions & 6 deletions src/Client/GameModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class GameModel
private Controls m_controls;
private GraphicsDeviceManager m_graphics;
private SpriteFont m_font;
private Texture2D m_sand;

/// <summary>
/// This is where everything performs its update.
Expand Down Expand Up @@ -56,11 +57,13 @@ public void render(TimeSpan elapsedTime, SpriteBatch spriteBatch)
public bool initialize(ContentManager contentManager, Controls controls, GraphicsDeviceManager graphics)
{
m_font = contentManager.Load<SpriteFont>("Fonts/menu");
m_sand = contentManager.Load<Texture2D>("Textures/SandTile");

m_contentManager = contentManager;
m_entities = new Dictionary<uint, Entity>();
m_systemInterpolation = new Systems.Interpolation();
m_systemCamera = new Systems.Camera(new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
m_renderer = new Systems.Renderer(m_systemCamera, graphics, m_font);
m_renderer = new Systems.Renderer(m_systemCamera, graphics, m_font, m_sand);
m_systemWormMovement = new Shared.Systems.WormMovement();
m_systemNetwork = new Systems.Network();

Expand Down Expand Up @@ -111,19 +114,19 @@ private Entity createEntity(Shared.Messages.NewEntity message)
{
entity.add(new Shared.Components.Input(message.inputs));
}

if (message.hasCollision)
{
entity.add(new Collision());
}

// Worm parts

if (message.hasHead)
{
entity.add(new Head());
}

if (message.hasTail)
{
entity.add(new Tail());
Expand All @@ -138,7 +141,7 @@ private Entity createEntity(Shared.Messages.NewEntity message)
{
entity.add(new ChildId(message.childId));
}

if (message.hasWorm)
{
entity.add(new Worm());
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Systems/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Camera : Shared.Systems.System
{
private Rectangle m_viewport = new();
public Rectangle Viewport { get { return m_viewport; } }
private float m_zoom = 1.0f;
private float m_zoom = 0.6f;
public float Zoom { get { return m_zoom; } }

public Camera(Vector2 viewportSize) :
Expand Down
31 changes: 22 additions & 9 deletions src/Client/Systems/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ public class Renderer : Shared.Systems.System
private Systems.Camera m_camera;
private GraphicsDeviceManager m_graphics;
private SpriteFont m_font;
private Texture2D m_sand;

public Renderer(Systems.Camera camera, GraphicsDeviceManager graphics, SpriteFont font) :
public Renderer(Systems.Camera camera, GraphicsDeviceManager graphics, SpriteFont font, Texture2D sand) :
base(
typeof(Position), typeof(Sprite)
)
{
m_camera = camera;
m_graphics = graphics;
m_font = font;
m_sand = sand;
}

public override void update(TimeSpan elapsedTime) { }
Expand All @@ -36,20 +38,33 @@ public void render(TimeSpan elapsedTime, SpriteBatch spriteBatch)
float scale = m_camera.Zoom;
Matrix matrix = Matrix.Identity;
Vector2 offset = -m_camera.Viewport.Location.ToVector2()
+ new Vector2(m_camera.Viewport.Width,m_camera.Viewport.Height) / scale / 2;
+ new Vector2(m_camera.Viewport.Width, m_camera.Viewport.Height) / scale / 2;
float scaleX = m_graphics.PreferredBackBufferWidth / (float)m_camera.Viewport.Width * scale;
float scaleY = m_graphics.PreferredBackBufferHeight / (float)m_camera.Viewport.Height * scale;

matrix *= Matrix.CreateTranslation(new Vector3(offset, 0));
matrix *= Matrix.CreateScale(scaleX, scaleY, 1);

// spriteBatch.Begin(transformMatrix: matrix);
spriteBatch.Begin();
//spriteBatch.Begin();
spriteBatch.Begin(transformMatrix: matrix);

Rectangle rect = new(0, 0, 500, 500);
spriteBatch.Draw(
m_sand,
rect,
null,
Color.White,
0,
Vector2.Zero,
SpriteEffects.None,
0
);

var heads = new List<Entity>();
var bodies = new List<Entity>();
var tails = new List<Entity>();
var others = new List<Entity>();

foreach (Entity entity in m_entities.Values)
{
if (entity.contains<Head>())
Expand All @@ -61,7 +76,7 @@ public void render(TimeSpan elapsedTime, SpriteBatch spriteBatch)
else
others.Add(entity);
}

foreach (Entity entity in others)
{
renderEntity(elapsedTime, spriteBatch, entity);
Expand All @@ -78,7 +93,7 @@ public void render(TimeSpan elapsedTime, SpriteBatch spriteBatch)
{
renderEntity(elapsedTime, spriteBatch, entity);
}

spriteBatch.End();
}

Expand Down Expand Up @@ -113,7 +128,5 @@ private void renderEntity(TimeSpan elapsedTime, SpriteBatch spriteBatch, Entity
Vector2 namePosition = new Vector2(position.X - size.X + 10, position.Y - size.Y - 10);
Drawing.DrawPlayerName(m_font, entity.get<Name>().name, namePosition, Color.White, spriteBatch);
}

}

}
14 changes: 6 additions & 8 deletions src/Shared/Systems/WormMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public override void update(TimeSpan elapsedTime)

public static void ninetyLeft(Entity head, TimeSpan elapsedTime)
{
applyLeftRotation(head, -90);
applyLeftRotation(head, -MathHelper.PiOver2);
}

public static void ninetyRight(Entity head, TimeSpan elapsedTime)
{
applyRightRotation(head, 90);
applyRightRotation(head, MathHelper.PiOver2);
}

private static Entity getHead(Entity entity, Dictionary<uint, Entity> entities)
Expand Down Expand Up @@ -139,20 +139,18 @@ private void applyThrust(Entity wormHead, TimeSpan elapsedTime)


// We don't need to update the entire worm with these because it will be updated in the next frame when thrust is applied
private static void applyLeftRotation(Entity head, int degrees)
private static void applyLeftRotation(Entity head, float radians)
{
var position = head.get<Position>();
var movement = head.get<Movement>();
// Rotate left 90 degrees
position.orientation += degrees;
position.orientation += radians;
}

private static void applyRightRotation(Entity head, int degrees)
private static void applyRightRotation(Entity head, float radians)
{
var position = head.get<Position>();
var movement = head.get<Movement>();
// Rotate right 90 degrees
position.orientation += degrees;
position.orientation += radians;
}

}

0 comments on commit 0c66a0b

Please sign in to comment.