diff --git a/FNAF_Clone.sln.DotSettings.user b/FNAF_Clone.sln.DotSettings.user index f51aa32..407f818 100644 --- a/FNAF_Clone.sln.DotSettings.user +++ b/FNAF_Clone.sln.DotSettings.user @@ -5,11 +5,13 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded \ No newline at end of file diff --git a/FNAF_Clone/Client.cs b/FNAF_Clone/Client.cs index 3fa6d5c..6955f2b 100644 --- a/FNAF_Clone/Client.cs +++ b/FNAF_Clone/Client.cs @@ -2,6 +2,7 @@ using System; using System.Linq; using System.Net; using System.Net.Sockets; +using System.Threading; using FNAF_Clone.GUI; using FNAF_Clone.Map; using GlobalClassLib; @@ -11,7 +12,21 @@ using PacketLib; namespace FNAF_Clone; -public class Client { +public class Client { + public enum ConnectionState { + IDLE, + CONNECTING, + CONNECTED, + ACCEPTED, + GAME_STARTING, + GAME_IN_PROGRESS, + SERVER_NOT_FOUND, + SERVER_FULL, + ERROR + } + + public static ConnectionState State { get; private set; } = ConnectionState.IDLE; + private static EventBasedNetListener listener = new(); private static NetManager client; private static NetPeer server; @@ -24,6 +39,7 @@ public class Client { public static ClientPlayer GetPlayer(int pid) => Player.state.pid == pid ? Player : Opponent; public static void Connect(string endPoint, int port) { + State = ConnectionState.CONNECTING; writer = new NetDataWriter(); processor = new NetPacketProcessor(); @@ -32,7 +48,11 @@ public class Client { processor.SubscribeReusable(OnJoinAccept); processor.SubscribeReusable(OnPlayerUpdate); processor.SubscribeReusable(OnMapInit); - processor.SubscribeReusable(packet => Opponent.state = packet.state); + processor.SubscribeReusable(packet => { // TODO: move this to a method + Opponent.state = packet.state; + Opponent.username = packet.username; + State = ConnectionState.GAME_STARTING; + }); client = new NetManager(listener){ AutoRecycle = true @@ -48,10 +68,11 @@ public class Client { listener.PeerConnectedEvent += peer => { Console.WriteLine("Connected to Server"); server = peer; - SendPacket(new JoinPacket {username = "Player1"}, DeliveryMethod.ReliableOrdered); + State = ConnectionState.CONNECTED; + SendPacket(new JoinPacket {username = Player.username == "" ? "Anonymous" : Player.username}, DeliveryMethod.ReliableOrdered); }; - client.Connect(endPoint, port, ""); // TODO: figure out how keys work + new Thread(() => client.Connect(endPoint, port, "")).Start(); // TODO: figure out how keys work } public static void SendPacket(T packet, DeliveryMethod deliveryMethod) where T : class, new() { @@ -71,6 +92,7 @@ public class Client { private static void OnJoinAccept(JoinAcceptPacket packet) { Console.WriteLine($"Accepted by server, pid: {packet.state.pid}"); + State = ConnectionState.ACCEPTED; Player.state = packet.state; } @@ -83,8 +105,7 @@ public class Client { TileConnectorProjection[] connectors = connectorsData.Select(c => new TileConnectorProjection(ClientMapManager.Get(c.id1), ClientMapManager.Get(c.id2), c.type)).ToArray(); ClientMapManager.InitConnectors(connectors); - UIManager.InitUI(); - UIManager.SpawnDoors(connectors.Where(c => c.Type == ConnectorType.DOOR_REMOTE).ToArray()); + UIManager.SpawnMapElements(connectors.Where(c => c.Type == ConnectorType.DOOR_REMOTE).ToArray()); } diff --git a/FNAF_Clone/CommandManager.cs b/FNAF_Clone/CommandManager.cs index c21cdbe..73cba39 100644 --- a/FNAF_Clone/CommandManager.cs +++ b/FNAF_Clone/CommandManager.cs @@ -25,7 +25,7 @@ public class CommandManager { Array.ForEach(keybinds, tuple => InputManager.AddListener(tuple.label, tuple.key, () => tuple.action(), InputTiming.PRESS, allControlsHook)); } - public static void AllowInput(bool state) { + public static void AllowGameControls(bool state) { allControlsHook.Enabled = state; } diff --git a/FNAF_Clone/Content/ponderosa.spritefont b/FNAF_Clone/Content/ponderosa.spritefont index fa8b598..27d8754 100755 --- a/FNAF_Clone/Content/ponderosa.spritefont +++ b/FNAF_Clone/Content/ponderosa.spritefont @@ -17,7 +17,7 @@ with. Size is a float value, measured in points. Modify this value to change the size of the font. --> - 20 + 40