První 3 monstra z plánovaných pěti. Kompletní pathfinding i zrcadlení do clienta. Útoky implementované nejsou. Lurk a Neko jsou hardcoded aby útočili na P1.

This commit is contained in:
Perry 2026-03-08 16:55:49 +01:00
parent 4484b127c5
commit 9bfe63a166
27 changed files with 772 additions and 47 deletions

View file

@ -52,6 +52,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 void AddElement(string id, UIElement element) {
elements.Add(id, element);
@ -80,8 +81,6 @@ public class Screen {
}
public void Update() {
foreach (var keyValuePair in elements){
keyValuePair.Value.Update();
}

View file

@ -69,9 +69,7 @@ public class UIElement {
currentTextureId = textureId;
}
public void Update() {
}
public virtual void Update() { }
public bool IsWithinBounds(Point pos) {
return pos.X >= Math.Min(screenSpaceBounds.Item1.X, screenSpaceBounds.Item2.X) && pos.X <= Math.Max(screenSpaceBounds.Item1.X, screenSpaceBounds.Item2.X) &&

View file

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using FNAF_Clone.Map;
using GlobalClassLib;
using Microsoft.Xna.Framework;
@ -21,15 +23,19 @@ public class UIManager {
private static TextureAtlas testAtlas;
private static TextureAtlas officeAtlas;
private static TextureAtlas monitorAtlas;
public static TextureAtlas enemyAtlas;
public static int GlobalPixelMultiplier{ get; private set; }
private Dictionary<(int, int), UIElement> doorElements = new();
private static Dictionary<int, UIElement> enemyElements = new();
public static void InitUI() {
GlobalPixelMultiplier = Core.graphicsDevice.Viewport.Height / 360;
testAtlas = TextureAtlas.FromFile(Core.content, "images/testBlocks-definition.xml");
officeAtlas = TextureAtlas.FromFile(Core.content, "images/office-definition.xml");
monitorAtlas = TextureAtlas.FromFile(Core.content, "images/monitor-definition.xml");
enemyAtlas = TextureAtlas.FromFile(Core.content, "images/enemies-definition.xml");
Screen.AddScreens([officeScreen, monitorScreen]);
Screen.SetScreen(ScreenTypes.OFFICE);
@ -67,6 +73,7 @@ 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));
UpdateCameras([Client.Player.state.camera]);
}
public static void SpawnDoors(TileConnectorProjection[] doors) {
@ -91,6 +98,13 @@ public class UIManager {
monitorScreen.AddElement("p2-office-door-left", new UIElement([monitorAtlas[17], monitorAtlas[18]], new Point(400, 144)));
}
public static void AddEnemySprite(int id, UIElement sprite) {
monitorScreen.AddElement($"enemy{id}", sprite);
enemyElements.Add(id, sprite);
sprite.Visible = false;
}
public static void ChangeDoorState(Direction dir, bool state) {
int stateInt = state ? 1 : 0;
@ -141,12 +155,25 @@ public class UIManager {
public static void ChangeCamera(int id) {
monitorScreen["eye-player"].SetPosition(monitorScreen["room"+id].Bounds.Item1);
UpdateCameras([id]);
}
public static void UpdateCameras(int[] camIds) {
if (camIds.Contains(Client.Player.state.camera)){
enemyElements.Values.Where(e => e.Visible).ToList().ForEach(e => e.Visible = false);
ClientEnemy[] enemies = ClientEnemyManager.GetByLocation(ClientMapManager.Get(Client.Player.state.camera));;
foreach (var enemy in enemies){
enemyElements.TryGetValue(enemy.Id, out var element);
if (element == null) continue;
element.Visible = true;
}
}
}
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));
// }