add vectors in UpdateInput, add event ActionEvent and Subscribing to the actions of the input manager

This commit is contained in:
Lev 2024-08-17 19:42:55 +03:00
parent 81ab544d11
commit c9d766242f
3 changed files with 40 additions and 10 deletions

View file

@ -14,6 +14,8 @@ using ZoFo.GameCore.GameObjects.MapObjects.Tiles;
using System.Drawing; using System.Drawing;
using System.Reflection; using System.Reflection;
using ZoFo.GameCore.GameObjects.Entities; using ZoFo.GameCore.GameObjects.Entities;
using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
namespace ZoFo.GameCore namespace ZoFo.GameCore
{ {
@ -26,6 +28,13 @@ namespace ZoFo.GameCore
{ {
networkManager = new ClientNetworkManager(); networkManager = new ClientNetworkManager();
networkManager.GetDataSent += OnDataSend; networkManager.GetDataSent += OnDataSend;
// Подписка на действия инпутменеджера.
// Отправляются данные апдейтса с обновлением инпута
AppManager.Instance.InputManager.ActionEvent += () => networkManager.AddData(new UpdateInput(){
InputMovementDirection = AppManager.Instance.InputManager.InputMovementDirection,
InputAttackDirection = AppManager.Instance.InputManager.InputAttackDirection
});
} }
public void OnDataSend(string data) public void OnDataSend(string data)

View file

@ -17,17 +17,21 @@ namespace ZoFo.GameCore.GameManagers
public class InputManager public class InputManager
{ {
public delegate void Delegat(); public event Action ShootEvent; // событие удара(когда нажат X, событие срабатывает)
public event Delegat ShootEvent; // событие удара(когда нажат X, событие срабатывает)
public event Delegat OnInteract; // событие взаимодействия с collectable(например, лутом) public event Action OnInteract; // событие взаимодействия с collectable(например, лутом)
//с помощью кнопки E. //с помощью кнопки E.
public event Action ActionEvent;
public Vector2 InputMovementDirection; public Vector2 InputMovementDirection;
private Vector2 prevInputMovementDirection;
public Vector2 InputAttackDirection; public Vector2 InputAttackDirection;
private Vector2 prevInputAttackDirection;
public event Delegat TalkEvent; public event Action TalkEvent;
ScopeState currentScopeState; // Положение оружия. Left, Right, Straight, Back, StraightLeft, StraightRight, BackLeft, BackRight. public ScopeState currentScopeState; // Положение оружия. Left, Right, Straight, Back, StraightLeft, StraightRight, BackLeft, BackRight.
private ScopeState prevCurrentScopeState;
private bool _cheatsEnabled = false; private bool _cheatsEnabled = false;
public bool InvincibilityCheat { get; private set; } = false; public bool InvincibilityCheat { get; private set; } = false;
public bool CollisionsCheat { get; private set; } = false; public bool CollisionsCheat { get; private set; } = false;
@ -128,6 +132,7 @@ namespace ZoFo.GameCore.GameManagers
lastGamePadState = gamePadState; lastGamePadState = gamePadState;
#endregion #endregion
#region Работа с KeyBoard #region Работа с KeyBoard
#region InputAttack with mouse #region InputAttack with mouse
MouseState mouseState = Mouse.GetState(); MouseState mouseState = Mouse.GetState();
AppManager.Instance.debugHud.Set("mouse position", $"({mouseState.X}, {mouseState.Y}"); AppManager.Instance.debugHud.Set("mouse position", $"({mouseState.X}, {mouseState.Y}");
@ -231,6 +236,17 @@ namespace ZoFo.GameCore.GameManagers
lastKeyboardState = keyBoardState; lastKeyboardState = keyBoardState;
#endregion #endregion
#region ActionEvent
if(InputMovementDirection != prevInputMovementDirection ||
InputAttackDirection != prevInputAttackDirection ||
currentScopeState != prevCurrentScopeState)
{
ActionEvent?.Invoke();
}
prevInputMovementDirection = InputMovementDirection;
prevInputAttackDirection = InputAttackDirection;
prevCurrentScopeState = currentScopeState;
#endregion
} }
} }
} }

View file

@ -1,6 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.Xna.Framework;
using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -9,9 +11,12 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer
public class UpdateInput :UpdateData public class UpdateInput :UpdateData
{ {
// public int IdEntity { get; set; } // public int IdEntity { get; set; }
public Vector2 InputMovementDirection{get;set;}
public Vector2 InputAttackDirection {get;set;}
public UpdateInput() public UpdateInput()
{ {
UpdateType = "UpdateInput"; UpdateType = "UpdateInput";
} }
} }
} }