Rozsvěcení a zhasínání světel, sprity pro místnosti, indikátory rozsvícených světel, po konci hry je hráč vrácen do hlavního menu

This commit is contained in:
Perry 2026-03-16 20:43:53 +01:00
parent 25a62af483
commit 55fd052072
27 changed files with 338 additions and 113 deletions

View file

@ -1,7 +1,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.JavaScript;
using FNAF_Clone.GUI;
using GlobalClassLib;
using PacketLib;
namespace FNAF_Clone.Map;
@ -11,11 +15,18 @@ public class ClientMapManager {
public static MapTileProjection Get(int tileId) => Get(IdToCoords(tileId));
private static bool inverted;
public static void InitMap(bool invert = false) {
inverted = invert;
public static void InitMap(int[] connectors, int[] yourTiles, int[] opponentTiles, int[] litTiles, bool upsideDown ) {
IdToCoords = invert ? _IdToCoordsInverse : _IdToCoords;
CoordsToId = invert ? _CoordsToIdInverse : _CoordsToId;
(int id1, int id2, ConnectorType type, ClientPlayer? owner)[] connectorsData = new (int, int , ConnectorType, ClientPlayer?)[connectors.Length / 4];
for (int i = 0; i < connectors.Length / 4; i++){
connectorsData[i] = (connectors[i * 4], connectors[i * 4 + 1], (ConnectorType)connectors[i * 4 + 2], connectors[i * 4 + 3] == -1 ? null : Client.GetPlayer(connectors[i * 4 + 3]));
}
// ClientMapManager.InitMap(upsideDown);
inverted = upsideDown;
IdToCoords = upsideDown ? _IdToCoordsInverse : _IdToCoords;
CoordsToId = upsideDown ? _CoordsToIdInverse : _CoordsToId;
for (int i = 0; i < 5; i++){
for (int j = 0; j < 2; j++){
@ -27,6 +38,26 @@ public class ClientMapManager {
}
}
foreach (var tileId in yourTiles){
Get(tileId).Owner = Client.Player;
}
foreach (var tileId in opponentTiles){
Get(tileId).Owner = Client.Opponent;
}
foreach (var tileId in litTiles){
Get(tileId).Lit = true;
}
TileConnectorProjection[] connectorProjections = connectorsData.Select(c => new TileConnectorProjection(Get(c.id1), Get(c.id2), c.type){Owner = c.owner}).ToArray();
InitConnectors(connectorProjections);
UIManager.SpawnMapElements(connectorProjections.Where(c => c.Type == ConnectorType.DOOR_REMOTE).ToArray());
}
public static void InitConnectors(TileConnectorProjection[] connectors) {
@ -58,12 +89,21 @@ public class ClientMapManager {
}
public const int ID_X_OFFSET = 5; // map grid height
public const int MAP_SIDE_LENGTH = 5; // map grid height
public static Func<int, int, int> CoordsToId{ get; private set; }
public static Func<int, (int x, int y)> IdToCoords{ get; private set; }
private static Func<int, (int x, int y)> _IdToCoords = id => (id / ID_X_OFFSET, id % ID_X_OFFSET);
private static Func<int, (int x, int y)> _IdToCoordsInverse = id => (ID_X_OFFSET - 1 - (id / ID_X_OFFSET), ID_X_OFFSET - 1 - (id % ID_X_OFFSET));
private static Func<int, int, int> _CoordsToId = (x, y) => x * ID_X_OFFSET + y;
private static Func<int, int, int> _CoordsToIdInverse = (x, y) => (ID_X_OFFSET - 1 - x) * ID_X_OFFSET + (ID_X_OFFSET - 1 - y);
private static Func<int, (int x, int y)> _IdToCoords = id => (id / MAP_SIDE_LENGTH, id % MAP_SIDE_LENGTH);
private static Func<int, (int x, int y)> _IdToCoordsInverse = id => (MAP_SIDE_LENGTH - 1 - (id / MAP_SIDE_LENGTH), MAP_SIDE_LENGTH - 1 - (id % MAP_SIDE_LENGTH));
private static Func<int, int, int> _CoordsToId = (x, y) => x * MAP_SIDE_LENGTH + y;
private static Func<int, int, int> _CoordsToIdInverse = (x, y) => (MAP_SIDE_LENGTH - 1 - x) * MAP_SIDE_LENGTH + (MAP_SIDE_LENGTH - 1 - y);
public static MapTileProjection[] GetAllTiles() {
List<MapTileProjection> tiles = new();
foreach (var tile in map){
tiles.Add(tile);
}
return tiles.ToArray();
}
}