Přidán build script, předělaná struktura, funkční spouštění serveru z clienta. Client je schopen fungovat po více her bez restartu. Bugfixy
This commit is contained in:
parent
c942d23a87
commit
1a27dd6fab
22 changed files with 269 additions and 136 deletions
5
.idea/.idea.FNAF_Clone/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/.idea.FNAF_Clone/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
|
|
@ -12,10 +12,17 @@
|
|||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AKeyValuePair_00602_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F384e456bc26f45f5a6a6a20ae50c6e0dd1a400_003Fe8_003F7272ae72_003FKeyValuePair_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AList_00601_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003Fe4_003F9c3fcf71_003FList_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetManager_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003Fd6_003Fec041615_003FNetManager_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetPacketProcessor_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003F68_003Fc826a80a_003FNetPacketProcessor_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetSerializer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003Fcc_003F8a34584a_003FNetSerializer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASdlGamePlatform_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa69b121f85054691b2a8d28643003c23136600_003F57_003F45ea073b_003FSdlGamePlatform_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASpriteBatch_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa69b121f85054691b2a8d28643003c23136600_003F98_003F17ad8de4_003FSpriteBatch_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThread_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003Fb3_003F92670209_003FThread_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThread_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Ffd792102e2a04b889c29784ca9de4981d1a000_003F2a_003Fa31b08a3_003FThread_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelpers_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003F48_003F95b0ef9d_003FThrowHelpers_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelper_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003Ffb_003Fa0fd6fc3_003FThrowHelper_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelper_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Ffd792102e2a04b889c29784ca9de4981d1a000_003F8f_003F6419ac7c_003FThrowHelper_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATitleContainer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa69b121f85054691b2a8d28643003c23136600_003F62_003F374a72ad_003FTitleContainer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AValueTuple_00602_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003F09_003F312b9770_003FValueTuple_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AValueTuple_00602_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003F09_003F312b9770_003FValueTuple_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue"><AssemblyExplorer>
|
||||
<Assembly Path="/home/perry/RiderProjects/FNAF_Clone/FNAF_Clone/link/MonoGameLibrary.dll" />
|
||||
</AssemblyExplorer></s:String></wpf:ResourceDictionary>
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
|
@ -38,8 +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;
|
||||
public static void Init() {
|
||||
writer = new NetDataWriter();
|
||||
processor = new NetPacketProcessor();
|
||||
|
||||
|
|
@ -58,9 +58,6 @@ public class Client {
|
|||
AutoRecycle = true
|
||||
};
|
||||
|
||||
client.Start();
|
||||
Console.WriteLine($"Connecting to server @ {endPoint}:{port}");
|
||||
|
||||
listener.NetworkReceiveEvent += (peer, reader, channel, method) => {
|
||||
OnNetworkReceive(peer, reader, method);
|
||||
};
|
||||
|
|
@ -71,6 +68,13 @@ public class Client {
|
|||
State = ConnectionState.CONNECTED;
|
||||
SendPacket(new JoinPacket {username = Player.username == "" ? "Anonymous" : Player.username}, DeliveryMethod.ReliableOrdered);
|
||||
};
|
||||
}
|
||||
|
||||
public static void Connect(string endPoint, int port) {
|
||||
State = ConnectionState.CONNECTING;
|
||||
|
||||
client.Start();
|
||||
Console.WriteLine($"Connecting to server @ {endPoint}:{port}");
|
||||
|
||||
new Thread(() => client.Connect(endPoint, port, "")).Start(); // TODO: figure out how keys work
|
||||
}
|
||||
|
|
@ -108,9 +112,18 @@ public class Client {
|
|||
public static void OnPlayerUpdate(UpdatePlayerPacket packet) { // TODO: move this to a separate class
|
||||
EventProcessor.Evaluate(packet.events);
|
||||
//Player.state = Player.state.pid == 0 ? packet.stateP1 : packet.stateP2;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void Disconnect() {
|
||||
if (client == null || client.ConnectedPeersCount == 0) return;
|
||||
client.DisconnectAll();
|
||||
client.Stop();
|
||||
State = ConnectionState.IDLE;
|
||||
}
|
||||
|
||||
public static void StartServer() {
|
||||
Process.Start("FNAF_Server");
|
||||
// new Thread(() => Server.Start(9012)).Start();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -99,4 +99,8 @@ public static class ClientEnemyManager {
|
|||
|
||||
return output.ToArray();
|
||||
}
|
||||
|
||||
public static void ClearEnemies() {
|
||||
enemies.Clear();
|
||||
}
|
||||
}
|
||||
|
|
@ -105,6 +105,8 @@ public class EventProcessor {
|
|||
case 11:
|
||||
Console.WriteLine($"E: Player {e.Args[0]} won");
|
||||
if(Client.Player.state.pid == e.Args[0]) UIManager.ShowVictoryScreen();
|
||||
Client.Disconnect();
|
||||
ClientEnemyManager.ClearEnemies();
|
||||
break;
|
||||
|
||||
case 12: // game start
|
||||
|
|
|
|||
|
|
@ -11,6 +11,12 @@
|
|||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<ApplicationIcon>Icon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<OutputPath>../bin/Client/</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<OutputPath>../bin/Debug/Client/</OutputPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Icon.ico"/>
|
||||
<None Remove="Icon.bmp"/>
|
||||
|
|
@ -31,16 +37,21 @@
|
|||
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.*"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="lib\" />
|
||||
<Folder Include="link\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MonoGameLibrary">
|
||||
<HintPath>lib\MonoGameLibrary.dll</HintPath>
|
||||
<HintPath>link\MonoGameLibrary.dll</HintPath>
|
||||
</Reference>
|
||||
<!-- <Reference Include="FNAF_Server">-->
|
||||
<!-- <HintPath>link\FNAF_Server.dll</HintPath>-->
|
||||
<!-- </Reference>-->
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GlobalClassLib\GlobalClassLib.csproj" />
|
||||
<ProjectReference Include="..\PacketLib\PacketLib.csproj" />
|
||||
<!-- <ProjectReference Include="..\FNAF_Server\FNAF_Server.csproj" />-->
|
||||
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Remove="Input\**" />
|
||||
|
|
|
|||
|
|
@ -74,6 +74,8 @@ public class Screen {
|
|||
private InputListenerHook mouseInputHook = new(true);
|
||||
private bool temporary = false;
|
||||
|
||||
private List<string> temporaryElements = new();
|
||||
|
||||
public Screen(string label) {
|
||||
Label = label;
|
||||
InputManager.AddListener(InputManager.MouseButton.LEFT, () => ProcessMouseInput(InputManager.MouseState), InputTiming.PRESS, mouseInputHook);
|
||||
|
|
@ -87,7 +89,7 @@ public class Screen {
|
|||
public UIElement this[string id] => elements[id];
|
||||
public UIElement TryGetElement(string id) => elements.TryGetValue(id, out var val) ? val : null;
|
||||
|
||||
public UIElement AddElement(string id, UIElement element) {
|
||||
public UIElement AddElement(string id, UIElement element, bool temporary = false) {
|
||||
elements.Add(id, element);
|
||||
|
||||
int insertIndex = elementsInDrawOrder.FindLastIndex(e => e.DrawPriority == element.DrawPriority);
|
||||
|
|
@ -98,9 +100,24 @@ public class Screen {
|
|||
elementsInDrawOrder.Insert(insertIndex + 1, element);
|
||||
}
|
||||
|
||||
if (temporary){
|
||||
temporaryElements.Add(id);
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public void RemoveElement(string id) {
|
||||
if (!elements.ContainsKey(id)) return;
|
||||
elements.Remove(id, out var element);
|
||||
elementsInDrawOrder.RemoveAll(e => e == element);
|
||||
}
|
||||
|
||||
public void RemoveTemporary() {
|
||||
temporaryElements.ForEach(RemoveElement);
|
||||
temporaryElements.Clear();
|
||||
}
|
||||
|
||||
public void SetActive(bool active) {
|
||||
Active = active;
|
||||
if (Active == active) return;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class TimerUIElement : TextUIElement{
|
|||
}
|
||||
|
||||
public void Start() {
|
||||
stopwatch.Start();
|
||||
stopwatch.Restart();
|
||||
}
|
||||
|
||||
public void Stop() {
|
||||
|
|
|
|||
|
|
@ -88,6 +88,14 @@ public class UIManager {
|
|||
cameraView = new UIElement(rooms.ToArray(), new(64, 64));
|
||||
monitorScreen.AddElement("camera-view", cameraView);
|
||||
|
||||
monitorScreen.AddElement("p1-office-door-left", new UIElement([MonitorAtlas["door-office-p1-left-open"], MonitorAtlas["door-office-p1-left-closed"]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p1-office-door-centre", new UIElement([MonitorAtlas["door-office-p1-centre-open"], MonitorAtlas["door-office-p1-centre-closed"]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p1-office-door-right", new UIElement([MonitorAtlas["door-office-p1-right-open"], MonitorAtlas["door-office-p1-right-closed"]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p2-office-door-right", new UIElement([MonitorAtlas["door-office-p2-right-open"], MonitorAtlas["door-office-p2-right-closed"]], new Point(400, 144)));
|
||||
monitorScreen.AddElement("p2-office-door-centre", new UIElement([MonitorAtlas["door-office-p2-centre-open"], MonitorAtlas["door-office-p2-centre-closed"]], new Point(400, 144)));
|
||||
monitorScreen.AddElement("p2-office-door-left", new UIElement([MonitorAtlas["door-office-p2-left-open"], MonitorAtlas["door-office-p2-left-closed"]], new Point(400, 144)));
|
||||
|
||||
|
||||
// main menu
|
||||
timerElement = new(new(0, 0), PixelMonoFont);
|
||||
overlayScreen.AddElement("timer", timerElement);
|
||||
|
|
@ -119,19 +127,69 @@ public class UIManager {
|
|||
}
|
||||
});
|
||||
menuScreen.AddElement("host-button",
|
||||
new TextUIElement(new(connectButton.Bounds.Item1.X, connectButton.Bounds.Item2.Y + 30), PixelMonoFont) {Text = "HOST"});
|
||||
new TextUIElement(new(connectButton.Bounds.Item1.X, connectButton.Bounds.Item2.Y + 30), PixelMonoFont) {Text = "HOST", Pressable = true,
|
||||
OnMousePress = () => {
|
||||
Client.StartServer();
|
||||
Client.Player.username = usernameField.Text;
|
||||
Client.Connect("127.0.0.1", 9012);
|
||||
Screen.SetScreen(ScreenTypes.LOADING);
|
||||
|
||||
}});
|
||||
|
||||
loadingScreen.AddElement("loading-text", new LoadingUIElement(new(320, 180), PixelMonoFont, field.Text));
|
||||
|
||||
}
|
||||
|
||||
public static void DisplayMainMenu() {
|
||||
ResetUI();
|
||||
Screen.SetScreen(ScreenTypes.MENU);
|
||||
CommandManager.AllowGameControls(false);
|
||||
// if(Client.Player.username != null)
|
||||
// ((MenuInputField)menuScreen["username-field"]).Text = Client.Player.username;
|
||||
}
|
||||
|
||||
public static void SpawnMapElements(TileConnectorProjection[] doors) {
|
||||
|
||||
|
||||
for (int i = 0; i < 5; i++){ // NOTE: this loop does y in reverse, y labels are inverted to match server
|
||||
for (int j = 0; j < 5; j++){
|
||||
int id = ClientMapManager.CoordsToId(i, 4 - j);
|
||||
if (Client.Player.state.officeTileId == id || Client.Opponent.state.officeTileId == id) continue; // TODO: remove the other check for office
|
||||
Point point1 = new Point(336 + (32 * i), 144 + (32 * j));
|
||||
Point point2 = new Point(367 + (32 * i), 175 + (32 * j));
|
||||
monitorScreen.AddElement(
|
||||
$"room{id}", new UIElement(point1, point2)
|
||||
{Pressable = true, OnMousePress = (() => CommandManager.SendChangeCamera(id))},
|
||||
true);
|
||||
lightIndicators.Add(id,
|
||||
monitorScreen.AddElement(
|
||||
$"light{id}", new UIElement(MonitorAtlas["map-light-indicator"], point1)
|
||||
{Visible = false},
|
||||
true));
|
||||
|
||||
//
|
||||
// if (doorPositions.ContainsKey((i, j))){
|
||||
// monitorScreen.AddElement("door"+doorPositions[(i, j)], new UIElement([monitorAtlas[5], monitorAtlas[6]], point1));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
monitorScreen.AddElement("eye-player", new UIElement(MonitorAtlas["eye-small-player"], monitorScreen["room"+Client.Player.state.camera].Bounds.Item1), true);
|
||||
monitorScreen.AddElement("eye-opponent", new UIElement([MonitorAtlas["eye-small-opponent-closed"], MonitorAtlas["eye-small-opponent-open"]], monitorScreen["room"+Client.Opponent.state.camera].Bounds.Item1), true);
|
||||
|
||||
foreach (var door in doors){
|
||||
if(door.Type != ConnectorType.DOOR_REMOTE) continue;
|
||||
|
||||
(int x, int y) dpos = (Math.Abs(door.Tiles.tile1.GridPosition.x - door.Tiles.tile2.GridPosition.x), Math.Abs(door.Tiles.tile1.GridPosition.y - door.Tiles.tile2.GridPosition.y));
|
||||
|
||||
if (dpos.y == 1){
|
||||
int targetId = door.Tiles.tile1.GridPosition.y > door.Tiles.tile2.GridPosition.y ? door.Tiles.tile1.Id : door.Tiles.tile2.Id;
|
||||
UIElement tile = monitorScreen["room"+targetId];
|
||||
|
||||
monitorScreen.AddElement("door"+Math.Max(door.Tiles.tile1.Id, door.Tiles.tile2.Id)+"-"+Math.Min(door.Tiles.tile1.Id, door.Tiles.tile2.Id), new UIElement([MonitorAtlas["door-remote-open"], MonitorAtlas["door-remote-closed"]], tile.Bounds.Item1), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DisplayGameUI() {
|
||||
Screen.SetScreen(ScreenTypes.OFFICE);
|
||||
|
|
@ -145,53 +203,10 @@ public class UIManager {
|
|||
timerElement.Start();
|
||||
}
|
||||
|
||||
public static void SpawnMapElements(TileConnectorProjection[] doors) {
|
||||
for (int i = 0; i < 5; i++){ // NOTE: this loop does y in reverse, y labels are inverted to match server
|
||||
for (int j = 0; j < 5; j++){
|
||||
int id = ClientMapManager.CoordsToId(i, 4 - j);
|
||||
if (Client.Player.state.officeTileId == id || Client.Opponent.state.officeTileId == id) continue; // TODO: remove the other check for office
|
||||
Point point1 = new Point(336 + (32 * i), 144 + (32 * j));
|
||||
Point point2 = new Point(367 + (32 * i), 175 + (32 * j));
|
||||
monitorScreen.AddElement($"room{id}", new UIElement(point1, point2)
|
||||
{Pressable = true, OnMousePress = (() => CommandManager.SendChangeCamera(id))});
|
||||
lightIndicators.Add(id, monitorScreen.AddElement($"light{id}", new UIElement(MonitorAtlas["map-light-indicator"], point1){Visible = false}));
|
||||
|
||||
//
|
||||
// if (doorPositions.ContainsKey((i, j))){
|
||||
// monitorScreen.AddElement("door"+doorPositions[(i, j)], new UIElement([monitorAtlas[5], monitorAtlas[6]], point1));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
monitorScreen.AddElement("eye-player", new UIElement(MonitorAtlas["eye-small-player"], monitorScreen["room"+Client.Player.state.camera].Bounds.Item1));
|
||||
monitorScreen.AddElement("eye-opponent", new UIElement([MonitorAtlas["eye-small-opponent-closed"], MonitorAtlas["eye-small-opponent-open"]], monitorScreen["room"+Client.Opponent.state.camera].Bounds.Item1));
|
||||
|
||||
foreach (var door in doors){
|
||||
if(door.Type != ConnectorType.DOOR_REMOTE) continue;
|
||||
|
||||
(int x, int y) dpos = (Math.Abs(door.Tiles.tile1.GridPosition.x - door.Tiles.tile2.GridPosition.x), Math.Abs(door.Tiles.tile1.GridPosition.y - door.Tiles.tile2.GridPosition.y));
|
||||
|
||||
if (dpos.y == 1){
|
||||
int targetId = door.Tiles.tile1.GridPosition.y > door.Tiles.tile2.GridPosition.y ? door.Tiles.tile1.Id : door.Tiles.tile2.Id;
|
||||
UIElement tile = monitorScreen["room"+targetId];
|
||||
|
||||
monitorScreen.AddElement("door"+Math.Max(door.Tiles.tile1.Id, door.Tiles.tile2.Id)+"-"+Math.Min(door.Tiles.tile1.Id, door.Tiles.tile2.Id), new UIElement([MonitorAtlas["door-remote-open"], MonitorAtlas["door-remote-closed"]], tile.Bounds.Item1));
|
||||
}
|
||||
}
|
||||
|
||||
monitorScreen.AddElement("p1-office-door-left", new UIElement([MonitorAtlas["door-office-p1-left-open"], MonitorAtlas["door-office-p1-left-closed"]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p1-office-door-centre", new UIElement([MonitorAtlas["door-office-p1-centre-open"], MonitorAtlas["door-office-p1-centre-closed"]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p1-office-door-right", new UIElement([MonitorAtlas["door-office-p1-right-open"], MonitorAtlas["door-office-p1-right-closed"]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p2-office-door-right", new UIElement([MonitorAtlas["door-office-p2-right-open"], MonitorAtlas["door-office-p2-right-closed"]], new Point(400, 144)));
|
||||
monitorScreen.AddElement("p2-office-door-centre", new UIElement([MonitorAtlas["door-office-p2-centre-open"], MonitorAtlas["door-office-p2-centre-closed"]], new Point(400, 144)));
|
||||
monitorScreen.AddElement("p2-office-door-left", new UIElement([MonitorAtlas["door-office-p2-left-open"], MonitorAtlas["door-office-p2-left-closed"]], new Point(400, 144)));
|
||||
|
||||
}
|
||||
|
||||
public static void AddEnemySprite(int id, UIElement sprite, UIElement jumpscareSprite = null) {
|
||||
monitorScreen.AddElement($"enemy{id}", sprite);
|
||||
monitorScreen.AddElement($"enemy{id}", sprite, true);
|
||||
if (jumpscareSprite != null){
|
||||
officeScreen.AddElement($"enemy{id}-jumpscare", jumpscareSprite);
|
||||
officeScreen.AddElement($"enemy{id}-jumpscare", jumpscareSprite, true);
|
||||
jumpscareSprite.Active = false;
|
||||
jumpscareSprite.Visible = false;
|
||||
}
|
||||
|
|
@ -315,6 +330,16 @@ public class UIManager {
|
|||
InputManager.AddListener(Keys.Space, DisplayMainMenu, InputTiming.PRESS, new InputListenerHook(true, true));
|
||||
}
|
||||
|
||||
public static void ResetUI() {
|
||||
foreach (Screen screen in Screen.Screens.Values){
|
||||
screen.RemoveTemporary();
|
||||
}
|
||||
lightIndicators.Clear();
|
||||
enemyElements.Clear();
|
||||
|
||||
timerElement.Stop();
|
||||
}
|
||||
|
||||
// private static Point GetRoomUIPos((int x, int y) pos) {
|
||||
// return new Point(336 + (32 * pos.x), 144 + (32 * pos.y));
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@ public class GameMain() : Core("fnafkooo", 1280, 720, false) {
|
|||
|
||||
|
||||
protected override void Initialize() {
|
||||
Exiting += (_, _) => {
|
||||
Client.Disconnect();
|
||||
};
|
||||
|
||||
// Client.Connect("127.0.0.1", 9012);
|
||||
CommandManager.InitInputListeners();
|
||||
|
||||
|
|
@ -23,6 +27,7 @@ public class GameMain() : Core("fnafkooo", 1280, 720, false) {
|
|||
|
||||
base.Initialize();
|
||||
|
||||
Client.Init();
|
||||
UIManager.InitUI();
|
||||
UIManager.DisplayMainMenu();
|
||||
}
|
||||
|
|
@ -35,9 +40,9 @@ public class GameMain() : Core("fnafkooo", 1280, 720, false) {
|
|||
}
|
||||
|
||||
protected override void Update(GameTime gameTime) {
|
||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
|
||||
Keyboard.GetState().IsKeyDown(Keys.Escape))
|
||||
if (Keyboard.GetState().IsKeyDown(Keys.Escape)){
|
||||
Exit();
|
||||
}
|
||||
|
||||
InputManager.NextInputCycle();
|
||||
Screen.UpdateAll();
|
||||
|
|
@ -59,4 +64,6 @@ public class GameMain() : Core("fnafkooo", 1280, 720, false) {
|
|||
spriteBatch.End();
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,2 +1,5 @@
|
|||
using var game = new FNAF_Clone.GameMain();
|
||||
using System;
|
||||
|
||||
using var game = new FNAF_Clone.GameMain();
|
||||
Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
game.Run();
|
||||
|
|
@ -1 +0,0 @@
|
|||
../../MonoGameLibrary/MonoGameLibrary/bin/Debug/net8.0/MonoGameLibrary.dll
|
||||
1
FNAF_Clone/link/MonoGameLibrary.dll
Symbolic link
1
FNAF_Clone/link/MonoGameLibrary.dll
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../MonoGameLibrary/MonoGameLibrary/bin/Release/net9.0/publish/MonoGameLibrary.dll
|
||||
|
|
@ -55,7 +55,6 @@ public class NekoEnemy : Enemy {
|
|||
Server.SendUpdateToAll([GameEvent.NEKO_ANGERED(Location.Owner.state.pid, Id)]);
|
||||
}
|
||||
|
||||
if (movementOpportunity.CheckAndRoll() || (Aggressive && GameLogic.NSecondUpdate)){
|
||||
if (Target == null){
|
||||
if (Server.P1.state.power > Server.P2.state.power){
|
||||
Target = Server.P2;
|
||||
|
|
@ -68,12 +67,10 @@ public class NekoEnemy : Enemy {
|
|||
Target = Server.Players[new Random().Next(2)];
|
||||
SetDifficulty(8);
|
||||
}
|
||||
else{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Target != null && (movementOpportunity.CheckAndRoll() || (Aggressive && GameLogic.NSecondUpdate))){
|
||||
Pathfinder.Decision decision = pathfinder.DecideNext(MapManager.Get(Target.state.officeTileId));
|
||||
switch (decision.type){
|
||||
case Pathfinder.Decision.MoveType:
|
||||
|
|
|
|||
|
|
@ -8,6 +8,14 @@
|
|||
<LangVersion>14</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<OutputPath>../bin/Debug/Server</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<OutputPath>../bin/Server</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LiteNetLib" Version="1.3.1" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ public class GameLogic {
|
|||
public const int START_CAMERA = 12;
|
||||
|
||||
private static MovementOpportunity secondCycleTimer = new(1000);
|
||||
private static MovementOpportunity gamePhaseTimer = new(30_000);
|
||||
private static MovementOpportunity gamePhaseTimer = new(60_000);
|
||||
public static bool NSecondUpdate{ get; private set; } = false;
|
||||
|
||||
public static MapTile P1Office;
|
||||
|
|
@ -84,7 +84,7 @@ public class GameLogic {
|
|||
// EnemyManager.AddEnemy(new MareEnemy(10)).Spawn(MapManager.Get(22));
|
||||
|
||||
EnemyManager.AddEnemy(new LurkEnemy(4)).Spawn(MapManager.Get(2));
|
||||
EnemyManager.AddEnemy(new NekoEnemy(4)).Spawn(MapManager.Get(22));
|
||||
EnemyManager.AddEnemy(new NekoEnemy(4)).Spawn(MapManager.Get(0));
|
||||
|
||||
}
|
||||
public static void Update() {
|
||||
|
|
@ -122,10 +122,17 @@ public class GameLogic {
|
|||
}
|
||||
|
||||
public static void DeclareWinner(ServerPlayer player) {
|
||||
if (Server.Players.Count == 2){
|
||||
Server.SendUpdateToAll([GameEvent.PLAYER_WIN(player.state.pid)]);
|
||||
Server.Stop();
|
||||
Console.WriteLine("Player " + player.state.pid + " won!");
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
Server.Stop();
|
||||
|
||||
if (!Server.AutoStop){
|
||||
Program.Restart();
|
||||
}
|
||||
}
|
||||
|
||||
private static (int p1Usage, int p2Usage) CalculatePowerUsage() {
|
||||
int p1Usage = 0;
|
||||
|
|
@ -158,7 +165,7 @@ public class GameLogic {
|
|||
PhaseCounter++;
|
||||
Server.SendUpdateToAll([GameEvent.NEXT_PHASE()]);
|
||||
|
||||
int roll = random.Next(3);
|
||||
int roll = spawnOrder.Count > 0 ? random.Next(3) : random.Next(1,3);
|
||||
switch (roll){
|
||||
case 0:
|
||||
int spawnRoll = random.Next(spawnOrder[0].Count);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,18 @@
|
|||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace FNAF_Server;
|
||||
|
||||
public class Program {
|
||||
public static void Main(string[] args) {
|
||||
if (args.Contains("--persistent")){
|
||||
Server.AutoStop = false;
|
||||
}
|
||||
Server.Start(9012);
|
||||
}
|
||||
|
||||
public static void Restart() {
|
||||
Console.WriteLine("Game concluded -> restarting server");
|
||||
Process.Start(new ProcessStartInfo{ FileName = Environment.ProcessPath, UseShellExecute = false });
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,8 @@ public class Server {
|
|||
public static readonly Dictionary<int, ServerPlayer> Players = new();
|
||||
public static ServerPlayer OtherPlayer(ServerPlayer player) => player.state.pid == P1.state.pid ? P2 : P1;
|
||||
|
||||
public static bool AutoStop{ get; set; } = true;
|
||||
|
||||
private static EventBasedNetListener listener;
|
||||
private static NetManager server;
|
||||
|
||||
|
|
@ -138,6 +140,8 @@ public class Server {
|
|||
}
|
||||
|
||||
public static void OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo) {
|
||||
GameLogic.DeclareWinner(OtherPlayer(Players.Values.First(p => Equals(p.peer, peer))));
|
||||
|
||||
if (peer.Tag != null) {
|
||||
Players.Remove(peer.Id);
|
||||
}
|
||||
|
|
@ -193,6 +197,7 @@ public class Server {
|
|||
public static void Stop()
|
||||
{
|
||||
isRunning = false;
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
namespace GlobalClassLib;
|
||||
|
||||
public static class Power {
|
||||
public const int MAX_POWER_VALUE = 1000;
|
||||
public const int MAX_POWER_VALUE = 4000;
|
||||
}
|
||||
7
build-linux.sh
Executable file
7
build-linux.sh
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
dotnet publish MonoGameLibrary
|
||||
ln -sfrv MonoGameLibrary/MonoGameLibrary/bin/Release/net9.0/publish/MonoGameLibrary.dll FNAF_Clone/link/MonoGameLibrary.dll
|
||||
|
||||
dotnet publish
|
||||
|
||||
ln -sfrv bin/Server/net9.0/publish/FNAF_Server bin/Client/net9.0/publish/FNAF_Server
|
||||
ln -sfrv bin/Client/net9.0/publish/FNAF_Clone outexe
|
||||
5
launch-server.sh
Executable file
5
launch-server.sh
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
while :
|
||||
do
|
||||
bin/Server/net9.0/publish/FNAF_Server
|
||||
echo "Restarting server..."
|
||||
done
|
||||
1
outexe
Symbolic link
1
outexe
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
bin/Client/net9.0/publish/FNAF_Clone
|
||||
Loading…
Add table
Add a link
Reference in a new issue