diff --git a/.gitignore b/.gitignore
index 9e6528f..4daaf92 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,4 +13,5 @@ riderModule.iml
*.mgcb
#Visual Studio
-.vs/
\ No newline at end of file
+.vs/
+/Blocktest/Content/Graphics/Player/placeholder-base.png
diff --git a/Blocktest/Blocktest.csproj b/Blocktest/Blocktest.csproj
index 86e500c..21c7484 100644
--- a/Blocktest/Blocktest.csproj
+++ b/Blocktest/Blocktest.csproj
@@ -12,12 +12,12 @@
Icon.ico
-
-
+
+
-
-
+
+
true
@@ -26,17 +26,17 @@
-
+
-
+
-
+
-
-
+
+
\ No newline at end of file
diff --git a/Blocktest/Code/Networking/Client.cs b/Blocktest/Code/Networking/Client.cs
index 1f7ae50..ee34ad5 100644
--- a/Blocktest/Code/Networking/Client.cs
+++ b/Blocktest/Code/Networking/Client.cs
@@ -15,6 +15,7 @@ public sealed class Client : NetworkInterface {
private readonly BlocktestGame _game;
private readonly Dictionary _playerRenderables = new();
private bool _initialized;
+ public bool WorldDownloaded;
public Client(WorldState worldState, Camera camera, BlocktestGame game) : base(worldState) {
_camera = camera;
@@ -76,6 +77,11 @@ protected override void HandlePackets(NetDataReader packetReader, int sourceId,
}, Server);
_initialized = true;
+
+ if (!WorldDownloaded)
+ {
+ WorldDownloaded = true; // nyehhh i dont know what i'm doing with this
+ }
break;
default:
Console.WriteLine("Bad packet!!!");
diff --git a/Blocktest/Code/Rendering/Renderable.cs b/Blocktest/Code/Rendering/Renderable.cs
index 232d81a..d6c066e 100644
--- a/Blocktest/Code/Rendering/Renderable.cs
+++ b/Blocktest/Code/Rendering/Renderable.cs
@@ -3,9 +3,9 @@ namespace Blocktest.Rendering;
public enum Layer {
Top = 0,
- Player = 1,
+ Player = 3,
Default = 2,
- ForegroundBlocks = 3,
+ ForegroundBlocks = 1,
BackgroundBlocks = 4
}
diff --git a/Blocktest/Code/Scenes/GameScene.cs b/Blocktest/Code/Scenes/GameScene.cs
index 106db44..259bdbc 100644
--- a/Blocktest/Code/Scenes/GameScene.cs
+++ b/Blocktest/Code/Scenes/GameScene.cs
@@ -1,3 +1,4 @@
+using System.Diagnostics;
using System.Linq;
using System.Net;
using Blocktest.Block_System;
@@ -27,6 +28,9 @@ public sealed class GameScene : IScene {
private readonly Client _networkingClient;
private readonly SpriteBatch _spriteBatch;
+ private readonly Vector2 _cameraPosition;
+ private Vector2 _cameraStayPosition;
+
private readonly WorldState _worldState = new();
private KeyboardState _previousKeyboardState;
@@ -37,7 +41,8 @@ public GameScene(BlocktestGame game, bool doConnect, IPEndPoint? ip) {
_spriteBatch = new SpriteBatch(game.GraphicsDevice);
_game = game;
- _camera = new Camera(Vector2.Zero, new Vector2(640, 360), game.GraphicsDevice);
+ _cameraPosition = Vector2.Zero;
+ _camera = new Camera(_cameraPosition, new Vector2(640, 360), game.GraphicsDevice);
_backgroundTilemapSprites = new RenderableTilemap(_worldState.Foreground, _camera);
_foregroundTilemapSprites = new RenderableTilemap(_worldState.Background, _camera);
@@ -70,7 +75,10 @@ public void Update(GameTime gameTime) {
_networkingClient.Update();
}
- HandleInput();
+ if (!_connect || _networkingClient.WorldDownloaded)
+ {
+ HandleInput();
+ }
_networkingClient.LocalTickBuffer.IncrCurrTick(_worldState);
}
@@ -147,13 +155,16 @@ private void HandleInput() {
moveVector.Y -= moveValue;
}
+ int selfId = _networkingClient.Server?.RemoteId ?? 0;
if (moveVector != Vector2.Zero) {
- _camera.Position += moveVector;
+ //_camera.Position += moveVector;
+ Debug.WriteLine(selfId);
MovePlayer movementPacket = new() {
TickNum = _networkingClient.LocalTickBuffer.CurrTick,
- Position = (Vector2Int)_camera.Position,
- SourceId = _networkingClient.Server?.RemoteId ?? 0
+ //Position = (Vector2Int)_camera.Position,
+ AddToPosition = (Vector2Int)moveVector,
+ SourceId = selfId
};
_networkingClient.LocalTickBuffer.AddPacket(movementPacket);
if (_connect) {
@@ -161,6 +172,26 @@ private void HandleInput() {
}
}
+ // allows free camera movement with lctrl, returns to player
+ Vector2 cameraMoveVector = Vector2.Zero;
+ if (currentKeyboardState.IsKeyDown(Keys.LeftControl))
+ {
+ if (_camera.RenderLocation.Contains(currentMouseState.Position))
+ {
+ cameraMoveVector.X = (currentMouseState.Position.X - _camera.RenderLocation.Center.X) / 10;
+ cameraMoveVector.Y = -(currentMouseState.Position.Y - _camera.RenderLocation.Center.Y) / 10;
+ }
+ if (cameraMoveVector != Vector2.Zero)
+ {
+ _camera.Position += cameraMoveVector;
+ }
+ }
+ else
+ {
+ _camera.Position.X = _worldState.PlayerPositions[selfId].Position.X - _camera.RenderTarget.Width / 2;
+ _camera.Position.Y = _worldState.PlayerPositions[selfId].Position.Y - _camera.RenderTarget.Height / 2;
+ }
+
_previousKeyboardState = currentKeyboardState;
if (currentMouseState.LeftButton != ButtonState.Pressed &&
diff --git a/Shared/Code/Packets/MovePlayer.cs b/Shared/Code/Packets/MovePlayer.cs
index 03cd5ba..55eec3e 100644
--- a/Shared/Code/Packets/MovePlayer.cs
+++ b/Shared/Code/Packets/MovePlayer.cs
@@ -1,8 +1,12 @@
using LiteNetLib.Utils;
+using System.Diagnostics;
namespace Shared.Code.Packets;
public sealed class MovePlayer : IPacket {
public Vector2Int Position { get; set; }
+
+ public Vector2Int AddToPosition { get; set; }
+
public ushort TickNum { get; init; }
public int SourceId { get; init; }
@@ -16,7 +20,8 @@ public void Deserialize(NetDataReader reader) {
}
public void Process(WorldState worldState) {
- worldState.PlayerPositions[SourceId].Position = Position + new Vector2Int(256, 128);
+ //worldState.PlayerPositions[SourceId].Position = Position + new Vector2Int(256, 128);
+ worldState.PlayerPositions[SourceId].Position += AddToPosition;
}
public PacketType GetPacketType() => PacketType.MovePlayer;