Merge pull request #52 from progtime-net/Player

Player
This commit is contained in:
Andrey 2024-08-18 00:20:38 +03:00 committed by GitHub
commit 8ab6f3d434
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 11 deletions

View file

@ -13,11 +13,12 @@ using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
using System.Drawing;
using System.Reflection;
using ZoFo.GameCore.GameObjects.Entities;
using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
using System.Linq;
using System.Web;
using ZoFo.GameCore.GUI;
namespace ZoFo.GameCore
{
public class Client
@ -31,6 +32,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)

View file

@ -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
}
}
}

View file

@ -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;
@ -8,10 +10,13 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer
{
public class UpdateInput :UpdateData
{
// public int IdEntity { get; set; }
public UpdateInput()
{
UpdateType = "UpdateInput";
}
// public int IdEntity { get; set; }
public Vector2 InputMovementDirection{get;set;}
public Vector2 InputAttackDirection {get;set;}
public UpdateInput()
{
UpdateType = "UpdateInput";
}
}
}