add vectors in UpdateInput, add event ActionEvent and Subscribing to the actions of the input manager
This commit is contained in:
parent
81ab544d11
commit
c9d766242f
3 changed files with 40 additions and 10 deletions
|
@ -14,6 +14,8 @@ using ZoFo.GameCore.GameObjects.MapObjects.Tiles;
|
|||
using System.Drawing;
|
||||
using System.Reflection;
|
||||
using ZoFo.GameCore.GameObjects.Entities;
|
||||
using ZoFo.GameCore.GameManagers;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
|
||||
|
||||
namespace ZoFo.GameCore
|
||||
{
|
||||
|
@ -26,6 +28,13 @@ namespace ZoFo.GameCore
|
|||
{
|
||||
networkManager = new ClientNetworkManager();
|
||||
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)
|
||||
|
|
|
@ -17,17 +17,21 @@ namespace ZoFo.GameCore.GameManagers
|
|||
|
||||
public class InputManager
|
||||
{
|
||||
public delegate void Delegat();
|
||||
public event Delegat ShootEvent; // событие удара(когда нажат X, событие срабатывает)
|
||||
public event Action ShootEvent; // событие удара(когда нажат X, событие срабатывает)
|
||||
|
||||
public event Delegat OnInteract; // событие взаимодействия с collectable(например, лутом)
|
||||
public event Action OnInteract; // событие взаимодействия с collectable(например, лутом)
|
||||
//с помощью кнопки E.
|
||||
|
||||
public event Action ActionEvent;
|
||||
public Vector2 InputMovementDirection;
|
||||
private Vector2 prevInputMovementDirection;
|
||||
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;
|
||||
public bool InvincibilityCheat { get; private set; } = false;
|
||||
public bool CollisionsCheat { get; private set; } = false;
|
||||
|
@ -128,6 +132,7 @@ namespace ZoFo.GameCore.GameManagers
|
|||
lastGamePadState = gamePadState;
|
||||
#endregion
|
||||
#region Работа с KeyBoard
|
||||
|
||||
#region InputAttack with mouse
|
||||
MouseState mouseState = Mouse.GetState();
|
||||
AppManager.Instance.debugHud.Set("mouse position", $"({mouseState.X}, {mouseState.Y}");
|
||||
|
@ -231,6 +236,17 @@ namespace ZoFo.GameCore.GameManagers
|
|||
lastKeyboardState = keyBoardState;
|
||||
|
||||
#endregion
|
||||
#region ActionEvent
|
||||
if(InputMovementDirection != prevInputMovementDirection ||
|
||||
InputAttackDirection != prevInputAttackDirection ||
|
||||
currentScopeState != prevCurrentScopeState)
|
||||
{
|
||||
ActionEvent?.Invoke();
|
||||
}
|
||||
prevInputMovementDirection = InputMovementDirection;
|
||||
prevInputAttackDirection = InputAttackDirection;
|
||||
prevCurrentScopeState = currentScopeState;
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -9,9 +11,12 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer
|
|||
public class UpdateInput :UpdateData
|
||||
{
|
||||
// public int IdEntity { get; set; }
|
||||
public Vector2 InputMovementDirection{get;set;}
|
||||
public Vector2 InputAttackDirection {get;set;}
|
||||
public UpdateInput()
|
||||
{
|
||||
UpdateType = "UpdateInput";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue