diff --git a/.idea/.idea.mine2d.dir/.idea/.gitignore b/.idea/.idea.mine2d.dir/.idea/.gitignore
new file mode 100644
index 0000000..dc5e979
--- /dev/null
+++ b/.idea/.idea.mine2d.dir/.idea/.gitignore
@@ -0,0 +1,13 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Rider ignored files
+/modules.xml
+/.idea.mine2d.iml
+/contentModel.xml
+/projectSettingsUpdater.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/.idea.mine2d.dir/.idea/encodings.xml b/.idea/.idea.mine2d.dir/.idea/encodings.xml
new file mode 100644
index 0000000..df87cf9
--- /dev/null
+++ b/.idea/.idea.mine2d.dir/.idea/encodings.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.mine2d.dir/.idea/indexLayout.xml b/.idea/.idea.mine2d.dir/.idea/indexLayout.xml
new file mode 100644
index 0000000..7b08163
--- /dev/null
+++ b/.idea/.idea.mine2d.dir/.idea/indexLayout.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.mine2d.dir/.idea/vcs.xml b/.idea/.idea.mine2d.dir/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/.idea.mine2d.dir/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Folder.DotSettings b/Folder.DotSettings
new file mode 100644
index 0000000..4d5bb0f
--- /dev/null
+++ b/Folder.DotSettings
@@ -0,0 +1,2 @@
+
+ True
\ No newline at end of file
diff --git a/Program.cs b/Program.cs
index 2c3e067..03d9fc4 100644
--- a/Program.cs
+++ b/Program.cs
@@ -1,4 +1,6 @@
-class Program
+namespace mine2d;
+
+class Program
{
static void Main(string[] args)
{
@@ -10,4 +12,4 @@
// p.Dump();
// Console.WriteLine("Hello World!");
}
-}
+}
\ No newline at end of file
diff --git a/mine2d.csproj b/mine2d.csproj
index 140033f..e88a42c 100644
--- a/mine2d.csproj
+++ b/mine2d.csproj
@@ -5,20 +5,20 @@
net6.0
mine2d
enable
- true
- link
- true
- true
+ true
+ link
+ true
+ true
disable
-
-
-
-
+
+
+
+
+
+
+
-
-
-
diff --git a/src/Context.cs b/src/Context.cs
index 7f40153..375f415 100644
--- a/src/Context.cs
+++ b/src/Context.cs
@@ -1,3 +1,11 @@
+using mine2d.backend;
+using mine2d.core.tiles;
+using mine2d.engine;
+using mine2d.frontend;
+using mine2d.state;
+
+namespace mine2d;
+
class Context
{
public bool IsHost { get; set; }
@@ -9,7 +17,7 @@ class Context
public Renderer Renderer { get; set; }
public TileRegistry TileRegistry { get; set; }
public ResourceLoader ResourceLoader { get; set; }
- public static Context instance { get; set; }
+ public static Context Instance { get; set; }
public Context(
bool isHost,
@@ -30,16 +38,16 @@ class Context
this.Window = window;
this.TileRegistry = new TileRegistry();
this.ResourceLoader = new ResourceLoader();
- Context.instance = this;
+ Context.Instance = this;
}
public static Context Get()
{
- if (Context.instance == null)
+ if (Context.Instance == null)
{
throw new Exception("Context not initialized");
}
- return Context.instance;
+ return Context.Instance;
}
-}
+}
\ No newline at end of file
diff --git a/src/Controls.cs b/src/Controls.cs
index 9ffc27a..cf93aaa 100644
--- a/src/Controls.cs
+++ b/src/Controls.cs
@@ -1,13 +1,13 @@
-using static SDL2.SDL;
+namespace mine2d;
enum Control
{
- UP,
- DOWN,
- LEFT,
- RIGHT,
- STAY,
- CONFIRM,
+ Up,
+ Down,
+ Left,
+ Right,
+ Stay,
+ Confirm,
}
static class ControlKeyExtension
@@ -16,20 +16,20 @@ static class ControlKeyExtension
{
switch (c)
{
- case Control.UP:
+ case Control.Up:
return SDL_Keycode.SDLK_w;
- case Control.DOWN:
+ case Control.Down:
return SDL_Keycode.SDLK_s;
- case Control.LEFT:
+ case Control.Left:
return SDL_Keycode.SDLK_a;
- case Control.RIGHT:
+ case Control.Right:
return SDL_Keycode.SDLK_d;
- case Control.STAY:
+ case Control.Stay:
return SDL_Keycode.SDLK_LCTRL;
- case Control.CONFIRM:
+ case Control.Confirm:
return SDL_Keycode.SDLK_SPACE;
default:
throw new ArgumentException("Invalid control");
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Mine2d.cs b/src/Mine2d.cs
index 0464ee0..2e8ad2c 100644
--- a/src/Mine2d.cs
+++ b/src/Mine2d.cs
@@ -1,3 +1,11 @@
+using mine2d.backend;
+using mine2d.core;
+using mine2d.engine;
+using mine2d.frontend;
+using mine2d.state;
+
+namespace mine2d;
+
class Mine2d : Game
{
private readonly Context ctx;
@@ -29,13 +37,13 @@ class Mine2d : Game
this.ctx.Frontend.Init();
}
- protected override void draw()
+ protected override void Draw()
{
this.ctx.Frontend.Process();
}
- protected override void update(double dt)
+ protected override void Update(double dt)
{
this.ctx.Backend.Process(dt);
}
-}
+}
\ No newline at end of file
diff --git a/src/backend/Backend.cs b/src/backend/Backend.cs
index 400fdf0..60fcea3 100644
--- a/src/backend/Backend.cs
+++ b/src/backend/Backend.cs
@@ -1,13 +1,18 @@
using System.Text;
+using mine2d.backend.data;
+using mine2d.engine.system.annotations;
+using mine2d.network;
using Newtonsoft.Json;
using WatsonTcp;
+namespace mine2d.backend;
+
class Backend : IBackend
{
private WatsonTcpServer server;
private Publisher publisher;
private Queue pendingPackets = new();
- private uint tick = 0;
+ private uint tick;
public void Process(double dt)
{
@@ -17,7 +22,7 @@ class Backend : IBackend
var packet = this.pendingPackets.Dequeue();
this.publisher.Publish(packet);
}
- this.sendGameState();
+ this.SendGameState();
}
public void ProcessPacket(ValueType packet)
@@ -34,13 +39,13 @@ class Backend : IBackend
public void Run()
{
this.server = new WatsonTcpServer("127.0.0.1", 42069);
- this.server.Events.ClientConnected += this.clientConnected;
- this.server.Events.ClientDisconnected += this.clientDisconnected;
- this.server.Events.MessageReceived += this.messageReceived;
+ this.server.Events.ClientConnected += this.ClientConnected;
+ this.server.Events.ClientDisconnected += this.ClientDisconnected;
+ this.server.Events.MessageReceived += this.MessageReceived;
this.server.Start();
}
- private void clientConnected(object sender, ConnectionEventArgs args)
+ private void ClientConnected(object sender, ConnectionEventArgs args)
{
Console.WriteLine("Client connected: " + args.IpPort);
var gameState = Context.Get().GameState;
@@ -51,12 +56,12 @@ class Backend : IBackend
}
}
- private void clientDisconnected(object sender, DisconnectionEventArgs args)
+ private void ClientDisconnected(object sender, DisconnectionEventArgs args)
{
Console.WriteLine("Client disconnected: " + args.IpPort);
}
- private void messageReceived(object sender, MessageReceivedEventArgs args)
+ private void MessageReceived(object sender, MessageReceivedEventArgs args)
{
var time = DateTime.Now;
Console.WriteLine("Message Received: " + args.IpPort);
@@ -64,24 +69,24 @@ class Backend : IBackend
Console.WriteLine("Received packet: " + packet);
if (packet != null)
{
- pendingPackets.Enqueue(packet);
+ this.pendingPackets.Enqueue(packet);
}
Console.WriteLine(DateTime.Now - time);
}
- private void sendGameState()
+ private void SendGameState()
{
- if (server == null)
+ if (this.server == null)
return;
- var clients = server.ListClients();
- if (clients.Count() == 0)
+ var clients = this.server.ListClients().ToArray();
+ if (!clients.Any())
return;
var gameState = Context.Get().GameState;
var json = JsonConvert.SerializeObject(gameState);
var bytes = Encoding.UTF8.GetBytes(json);
foreach (var client in clients)
{
- server.Send(client, bytes);
+ this.server.Send(client, bytes);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/backend/IBackend.cs b/src/backend/IBackend.cs
index 4533116..ab85e6d 100644
--- a/src/backend/IBackend.cs
+++ b/src/backend/IBackend.cs
@@ -1,6 +1,8 @@
+namespace mine2d.backend;
+
interface IBackend
{
public void Process(double dt);
public void ProcessPacket(ValueType packet);
public void Init();
-}
+}
\ No newline at end of file
diff --git a/src/backend/Publisher.cs b/src/backend/Publisher.cs
index 4eb482c..3122d7b 100644
--- a/src/backend/Publisher.cs
+++ b/src/backend/Publisher.cs
@@ -1,3 +1,10 @@
+using System.Reflection;
+using mine2d.core.extensions;
+using mine2d.engine;
+using mine2d.engine.system.annotations;
+
+namespace mine2d.backend;
+
class Publisher
{
private readonly Dictionary> subscribers =
@@ -7,13 +14,14 @@ class Publisher
public Publisher(InteractorKind kind)
{
this.kind = kind;
- this.scan();
+ this.Scan();
}
- private void scan()
+ private void Scan()
{
- var assembly = this.GetType().Assembly;
- var types = assembly.GetTypes();
+ var types = Assembly
+ .GetAssembly(this.GetType())!
+ .GetTypesSafe();
foreach (var type in types)
{
var attrs = type.GetCustomAttributes(typeof(Interactor), false);
@@ -35,15 +43,15 @@ class Publisher
continue;
}
var del = Delegate.CreateDelegate(
- typeof(Action<>).MakeGenericType(method.GetParameters()[0].ParameterType),
+ typeof(Action<>).MakeGenericTypeSafely(method.GetParameters()[0].ParameterType),
method
);
- this.subscribe(attr.Type, del);
+ this.Subscribe(attr.Type, del);
}
}
}
- private void subscribe(string type, Delegate callback)
+ private void Subscribe(string type, Delegate callback)
{
if (!this.subscribers.ContainsKey(type))
{
@@ -83,4 +91,4 @@ class Publisher
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/backend/RemoteBackend.cs b/src/backend/RemoteBackend.cs
index 0584e22..98e40fc 100644
--- a/src/backend/RemoteBackend.cs
+++ b/src/backend/RemoteBackend.cs
@@ -1,21 +1,25 @@
-using WatsonTcp;
-using Newtonsoft.Json;
using System.Text;
+using mine2d.backend.data;
+using mine2d.engine.system.annotations;
+using mine2d.state;
+using Newtonsoft.Json;
+using WatsonTcp;
+
+namespace mine2d.backend;
class RemoteBackend : IBackend
{
private WatsonTcpClient client;
private Publisher publisher;
- private Queue pendingPackets = new Queue();
+ private readonly Queue pendingPackets = new();
private uint tick = 0;
public void Process(double dt)
{
- var ctx = Context.Get();
- this.ProcessPacket(new TickPacket(tick++));
- while (pendingPackets.Count > 0)
+ this.ProcessPacket(new TickPacket(this.tick++));
+ while (this.pendingPackets.Count > 0)
{
- var packet = pendingPackets.Dequeue();
+ var packet = this.pendingPackets.Dequeue();
this.ProcessPacket(packet);
}
}
@@ -25,7 +29,7 @@ class RemoteBackend : IBackend
this.publisher.Publish(packet);
var json = JsonConvert.SerializeObject(packet);
var bytes = Encoding.UTF8.GetBytes(json);
- client.Send(bytes);
+ this.client.Send(bytes);
}
public void Init()
@@ -36,8 +40,8 @@ class RemoteBackend : IBackend
public void Run()
{
- client = new WatsonTcpClient("127.0.0.1", 42069);
- client.Events.MessageReceived += (sender, args) =>
+ this.client = new WatsonTcpClient("127.0.0.1", 42069);
+ this.client.Events.MessageReceived += (_, args) =>
{
var ctx = Context.Get();
var message = Encoding.UTF8.GetString(args.Data);
@@ -47,6 +51,6 @@ class RemoteBackend : IBackend
ctx.GameState = packet;
}
};
- client.Connect();
+ this.client.Connect();
}
-}
+}
\ No newline at end of file
diff --git a/src/backend/data/Packet.cs b/src/backend/data/Packet.cs
index 3d30fc7..f3bd6c1 100644
--- a/src/backend/data/Packet.cs
+++ b/src/backend/data/Packet.cs
@@ -1,49 +1,55 @@
-using System.Numerics;
+namespace mine2d.backend.data;
-readonly struct MovePacket
+public interface IPacket
{
- readonly public string type = "move";
- readonly public string playerName;
- readonly public Vector2 movement;
+ string Type { get; }
+}
+
+readonly struct MovePacket : IPacket
+{
+ public string Type => "move";
+
+ readonly public string PlayerName;
+ readonly public Vector2 Movement;
public MovePacket(string playerName, Vector2 movement)
{
- this.playerName = playerName;
- this.movement = movement;
+ this.PlayerName = playerName;
+ this.Movement = movement;
}
}
readonly struct ConnectPacket
{
- public readonly string type = "connect";
- public readonly string playerName;
- public readonly Guid playerGuid;
+ public readonly string Type = "connect";
+ public readonly string PlayerName;
+ public readonly Guid PlayerGuid;
public ConnectPacket(string playerName, Guid playerGuid)
{
- this.playerName = playerName;
- this.playerGuid = playerGuid;
+ this.PlayerName = playerName;
+ this.PlayerGuid = playerGuid;
}
}
readonly struct TickPacket
{
- public readonly string type = "tick";
- public readonly uint tick;
+ public readonly string Type = "tick";
+ public readonly uint Tick;
public TickPacket(uint tick)
{
- this.tick = tick;
+ this.Tick = tick;
}
}
readonly struct SelfMovedPacket
{
- public readonly string type = "selfMoved";
- public readonly Vector2 target;
+ public readonly string Type = "selfMoved";
+ public readonly Vector2 Target;
public SelfMovedPacket(Vector2 target)
{
- this.target = target;
+ this.Target = target;
}
-}
+}
\ No newline at end of file
diff --git a/src/backend/interactor/Breaking.cs b/src/backend/interactor/Breaking.cs
index f9f4b73..8496f59 100644
--- a/src/backend/interactor/Breaking.cs
+++ b/src/backend/interactor/Breaking.cs
@@ -1,3 +1,8 @@
+using mine2d.backend.data;
+using mine2d.engine.system.annotations;
+
+namespace mine2d.backend.interactor;
+
[Interactor]
class Breaking
{
@@ -7,8 +12,8 @@ class Breaking
var ctx = Context.Get();
ctx.GameState.Players.ForEach(player =>
{
- Math.Max(0, player.MiningCooldown -= 1);
- if (player.Mining != null && player.MiningCooldown == 0)
+ player.MiningCooldown = Math.Max(0, player.MiningCooldown - 1);
+ if (player.Mining != Vector2.Zero && player.MiningCooldown == 0)
{
var chunk = ctx.GameState.World.GetChunkAt(player.Mining);
// chunk.SetTileAt(player.Mining, tile with { Hits = tile.Hits + 1 });
@@ -22,4 +27,4 @@ class Breaking
}
);
}
-}
+}
\ No newline at end of file
diff --git a/src/backend/interactor/Connect.cs b/src/backend/interactor/Connect.cs
index a222b52..ed8ed22 100644
--- a/src/backend/interactor/Connect.cs
+++ b/src/backend/interactor/Connect.cs
@@ -1,3 +1,9 @@
+using mine2d.backend.data;
+using mine2d.engine.system.annotations;
+using mine2d.state;
+
+namespace mine2d.backend.interactor;
+
[Interactor]
class Connect
{
@@ -5,18 +11,18 @@ class Connect
public static void ConnectServer(ConnectPacket packet)
{
var ctx = Context.Get();
- var player = ctx.GameState.Players.Find(p => p.Name == packet.playerName);
+ var player = ctx.GameState.Players.Find(p => p.Name == packet.PlayerName);
if (player == null)
{
ctx.GameState.Players.Add(
new Player
{
- Name = packet.playerName,
- Guid = packet.playerGuid,
+ Name = packet.PlayerName,
+ Guid = packet.PlayerGuid,
Position = new Vector2(20, 16 * 16),
Movement = new Vector2(0, 0)
}
);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/backend/interactor/Move.cs b/src/backend/interactor/Move.cs
index 9327b0a..d13daf2 100644
--- a/src/backend/interactor/Move.cs
+++ b/src/backend/interactor/Move.cs
@@ -1,3 +1,9 @@
+using mine2d.backend.data;
+using mine2d.core;
+using mine2d.engine.system.annotations;
+
+namespace mine2d.backend.interactor;
+
[Interactor]
class Move
{
@@ -5,10 +11,10 @@ class Move
public static void MoveHybrid(MovePacket packet)
{
var ctx = Context.Get();
- var player = ctx.GameState.Players.Find(p => p.Name == packet.playerName);
+ var player = ctx.GameState.Players.Find(p => p.Name == packet.PlayerName);
if (player != null)
{
- player.Movement = packet.movement * 4;
+ player.Movement = packet.Movement * 4;
}
}
@@ -26,4 +32,4 @@ class Move
var camera = Context.Get().FrontendGameState.Camera;
camera.CenterOn(PlayerEntity.GetSelf().Position);
}
-}
+}
\ No newline at end of file
diff --git a/src/core/Bootstrapper.cs b/src/core/Bootstrapper.cs
index 27ea3f1..b733e37 100644
--- a/src/core/Bootstrapper.cs
+++ b/src/core/Bootstrapper.cs
@@ -1,11 +1,17 @@
+using mine2d.core.data;
+using mine2d.core.tiles;
+using mine2d.core.world;
+
+namespace mine2d.core;
+
class Bootstrapper
{
public static void Bootstrap()
{
var ctx = Context.Get();
ctx.GameState.World = new World();
- ctx.GameState.World.AddChunk(ChunkGenerator.CreateFilledChunk(0, 1, STile.From(Tiles.stone)));
- ctx.GameState.World.AddChunk(ChunkGenerator.CreateFilledChunk(1, 1, STile.From(Tiles.stone)));
- ctx.GameState.World.AddChunk(ChunkGenerator.CreateFilledChunk(1, 0, STile.From(Tiles.stone)));
+ ctx.GameState.World.AddChunk(ChunkGenerator.CreateFilledChunk(0, 1, STile.From(Tiles.Stone)));
+ ctx.GameState.World.AddChunk(ChunkGenerator.CreateFilledChunk(1, 1, STile.From(Tiles.Stone)));
+ ctx.GameState.World.AddChunk(ChunkGenerator.CreateFilledChunk(1, 0, STile.From(Tiles.Stone)));
}
-}
+}
\ No newline at end of file
diff --git a/src/core/Camera.cs b/src/core/Camera.cs
index 624771c..1a4ff24 100644
--- a/src/core/Camera.cs
+++ b/src/core/Camera.cs
@@ -1,10 +1,12 @@
+namespace mine2d.core;
+
class Camera
{
- public Vector2 position;
+ public Vector2 Position;
public Camera()
{
- position = Vector2.Zero;
+ this.Position = Vector2.Zero;
}
public void CenterOn(Vector2 target)
@@ -13,6 +15,6 @@ class Camera
var scale = ctx.FrontendGameState.Settings.GameScale;
var windowWidth = ctx.FrontendGameState.WindowWidth;
var windowHeight = ctx.FrontendGameState.WindowHeight;
- position = target - (new Vector2(windowWidth / 2, windowHeight / 2)) / scale;
+ this.Position = target - (new Vector2(windowWidth, windowHeight) / 2) / scale;
}
-}
+}
\ No newline at end of file
diff --git a/src/core/Constants.cs b/src/core/Constants.cs
index df5de5e..758f520 100644
--- a/src/core/Constants.cs
+++ b/src/core/Constants.cs
@@ -1,6 +1,8 @@
+namespace mine2d.core;
+
class Constants
{
public const int ChunkSize = 32;
public const int TileSize = 16;
- public static Vector2 gravity = new Vector2(0, 0.1f);
-}
+ public static Vector2 Gravity = new Vector2(0, 0.1f);
+}
\ No newline at end of file
diff --git a/src/core/PlayerEntity.cs b/src/core/PlayerEntity.cs
index b7808a8..5014c84 100644
--- a/src/core/PlayerEntity.cs
+++ b/src/core/PlayerEntity.cs
@@ -1,6 +1,10 @@
+using mine2d.state;
+
+namespace mine2d.core;
+
class PlayerEntity
{
- public static bool isSelf(Player p)
+ public static bool IsSelf(Player p)
{
return p.Guid == GetSelf().Guid;
}
@@ -16,7 +20,7 @@ class PlayerEntity
public static void Move(Player p)
{
- p.Movement += Constants.gravity;
+ p.Movement += Constants.Gravity;
p.Position += p.Movement;
}
@@ -28,7 +32,7 @@ class PlayerEntity
{
var pL = p.Position + new Vector2(0, -8);
hasCollision =
- world.HasChunkAt(pL) && world.GetChunkAt(pL).hasTileAt(pL);
+ world.HasChunkAt(pL) && world.GetChunkAt(pL).HasTileAt(pL);
if (hasCollision)
{
p.Movement = p.Movement with { X = 0 };
@@ -39,7 +43,7 @@ class PlayerEntity
{
var pR = p.Position + new Vector2(16, -8);
hasCollision =
- world.HasChunkAt(pR) && world.GetChunkAt(pR).hasTileAt(pR);
+ world.HasChunkAt(pR) && world.GetChunkAt(pR).HasTileAt(pR);
if (hasCollision)
{
p.Movement = p.Movement with { X = 0 };
@@ -51,8 +55,8 @@ class PlayerEntity
var pL = p.Position;
var pR = p.Position + new Vector2(16, 0);
hasCollision =
- world.HasChunkAt(pL) && world.GetChunkAt(pL).hasTileAt(pL)
- || world.HasChunkAt(pR) && world.GetChunkAt(pR).hasTileAt(pR);
+ world.HasChunkAt(pL) && world.GetChunkAt(pL).HasTileAt(pL)
+ || world.HasChunkAt(pR) && world.GetChunkAt(pR).HasTileAt(pR);
if (hasCollision)
{
p.Movement = p.Movement with { Y = 0 };
@@ -64,8 +68,8 @@ class PlayerEntity
var pL = p.Position + new Vector2(0, -32);
var pR = p.Position + new Vector2(16, -32);
hasCollision =
- world.HasChunkAt(pL) && world.GetChunkAt(pL).hasTileAt(pL)
- || world.HasChunkAt(pR) && world.GetChunkAt(pR).hasTileAt(pR);
+ world.HasChunkAt(pL) && world.GetChunkAt(pL).HasTileAt(pL)
+ || world.HasChunkAt(pR) && world.GetChunkAt(pR).HasTileAt(pR);
if (hasCollision)
{
p.Movement = p.Movement with { Y = 0 };
@@ -73,4 +77,4 @@ class PlayerEntity
}
} while (hasCollision);
}
-}
+}
\ No newline at end of file
diff --git a/src/core/data/Chunk.cs b/src/core/data/Chunk.cs
index d223c63..8b7fd85 100644
--- a/src/core/data/Chunk.cs
+++ b/src/core/data/Chunk.cs
@@ -1,3 +1,5 @@
+namespace mine2d.core.data;
+
class Chunk
{
public STile[,] Tiles { get; set; } = new STile[Constants.ChunkSize, Constants.ChunkSize];
@@ -20,17 +22,17 @@ class Chunk
return this.Tiles[x, y];
}
- public bool hasTileAt(Vector2 pos)
+ public bool HasTileAt(Vector2 pos)
{
- return this.hasTileAt((int)pos.X, (int)pos.Y);
+ return this.HasTileAt((int)pos.X, (int)pos.Y);
}
- public bool hasTileAt(int x, int y)
+ public bool HasTileAt(int x, int y)
{
var posInChunk = this.GetPositionInChunk(new Vector2(x, y));
var tileX = (int)Math.Floor(posInChunk.X / Constants.TileSize);
var tileY = (int)Math.Floor(posInChunk.Y / Constants.TileSize);
- return this.hasTile(tileX, tileY);
+ return this.HasTile(tileX, tileY);
}
public STile GetTileAt(Vector2 pos)
@@ -59,14 +61,14 @@ class Chunk
this.SetTile(tileX, tileY, tile);
}
- public bool hasTile(int x, int y)
+ public bool HasTile(int x, int y)
{
return x >= 0 && x < this.Tiles.Length && y >= 0 && y < this.Tiles.Length && this.Tiles[x, y].Id != 0;
}
- public bool hasTile(Vector2 pos)
+ public bool HasTile(Vector2 pos)
{
- return this.hasTile((int)pos.X, (int)pos.Y);
+ return this.HasTile((int)pos.X, (int)pos.Y);
}
public Vector2 GetPositionInChunk(Vector2 pos)
@@ -74,4 +76,4 @@ class Chunk
return pos - new Vector2(this.X * Constants.ChunkSize * Constants.TileSize,
this.Y * Constants.ChunkSize * Constants.TileSize);
}
-}
+}
\ No newline at end of file
diff --git a/src/core/data/STile.cs b/src/core/data/STile.cs
index b1bc0cb..9e87155 100644
--- a/src/core/data/STile.cs
+++ b/src/core/data/STile.cs
@@ -1,3 +1,7 @@
+using mine2d.core.tiles;
+
+namespace mine2d.core.data;
+
struct STile
{
public int Id { get; set; }
@@ -15,4 +19,4 @@ struct STile
{
return From((int)id);
}
-}
+}
\ No newline at end of file
diff --git a/src/core/data/World.cs b/src/core/data/World.cs
index c32a20e..f0035f9 100644
--- a/src/core/data/World.cs
+++ b/src/core/data/World.cs
@@ -1,3 +1,5 @@
+namespace mine2d.core.data;
+
class World
{
public Dictionary Chunks { get; set; } = new Dictionary();
@@ -75,6 +77,6 @@ class World
public bool HasTileAt(int x, int y)
{
- return this.HasChunkAt(x, y) && this.GetChunkAt(x, y).hasTileAt(new Vector2(x, y));
+ return this.HasChunkAt(x, y) && this.GetChunkAt(x, y).HasTileAt(new Vector2(x, y));
}
-}
+}
\ No newline at end of file
diff --git a/src/core/extensions/AssemblyExtensions.cs b/src/core/extensions/AssemblyExtensions.cs
new file mode 100644
index 0000000..1025756
--- /dev/null
+++ b/src/core/extensions/AssemblyExtensions.cs
@@ -0,0 +1,20 @@
+using System.Reflection;
+
+namespace mine2d.core.extensions;
+
+public static class AssemblyExtensions
+{
+ public static Type[] GetTypesSafe(this Assembly assembly)
+ {
+ try
+ {
+#pragma warning disable IL2026
+ return assembly.GetTypes();
+#pragma warning restore IL2026
+ }
+ catch (ReflectionTypeLoadException ex)
+ {
+ return ex.Types.Where(t => t != null).ToArray();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/core/extensions/TypeExtensions.cs b/src/core/extensions/TypeExtensions.cs
new file mode 100644
index 0000000..0139bc3
--- /dev/null
+++ b/src/core/extensions/TypeExtensions.cs
@@ -0,0 +1,23 @@
+using System.Reflection;
+
+namespace mine2d.core.extensions;
+
+public static class TypeExtensions
+{
+ public static Type MakeGenericTypeSafely(this Type type, params Type[] typeArguments)
+ {
+ try
+ {
+#pragma warning disable IL2026
+ return type.MakeGenericType(typeArguments);
+#pragma warning restore IL2026
+ }
+ catch (ReflectionTypeLoadException e)
+ {
+ var missingTypes = e.Types
+ .Where(t => typeArguments.Contains(t) && t != null);
+
+ throw new Exception($"Failed to make generic type {type} with arguments {string.Join(", ", missingTypes)}", e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/core/tiles/Tile.cs b/src/core/tiles/Tile.cs
index fafe49c..d12fc31 100644
--- a/src/core/tiles/Tile.cs
+++ b/src/core/tiles/Tile.cs
@@ -1,3 +1,7 @@
+using mine2d.core.data;
+
+namespace mine2d.core.tiles;
+
class Tile
{
public string Name { get; set; }
@@ -14,11 +18,10 @@ class Tile
var (ptr, size) = rl.LoadToIntPtr("assets." + textureName + ".png");
var sdlBuffer = SDL_RWFromMem(ptr, size);
var surface = IMG_Load_RW(sdlBuffer, 1);
- var texture = Context.Get().Renderer.CreateTextureFromSurface(surface);
- this.texture = texture;
+ this.texture = Context.Get().Renderer.CreateTextureFromSurface(surface);
if (breakingTexture == IntPtr.Zero)
{
- loadBreakingTexture();
+ LoadBreakingTexture();
}
SDL_FreeSurface(surface);
}
@@ -35,8 +38,8 @@ class Tile
var camera = Context.Get().FrontendGameState.Camera;
renderer.DrawTexture(
this.texture,
- (x - (int)camera.position.X) * scale,
- (y - (int)camera.position.Y) * scale,
+ (x - (int)camera.Position.X) * scale,
+ (y - (int)camera.Position.Y) * scale,
Constants.TileSize * scale,
Constants.TileSize * scale
);
@@ -45,8 +48,8 @@ class Tile
var breakingOffset = (int)((double)tile.Hits / this.Hardness * 4);
renderer.DrawTexture(
breakingTexture,
- (x - (int)camera.position.X) * scale,
- (y - (int)camera.position.Y) * scale,
+ (x - (int)camera.Position.X) * scale,
+ (y - (int)camera.Position.Y) * scale,
Constants.TileSize * scale,
Constants.TileSize * scale,
breakingOffset,
@@ -56,7 +59,7 @@ class Tile
}
}
- private static void loadBreakingTexture()
+ private static void LoadBreakingTexture()
{
var rl = Context.Get().ResourceLoader;
var (ptr, size) = rl.LoadToIntPtr("assets.breaking.png");
@@ -65,4 +68,4 @@ class Tile
breakingTexture = Context.Get().Renderer.CreateTextureFromSurface(surface);
SDL_FreeSurface(surface);
}
-}
+}
\ No newline at end of file
diff --git a/src/core/tiles/TileRegistry.cs b/src/core/tiles/TileRegistry.cs
index 0e77e7a..bfacc08 100644
--- a/src/core/tiles/TileRegistry.cs
+++ b/src/core/tiles/TileRegistry.cs
@@ -1,11 +1,13 @@
-enum Tiles : int
+namespace mine2d.core.tiles;
+
+enum Tiles
{
- stone = 1,
+ Stone = 1,
}
class TileRegistry
{
- public Dictionary Tiles { get; set; } = new Dictionary();
+ public Dictionary Tiles { get; set; } = new();
public void RegisterTile()
{
@@ -16,4 +18,4 @@ class TileRegistry
{
return this.Tiles[id];
}
-}
+}
\ No newline at end of file
diff --git a/src/core/world/ChunkGenerator.cs b/src/core/world/ChunkGenerator.cs
index eae02c4..eb5bd75 100644
--- a/src/core/world/ChunkGenerator.cs
+++ b/src/core/world/ChunkGenerator.cs
@@ -1,3 +1,7 @@
+using mine2d.core.data;
+
+namespace mine2d.core.world;
+
class ChunkGenerator
{
public static Chunk CreateFilledChunk(int x, int y, STile fill)
@@ -12,4 +16,4 @@ class ChunkGenerator
}
return chunk;
}
-}
+}
\ No newline at end of file
diff --git a/src/engine/AudioPlayer.cs b/src/engine/AudioPlayer.cs
index 252191c..9999ada 100644
--- a/src/engine/AudioPlayer.cs
+++ b/src/engine/AudioPlayer.cs
@@ -1,3 +1,5 @@
+namespace mine2d.engine;
+
enum Sound { }
class AudioPlayer
@@ -12,7 +14,7 @@ class AudioPlayer
public void Register(Sound name, string path)
{
- var buffer = resourceLoader.LoadBytes(path);
+ var buffer = this.resourceLoader.LoadBytes(path);
this.audioFiles.Add(name, buffer);
}
@@ -22,4 +24,4 @@ class AudioPlayer
var sound = SDL2.SDL_mixer.Mix_QuickLoad_WAV(buffer);
SDL2.SDL_mixer.Mix_PlayChannel((int)name, sound, 0);
}
-}
+}
\ No newline at end of file
diff --git a/src/engine/FontManager.cs b/src/engine/FontManager.cs
index ec94791..f5075a2 100644
--- a/src/engine/FontManager.cs
+++ b/src/engine/FontManager.cs
@@ -1,5 +1,4 @@
-using static SDL2.SDL_ttf;
-using static SDL2.SDL;
+namespace mine2d.engine;
class FontManager
{
@@ -17,20 +16,20 @@ class FontManager
public void RegisterFont(string name, string path, int fontSize)
{
- if (fonts.ContainsKey(name))
+ if (this.fonts.ContainsKey(name))
return;
- var res = resourceLoader.LoadToIntPtr(path);
+ var res = this.resourceLoader.LoadToIntPtr(path);
var sdlBuffer = SDL_RWFromConstMem(res.ptr, res.size);
var font = TTF_OpenFontRW(sdlBuffer, 1, fontSize);
if (font == IntPtr.Zero)
{
throw new Exception("TTF_OpenFont failed");
}
- fonts.Add(name, font);
+ this.fonts.Add(name, font);
}
public IntPtr GetFont(string name)
{
- return fonts[name];
+ return this.fonts[name];
}
-}
+}
\ No newline at end of file
diff --git a/src/engine/Game.cs b/src/engine/Game.cs
index 73963d5..878c618 100644
--- a/src/engine/Game.cs
+++ b/src/engine/Game.cs
@@ -1,30 +1,34 @@
+namespace mine2d.engine;
+
abstract class Game
{
- public const int TPS = 128;
- private Queue fpsQueue = new Queue();
- protected abstract void update(double dt);
- protected abstract void draw();
+ public const int Tps = 128;
+
+ private bool running = true;
+ private Queue fpsQueue = new();
+ protected abstract void Update(double dt);
+ protected abstract void Draw();
public void Run()
{
var tLast = DateTime.Now;
var tAcc = TimeSpan.Zero;
- while (true)
+ while (this.running)
{
var dt = DateTime.Now - tLast;
tLast = DateTime.Now;
tAcc += dt;
var fps = (int)(1 / dt.TotalSeconds);
- fpsQueue.Enqueue(fps);
- while (fpsQueue.Count > fps)
- fpsQueue.Dequeue();
- while (tAcc >= TimeSpan.FromSeconds(1.0 / TPS))
+ this.fpsQueue.Enqueue(fps);
+ while (this.fpsQueue.Count > fps)
+ this.fpsQueue.Dequeue();
+ while (tAcc >= TimeSpan.FromSeconds(1.0 / Tps))
{
- update(dt.TotalSeconds);
- tAcc -= TimeSpan.FromSeconds(1.0 / TPS);
+ this.Update(dt.TotalSeconds);
+ tAcc -= TimeSpan.FromSeconds(1.0 / Tps);
}
- draw();
+ this.Draw();
}
}
-}
+}
\ No newline at end of file
diff --git a/src/engine/PacketUtils.cs b/src/engine/PacketUtils.cs
index f5dc1bf..c7cedee 100644
--- a/src/engine/PacketUtils.cs
+++ b/src/engine/PacketUtils.cs
@@ -1,4 +1,8 @@
-class PacketUtils
+using mine2d.backend.data;
+
+namespace mine2d.engine;
+
+public static class PacketUtils
{
public static string GetType(ValueType packet)
{
@@ -7,16 +11,16 @@ class PacketUtils
{
Console.WriteLine(pp.Name);
}
- var p = t.GetField("type");
+ var p = t.GetField(nameof(IPacket.Type));
if (p == null)
{
- throw new Exception("p undef");
+ throw new ArgumentNullException(nameof(p), "p undef");
}
var v = p.GetValue(packet);
if (v == null)
{
- throw new Exception("v undef");
+ throw new ArgumentNullException(nameof(v), "v undef");
}
return (string)v;
}
-}
+}
\ No newline at end of file
diff --git a/src/engine/Renderer.cs b/src/engine/Renderer.cs
index 85b6aa4..7da56a5 100644
--- a/src/engine/Renderer.cs
+++ b/src/engine/Renderer.cs
@@ -1,6 +1,10 @@
+using mine2d.engine.utils;
+
+namespace mine2d.engine;
+
class Renderer
{
- private IntPtr renderer;
+ private readonly IntPtr renderer;
private IntPtr font;
private SDL_Color color;
@@ -15,13 +19,13 @@ class Renderer
public void Clear()
{
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- SDL_RenderClear(renderer);
+ SDL_SetRenderDrawColor(this.renderer, 0, 0, 0, 255);
+ SDL_RenderClear(this.renderer);
}
public void Present()
{
- SDL_RenderPresent(renderer);
+ SDL_RenderPresent(this.renderer);
}
public void DrawRect(double x, double y, int w, int h)
@@ -31,13 +35,15 @@ class Renderer
public void DrawRect(int x, int y, int w, int h)
{
- SDL_Rect rect = new SDL_Rect();
- rect.x = x;
- rect.y = y;
- rect.w = w;
- rect.h = h;
+ var rect = new SDL_Rect
+ {
+ x = x,
+ y = y,
+ w = w,
+ h = h
+ };
- SDL_RenderFillRect(renderer, ref rect);
+ SDL_RenderFillRect(this.renderer, ref rect);
}
public void DrawOutline(int x, int y, int w, int h)
@@ -50,24 +56,24 @@ class Renderer
h = h
};
- _ = SDL_RenderDrawRect(renderer, ref rect);
+ _ = SDL_RenderDrawRect(this.renderer, ref rect);
}
public void DrawLines(double[][] points)
{
- SDL_Point[] sdlPoints = new SDL_Point[points.Length];
- for (int i = 0; i < points.Length; i++)
+ var sdlPoints = new SDL_Point[points.Length];
+ for (var i = 0; i < points.Length; i++)
{
sdlPoints[i].x = (int)points[i][0];
sdlPoints[i].y = (int)points[i][1];
}
- SDL_RenderDrawLines(renderer, sdlPoints, points.Length);
+ SDL_RenderDrawLines(this.renderer, sdlPoints, points.Length);
}
public void SetColor(int r, int g, int b, int a = 255)
{
- SDL_SetRenderDrawColor(renderer, (byte)r, (byte)g, (byte)b, (byte)a);
+ SDL_SetRenderDrawColor(this.renderer, (byte)r, (byte)g, (byte)b, (byte)a);
}
public void SetFont(IntPtr font, SDL_Color color)
@@ -79,24 +85,23 @@ class Renderer
public void SetFont(IntPtr font, Color color)
{
this.font = font;
- this.color = color.toSDLColor();
+ this.color = color.ToSdlColor();
}
public void DrawText(string text, int x, int y, bool center = false)
{
var surfaceMessage = TTF_RenderText_Solid(this.font, text, this.color);
-
var texture = SDL_CreateTextureFromSurface(this.renderer, surfaceMessage);
- int width;
- int height;
- SDL_QueryTexture(texture, out _, out _, out width, out height);
+ SDL_QueryTexture(texture, out _, out _, out var width, out var height);
- SDL_Rect rect = new SDL_Rect();
- rect.x = x;
- rect.y = y;
- rect.w = width;
- rect.h = height;
+ var rect = new SDL_Rect
+ {
+ x = x,
+ y = y,
+ w = width,
+ h = height
+ };
if (center)
{
@@ -111,12 +116,12 @@ class Renderer
public IntPtr GetRaw()
{
- return renderer;
+ return this.renderer;
}
public IntPtr CreateTextureFromSurface(IntPtr surface)
{
- return SDL_CreateTextureFromSurface(renderer, surface);
+ return SDL_CreateTextureFromSurface(this.renderer, surface);
}
public void DrawTexture(IntPtr texture, int x, int y, int w, int h)
@@ -149,4 +154,4 @@ class Renderer
};
_ = SDL_RenderCopy(this.renderer, texture, ref srcRect, ref rect);
}
-}
+}
\ No newline at end of file
diff --git a/src/engine/ResourceLoader.cs b/src/engine/ResourceLoader.cs
index d17a3ad..20647bb 100644
--- a/src/engine/ResourceLoader.cs
+++ b/src/engine/ResourceLoader.cs
@@ -1,5 +1,7 @@
using System.Runtime.InteropServices;
+namespace mine2d.engine;
+
class ResourceLoader
{
private string assemblyName;
@@ -14,11 +16,12 @@ class ResourceLoader
#if (DEBUG)
Console.WriteLine("Loading resource: " + resourceName);
return File.ReadAllText(ToPath(resourceName));
-#endif
+#else
using var stream = this.GetType()
.Assembly.GetManifestResourceStream($"{this.assemblyName}.{resourceName}");
using var reader = new StreamReader(stream!);
return reader.ReadToEnd();
+#endif
}
public byte[] LoadBytes(string resourceName)
@@ -49,4 +52,4 @@ class ResourceLoader
var s = resourceName.Split('.');
return String.Join('/', s[..^1]) + "." + s[^1];
}
-}
+}
\ No newline at end of file
diff --git a/src/engine/Shapes.cs b/src/engine/Shapes.cs
index bffb4f4..79d6a2a 100644
--- a/src/engine/Shapes.cs
+++ b/src/engine/Shapes.cs
@@ -1,11 +1,13 @@
+namespace mine2d.engine;
+
struct Line
{
- public Vector2 start;
- public Vector2 end;
+ public Vector2 Start;
+ public Vector2 End;
public Line(Vector2 start, Vector2 end)
{
- this.start = start;
- this.end = end;
+ this.Start = start;
+ this.End = end;
}
-}
+}
\ No newline at end of file
diff --git a/src/engine/Window.cs b/src/engine/Window.cs
index 720ec85..bf04f0b 100644
--- a/src/engine/Window.cs
+++ b/src/engine/Window.cs
@@ -1,10 +1,12 @@
+namespace mine2d.engine;
+
class Window
{
IntPtr window;
public Window(string title, int w, int h)
{
- window = SDL_CreateWindow(
+ this.window = SDL_CreateWindow(
title,
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
@@ -41,4 +43,4 @@ class Window
{
return this.window;
}
-}
+}
\ No newline at end of file
diff --git a/src/engine/system/EventPriority.cs b/src/engine/system/EventPriority.cs
index 3adb334..200c9d9 100644
--- a/src/engine/system/EventPriority.cs
+++ b/src/engine/system/EventPriority.cs
@@ -1,4 +1,6 @@
-enum EventPriority : int
+namespace mine2d.engine.system;
+
+enum EventPriority
{
Lowest = 0,
Low = 1,
@@ -6,4 +8,4 @@ enum EventPriority : int
High = 3,
Highest = 4,
Important = 5,
-}
+}
\ No newline at end of file
diff --git a/src/engine/system/annotations/Interactor.cs b/src/engine/system/annotations/Interactor.cs
index 0aec9f7..c790fea 100644
--- a/src/engine/system/annotations/Interactor.cs
+++ b/src/engine/system/annotations/Interactor.cs
@@ -1,3 +1,5 @@
+namespace mine2d.engine.system.annotations;
+
enum InteractorKind
{
Client,
@@ -19,4 +21,4 @@ class Interaction : Attribute
this.Type = type;
this.Kind = kind;
}
-}
+}
\ No newline at end of file
diff --git a/src/engine/utils/Color.cs b/src/engine/utils/Color.cs
index ab3c5fb..bedd031 100644
--- a/src/engine/utils/Color.cs
+++ b/src/engine/utils/Color.cs
@@ -1,33 +1,35 @@
+namespace mine2d.engine.utils;
+
class Color
{
- public int r,
- g,
- b,
- a;
+ public int R,
+ G,
+ B,
+ A;
public Color(int r, int g, int b, int a)
{
- this.r = r;
- this.g = g;
- this.b = b;
- this.a = a;
+ this.R = r;
+ this.G = g;
+ this.B = b;
+ this.A = a;
}
public Color(int r, int g, int b)
{
- this.r = r;
- this.g = g;
- this.b = b;
- this.a = 255;
+ this.R = r;
+ this.G = g;
+ this.B = b;
+ this.A = 255;
}
- public SDL_Color toSDLColor()
+ public SDL_Color ToSdlColor()
{
SDL_Color color = new();
- color.r = (byte)r;
- color.g = (byte)g;
- color.b = (byte)b;
- color.a = (byte)a;
+ color.r = (byte)this.R;
+ color.g = (byte)this.G;
+ color.b = (byte)this.B;
+ color.a = (byte)this.A;
return color;
}
-}
+}
\ No newline at end of file
diff --git a/src/engine/utils/Point.cs b/src/engine/utils/Point.cs
index 585457e..ae36590 100644
--- a/src/engine/utils/Point.cs
+++ b/src/engine/utils/Point.cs
@@ -1,7 +1,9 @@
+namespace mine2d.engine.utils;
+
class Point
{
public static double Distance(double x1, double y1, double x2, double y2)
{
return Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2));
}
-}
+}
\ No newline at end of file
diff --git a/src/frontend/Frontend.cs b/src/frontend/Frontend.cs
index 43a33dc..8da2e6e 100644
--- a/src/frontend/Frontend.cs
+++ b/src/frontend/Frontend.cs
@@ -1,3 +1,10 @@
+using mine2d.backend.data;
+using mine2d.core;
+using mine2d.core.data;
+using mine2d.frontend.renderer;
+
+namespace mine2d.frontend;
+
class Frontend : IFrontend
{
public void Init()
@@ -44,7 +51,7 @@ class Frontend : IFrontend
}
if (e.type == SDL_EventType.SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT)
{
- var amp = ctx.FrontendGameState.MousePosition / ctx.FrontendGameState.Settings.GameScale + ctx.FrontendGameState.Camera.position;
+ var amp = ctx.FrontendGameState.MousePosition / ctx.FrontendGameState.Settings.GameScale + ctx.FrontendGameState.Camera.Position;
if (ctx.GameState.World.HasChunkAt(amp))
{
var chunk = ctx.GameState.World.GetChunkAt(amp);
@@ -122,9 +129,9 @@ class Frontend : IFrontend
if (
e.key.keysym.scancode
is SDL_Scancode.SDL_SCANCODE_A
- or SDL_Scancode.SDL_SCANCODE_D
- or SDL_Scancode.SDL_SCANCODE_W
- or SDL_Scancode.SDL_SCANCODE_S
+ or SDL_Scancode.SDL_SCANCODE_D
+ or SDL_Scancode.SDL_SCANCODE_W
+ or SDL_Scancode.SDL_SCANCODE_S
&& e.key.repeat == 0
&& e.type is SDL_EventType.SDL_KEYDOWN or SDL_EventType.SDL_KEYUP
)
@@ -156,29 +163,29 @@ class Frontend : IFrontend
{
if (player.Name == ctx.FrontendGameState.PlayerName)
{
- ctx.Renderer.SetColor(0, 0, 255, 255);
+ ctx.Renderer.SetColor(0, 0, 255);
}
else
{
- ctx.Renderer.SetColor(255, 0, 0, 255);
+ ctx.Renderer.SetColor(255, 0, 0);
}
ctx.Renderer.DrawRect(
- (player.Position.X - (int)camera.position.X) * scale,
- (player.Position.Y - (int)camera.position.Y) * scale - 32 * scale,
+ (player.Position.X - (int)camera.Position.X) * scale,
+ (player.Position.Y - (int)camera.Position.Y) * scale - 32 * scale,
16 * scale,
32 * scale
);
});
- var absoluteMousePos = ctx.FrontendGameState.MousePosition / ctx.FrontendGameState.Settings.GameScale + camera.position;
+ var absoluteMousePos = ctx.FrontendGameState.MousePosition / ctx.FrontendGameState.Settings.GameScale + camera.Position;
if (ctx.GameState.World.HasTileAt((int)absoluteMousePos.X, (int)absoluteMousePos.Y))
{
var a = Constants.TileSize;
var tilePos = new Vector2(absoluteMousePos.X - absoluteMousePos.X % a, absoluteMousePos.Y - absoluteMousePos.Y % a);
- ctx.Renderer.SetColor(255, 255, 255, 255);
+ ctx.Renderer.SetColor(255, 255, 255);
ctx.Renderer.DrawOutline(
- (int)tilePos.X * scale - (int)camera.position.X * scale,
- (int)tilePos.Y * scale - (int)camera.position.Y * scale,
+ (int)tilePos.X * scale - (int)camera.Position.X * scale,
+ (int)tilePos.Y * scale - (int)camera.Position.Y * scale,
16 * scale,
16 * scale
);
@@ -186,4 +193,4 @@ class Frontend : IFrontend
ctx.Renderer.Present();
}
-}
+}
\ No newline at end of file
diff --git a/src/frontend/IFrontend.cs b/src/frontend/IFrontend.cs
index 06df2db..fca0a75 100644
--- a/src/frontend/IFrontend.cs
+++ b/src/frontend/IFrontend.cs
@@ -1,5 +1,7 @@
+namespace mine2d.frontend;
+
interface IFrontend
{
public void Process();
public void Init();
-}
+}
\ No newline at end of file
diff --git a/src/frontend/renderer/IRenderer.cs b/src/frontend/renderer/IRenderer.cs
index 7423328..af1c3cb 100644
--- a/src/frontend/renderer/IRenderer.cs
+++ b/src/frontend/renderer/IRenderer.cs
@@ -1,4 +1,6 @@
+namespace mine2d.frontend.renderer;
+
interface IRenderer
{
public void Render();
-}
+}
\ No newline at end of file
diff --git a/src/frontend/renderer/WorldRenderer.cs b/src/frontend/renderer/WorldRenderer.cs
index 28267a1..42990cc 100644
--- a/src/frontend/renderer/WorldRenderer.cs
+++ b/src/frontend/renderer/WorldRenderer.cs
@@ -1,3 +1,7 @@
+using mine2d.core;
+
+namespace mine2d.frontend.renderer;
+
class WorldRenderer : IRenderer
{
public void Render()
@@ -25,4 +29,4 @@ class WorldRenderer : IRenderer
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/network/Converter.cs b/src/network/Converter.cs
index 2aa6a1f..b14a42f 100644
--- a/src/network/Converter.cs
+++ b/src/network/Converter.cs
@@ -1,6 +1,9 @@
using System.Text;
-using Newtonsoft.Json.Linq;
+using mine2d.backend.data;
using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
+namespace mine2d.network;
class Converter
{
@@ -33,4 +36,4 @@ class Converter
var jsonString = JsonConvert.SerializeObject(packet);
return Encoding.UTF8.GetBytes(jsonString);
}
-}
+}
\ No newline at end of file
diff --git a/src/state/GameState.cs b/src/state/GameState.cs
index 4715814..a00dedd 100644
--- a/src/state/GameState.cs
+++ b/src/state/GameState.cs
@@ -1,3 +1,8 @@
+using mine2d.core;
+using mine2d.core.data;
+
+namespace mine2d.state;
+
class FrontendGameState
{
public Vector2 MovementInput;
@@ -14,7 +19,7 @@ class FrontendGameState
class Settings
{
public int GameScale = 4;
- public int UIScale = 4;
+ public int UiScale = 4;
public bool ShowCollision = true;
public bool Fullscreen = false;
}
@@ -23,4 +28,4 @@ class GameState
{
public List Players { get; set; } = new List();
public World World { get; set; }
-}
+}
\ No newline at end of file
diff --git a/src/state/Player.cs b/src/state/Player.cs
index 519a753..0292ce6 100644
--- a/src/state/Player.cs
+++ b/src/state/Player.cs
@@ -1,3 +1,7 @@
+using mine2d.engine;
+
+namespace mine2d.state;
+
class Player
{
public string Name;
@@ -11,4 +15,4 @@ class Player
{
return new Line(this.Position, this.Position + new Vector2(16, 0));
}
-}
+}
\ No newline at end of file