diff --git a/FNAF_Clone/CommandManager.cs b/FNAF_Clone/CommandManager.cs index 11ccf8f..5f2999f 100644 --- a/FNAF_Clone/CommandManager.cs +++ b/FNAF_Clone/CommandManager.cs @@ -60,6 +60,7 @@ public class CommandManager { public static void SendChangeCamera(int id) { Client.Player.state.camera = id; + UIManager.ChangeCamera(id); Client.SendCommands([PlayerCommand.SWITCH_CAM(id)]); MapTileProjection tile = ClientMapManager.Get(id); // add UIManager switch camera diff --git a/FNAF_Clone/Content/images/SpriteSheet_monitor.png b/FNAF_Clone/Content/images/SpriteSheet_monitor.png index bc67efe..6b32e4e 100644 Binary files a/FNAF_Clone/Content/images/SpriteSheet_monitor.png and b/FNAF_Clone/Content/images/SpriteSheet_monitor.png differ diff --git a/FNAF_Clone/Content/images/monitor-definition.xml b/FNAF_Clone/Content/images/monitor-definition.xml index 4985f07..c80bec1 100644 --- a/FNAF_Clone/Content/images/monitor-definition.xml +++ b/FNAF_Clone/Content/images/monitor-definition.xml @@ -1,5 +1,5 @@ - + images/SpriteSheet_monitor @@ -25,6 +25,14 @@ + + + + + + + + diff --git a/FNAF_Clone/EventProcessor.cs b/FNAF_Clone/EventProcessor.cs index ca216b4..6b3b0bb 100644 --- a/FNAF_Clone/EventProcessor.cs +++ b/FNAF_Clone/EventProcessor.cs @@ -19,16 +19,25 @@ public class EventProcessor { break; case 2: // switch cam - if (Client.Player.state.pid != e.Args[0]) return; + if (Client.Player.state.pid != e.Args[0]){ + UIManager.ChangeCameraOpponent(e.Args[1]); + break; + } if (Client.Player.state.camera != e.Args[1]) Console.WriteLine("!!! DESYNC: CAMERA STATE"); Console.WriteLine($"E: player {e.Args[0]} switched to camera {e.Args[1]}"); break; case 3: // toggle cam - if (e.Args[0] == Client.Player.state.pid && Client.Player.state.monitorUp != (e.Args[1] == 1)) Console.WriteLine("!!! DESYNC: MONITOR STATE"); + Console.WriteLine($"E: Player {e.Args[0]} toggled monitor {(e.Args[1] == 0 ? "off" : "on")}"); + + if (e.Args[0] != Client.Player.state.pid){ + UIManager.ChangeMonitorStateOpponent(e.Args[1] == 1); + break; + } + + if (Client.Player.state.monitorUp != (e.Args[1] == 1)) Console.WriteLine("!!! DESYNC: MONITOR STATE"); // UIManager.ChangeMonitorState(e.Args[1] == 1); - Console.WriteLine($"E: Player {e.Args[0]} toggled monitor {(e.Args[1] == 0 ? "off" : "on")}"); break; case 4: // toggle door diff --git a/FNAF_Clone/GUI/UIElement.cs b/FNAF_Clone/GUI/UIElement.cs index d4d9d63..7166e29 100644 --- a/FNAF_Clone/GUI/UIElement.cs +++ b/FNAF_Clone/GUI/UIElement.cs @@ -14,7 +14,11 @@ public class UIElement { public bool Pressable { get; set; } = false; public bool Visible { get; set; } = true; - public (Point, Point) Bounds{ get; private set; } // TODO: Change this to support non-rectangular hitboxes + public (Point, Point) Bounds{ + get; + private set { field = value; UpdateBounds(); } + } // TODO: Change this to support non-rectangular hitboxes + private (Point, Point) screenSpaceBounds; private List textures = new(); private int currentTextureId = 0; @@ -32,6 +36,10 @@ public class UIElement { private int pixelScaleMultiplier = 1; private void LoadPixelScaleMultiplier() { pixelScaleMultiplier = (int)(UIManager.GlobalPixelMultiplier * _scaleMultiplier); // TODO: move GlobalPixelMultiplier somewhere where it would make sense + UpdateBounds(); + } + + private void UpdateBounds() { screenSpaceBounds = (Bounds.Item1.MultiplyByScalar(pixelScaleMultiplier), Bounds.Item2.MultiplyByScalar(pixelScaleMultiplier)); } @@ -85,4 +93,8 @@ public class UIElement { textures[currentTextureId].Draw(spriteBatch, screenSpaceBounds.Item1.ToVector2(), Color.White, 0, Vector2.Zero, pixelScaleMultiplier, SpriteEffects.None, 0); // texture.Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White); } + + public void SetPosition(Point position) { + Bounds = (position, position + new Point(textures[0].Width, textures[0].Height)); + } } \ No newline at end of file diff --git a/FNAF_Clone/GUI/UIManager.cs b/FNAF_Clone/GUI/UIManager.cs index aae5c2b..4afd137 100644 --- a/FNAF_Clone/GUI/UIManager.cs +++ b/FNAF_Clone/GUI/UIManager.cs @@ -63,6 +63,10 @@ public class UIManager { // } } } + + monitorScreen.AddElement("eye-player", new UIElement(monitorAtlas[24], monitorScreen["room"+Client.Player.state.camera].Bounds.Item1)); + monitorScreen.AddElement("eye-opponent", new UIElement([monitorAtlas[23], monitorAtlas[22]], monitorScreen["room"+Client.Opponent.state.camera].Bounds.Item1)); + } public static void SpawnDoors(TileConnectorProjection[] doors) { @@ -126,10 +130,25 @@ public class UIManager { public static void ChangeRemoteDoorState((int, int) id, bool state) { monitorScreen["door"+Math.Max(id.Item1, id.Item2)+"-"+Math.Min(id.Item1, id.Item2)].SetTexture(state ? 1 : 0); } - + public static void ChangeMonitorState(bool state) { Screen.SetScreen(state ? ScreenTypes.CAMERAS : ScreenTypes.OFFICE); } + + public static void ChangeMonitorStateOpponent(bool state) { + monitorScreen["eye-opponent"].SetTexture(state ? 1 : 0); + } + + public static void ChangeCamera(int id) { + monitorScreen["eye-player"].SetPosition(monitorScreen["room"+id].Bounds.Item1); + } + public static void ChangeCameraOpponent(int id) { + monitorScreen["eye-opponent"].SetPosition(monitorScreen["room"+id].Bounds.Item1); + + } - + // private static Point GetRoomUIPos((int x, int y) pos) { + // return new Point(336 + (32 * pos.x), 144 + (32 * pos.y)); + // } + } \ No newline at end of file diff --git a/FNAF_Server/GameLogic.cs b/FNAF_Server/GameLogic.cs index 56e62e2..550303f 100644 --- a/FNAF_Server/GameLogic.cs +++ b/FNAF_Server/GameLogic.cs @@ -6,6 +6,8 @@ namespace FNAF_Server; public class GameLogic { + public const int START_CAMERA = 12; + public static void Init() { // Create map MapManager.InitMap(); diff --git a/FNAF_Server/Server.cs b/FNAF_Server/Server.cs index ccfb27e..c9e991d 100644 --- a/FNAF_Server/Server.cs +++ b/FNAF_Server/Server.cs @@ -25,7 +25,7 @@ public class Server { private static NetPacketProcessor processor; private static bool isRunning; - + public static void Start(int port) { writer = new NetDataWriter(); processor = new NetPacketProcessor(); @@ -102,7 +102,7 @@ public class Server { peer = peer, state = new PlayerState { pid = peer.Id, - camera = 0, + camera = GameLogic.START_CAMERA, doorStates = [false, false, false] }, username = packet.username