Eventy upraveny pro podporu dvou hráčů. Všechny dveře se zobrazují na správných pozicích pro oba hráče.

This commit is contained in:
Perry 2026-02-25 17:05:15 +01:00
parent cea56112ea
commit 3049417914
18 changed files with 157 additions and 75 deletions

View file

@ -18,8 +18,8 @@ public class GameLogic {
connectorsConverted[i * 3 + 1] = connectors[i].Tiles.tile2.Id;
connectorsConverted[i * 3 + 2] = (int)connectors[i].Type;
}
Server.SendPacketToAll(new MapInitPacket{Connectors = connectorsConverted});
Server.SendPacket(new MapInitPacket{Connectors = connectorsConverted, UpsideDown = true}, Server.P1.peer);
Server.SendPacket(new MapInitPacket{Connectors = connectorsConverted, UpsideDown = false}, Server.P2.peer);
}
public static void Update() {

View file

@ -6,7 +6,7 @@ public static class MapManager {
private static MapTile[,] map = new MapTile[5, 5];
public static MapTile Get((int x, int y) coords) => map[coords.x, coords.y];
public static MapTile Get(int tileId) => Get(MapTile.IdToCoords(tileId));
public static MapTile Get(int tileId) => Get(IdToCoords(tileId));
private static Dictionary<(int x1, int y1), (int x2, int y2, int value, ConnectorType type)[]> halfConnectors = new(){
@ -30,11 +30,11 @@ public static class MapManager {
public static void InitMap() { // TODO: make map size not hardcoded
for (int i = 0; i < 5; i++){
for (int j = 0; j < 2; j++){
map[i, j] = new MapTile(MapTile.CoordsToId(i, j), null); // TODO: implement ownership
map[i, j] = new MapTile(CoordsToId(i, j), null); // TODO: implement ownership
}
map[i, 2] = new MapTile(MapTile.CoordsToId(i, 2), null);
map[i, 2] = new MapTile(CoordsToId(i, 2), null);
for (int j = 3; j < 5; j++){
map[i, j] = new MapTile(MapTile.CoordsToId(i, j), null);
map[i, j] = new MapTile(CoordsToId(i, j), null);
}
}
@ -69,4 +69,7 @@ public static class MapManager {
}
public const int ID_X_OFFSET = 5; // map grid height
public static int CoordsToId(int x, int y) => x * ID_X_OFFSET + y;
public static (int, int) IdToCoords(int id) => (id / ID_X_OFFSET, id % ID_X_OFFSET);
}

View file

@ -6,7 +6,7 @@ namespace FNAF_Server.Map;
public class MapTile : GlobalMapTile<TileConnector, MapTile> {
public ServerPlayer Owner{ get; private set; }
public MapTile(int id, ServerPlayer owner) : base(id) {
public MapTile(int id, ServerPlayer owner) : base(id, MapManager.IdToCoords(id)) {
Owner = owner;
}

View file

@ -115,14 +115,10 @@ public class Server {
}
else{
P2 = newPlayer;
SendPacket(new OpponentInitPacket{state = newPlayer.state}, P1.peer);
SendPacket(new OpponentInitPacket{state = P1.state}, P2.peer);
GameLogic.Init(); // TODO: move this to the condition above to wait for the other player
}
GameLogic.Init(); // TODO: move this to the condition above to wait for the other player
}
public static void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod) {