Merge pull request #84 from progtime-net/PlayerLog

Player log
This commit is contained in:
SergoDobro 2024-08-20 00:45:36 +03:00 committed by GitHub
commit b228c526a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 121 additions and 81 deletions

View file

@ -208,6 +208,19 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
} }
return players.ToArray(); return players.ToArray();
} }
public Entity[] GetEntities(Rectangle rectangle)
{
List<Entity> entities = new List<Entity>();
foreach (var item in AppManager.Instance.server.entities)//фильтрация
{
if (item.collisionComponent.stopRectangle.SetOrigin(item.position).Intersects(rectangle))
{
entities.Add(item);
}
}
return entities.ToArray();
}
} }
public static class ExtentionClass public static class ExtentionClass

View file

@ -8,13 +8,14 @@ using System.Diagnostics;
using System.Formats.Tar; using System.Formats.Tar;
using System.Linq; using System.Linq;
using System.Reflection.Metadata.Ecma335; using System.Reflection.Metadata.Ecma335;
using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ZoFo.GameCore.GUI; using ZoFo.GameCore.GUI;
namespace ZoFo.GameCore.GameManagers namespace ZoFo.GameCore.GameManagers
{ {
public enum ScopeState { Idle, Left, Right, Straight, Back, StraightLeft, StraightRight, BackLeft, BackRight } public enum ScopeState { Idle, Left, Right, Top, Down, TopLeft, TopRight, DownLeft, DownRight }
public class InputManager public class InputManager
{ {
@ -82,37 +83,7 @@ namespace ZoFo.GameCore.GameManagers
#endregion // Cheats #endregion // Cheats
#region set ScopeState #region set ScopeState
int currentSection = (int)Math.Ceiling(Math.Atan2(InputMovementDirection.Y, ConvertVector2ToState(InputMovementDirection);
InputMovementDirection.X) * 180 / Math.PI * 16 / 360);
switch(currentSection){
case 1 or 0 or 16:
currentScopeState = ScopeState.Right;
break;
case 2 or 3:
currentScopeState = ScopeState.StraightRight;
break;
case 4 or 5:
currentScopeState = ScopeState.Straight;
break;
case 6 or 7:
currentScopeState = ScopeState.StraightLeft;
break;
case 8 or 9:
currentScopeState = ScopeState.Left;
break;
case 10 or 11:
currentScopeState = ScopeState.BackLeft;
break;
case 12 or 13:
currentScopeState = ScopeState.Back;
break;
case 14 or 15:
currentScopeState = ScopeState.BackRight;
break;
default:
break;
}
#endregion #endregion
#region Обработка нажатия выстрела. Вызывает событие ShootEvent #region Обработка нажатия выстрела. Вызывает событие ShootEvent
@ -169,50 +140,24 @@ namespace ZoFo.GameCore.GameManagers
#endregion // Cheats #endregion // Cheats
#region Обработка состояния объекта. Задает значение полю scopeState. #region Обработка состояния объекта. Задает значение полю scopeState.
if(keyBoardState.IsKeyDown(Keys.Right) && keyBoardState.IsKeyDown(Keys.Up) || if (keyBoardState.IsKeyDown(Keys.Up) || keyBoardState.IsKeyDown(Keys.W))
keyBoardState.IsKeyDown(Keys.D) && keyBoardState.IsKeyDown(Keys.W))
{ {
currentScopeState = ScopeState.StraightRight; InputMovementDirection += new Vector2(0, -1);
InputMovementDirection = new Vector2(1, -1);
} }
else if(keyBoardState.IsKeyDown(Keys.Left) && keyBoardState.IsKeyDown(Keys.Up) || if (keyBoardState.IsKeyDown(Keys.Down) || keyBoardState.IsKeyDown(Keys.S))
keyBoardState.IsKeyDown(Keys.A) && keyBoardState.IsKeyDown(Keys.W))
{ {
currentScopeState = ScopeState.StraightLeft; InputMovementDirection += new Vector2(0, 1);
InputMovementDirection = new Vector2(-1, -1);
} }
else if(keyBoardState.IsKeyDown(Keys.Right) && keyBoardState.IsKeyDown(Keys.Down) || if (keyBoardState.IsKeyDown(Keys.Right) || keyBoardState.IsKeyDown(Keys.D))
keyBoardState.IsKeyDown(Keys.D) && keyBoardState.IsKeyDown(Keys.S))
{ {
currentScopeState = ScopeState.BackRight; InputMovementDirection += new Vector2(1, 0);
InputMovementDirection = new Vector2(1, 1);
} }
else if(keyBoardState.IsKeyDown(Keys.Left) && keyBoardState.IsKeyDown(Keys.Down) || if (keyBoardState.IsKeyDown(Keys.Left) || keyBoardState.IsKeyDown(Keys.A))
keyBoardState.IsKeyDown(Keys.A) && keyBoardState.IsKeyDown(Keys.S))
{ {
currentScopeState = ScopeState.BackLeft; InputMovementDirection += new Vector2(-1, 0);
InputMovementDirection = new Vector2(-1, 1);
}
else if (keyBoardState.IsKeyDown(Keys.Up) || keyBoardState.IsKeyDown(Keys.W))
{
currentScopeState = ScopeState.Straight;
InputMovementDirection = new Vector2(0, -1);
}
else if (keyBoardState.IsKeyDown(Keys.Down) || keyBoardState.IsKeyDown(Keys.S))
{
currentScopeState = ScopeState.Back;
InputMovementDirection = new Vector2(0, 1);
}
else if(keyBoardState.IsKeyDown(Keys.Left) || keyBoardState.IsKeyDown(Keys.A))
{
currentScopeState = ScopeState.Left;
InputMovementDirection = new Vector2(-1, 0);
}
else if(keyBoardState.IsKeyDown(Keys.Right) || keyBoardState.IsKeyDown(Keys.D))
{
currentScopeState = ScopeState.Right;
InputMovementDirection = new Vector2(1, 0);
} }
ConvertVector2ToState(InputMovementDirection);
#endregion #endregion
#region Обработка нажатия выстрела. Вызывает событие ShootEvent #region Обработка нажатия выстрела. Вызывает событие ShootEvent
@ -257,5 +202,48 @@ namespace ZoFo.GameCore.GameManagers
DebugHUD.Instance.Set("controls", currentScopeState.ToString()); DebugHUD.Instance.Set("controls", currentScopeState.ToString());
} }
#region работа с ScopeState и Vector2
public ScopeState ConvertVector2ToState(Vector2 vector)
{
//if()
int currentSection = (int)Math.Ceiling(Math.Atan2(vector.Y,
vector.X) * (180 / Math.PI) / 360 * 16);
DebugHUD.DebugSet("current section", currentSection.ToString());
//DebugHUD.DebugSet("y", InputMovementDirection.Y.ToString());
//DebugHUD.DebugSet("x", InputMovementDirection.X.ToString());
switch(currentSection)
{
case 0 or 1:
currentScopeState = ScopeState.Right;
break;
case 2 or 3:
currentScopeState = ScopeState.DownRight;
break;
case 4 or 5:
currentScopeState = ScopeState.Down;
break;
case 6 or 7:
currentScopeState = ScopeState.DownLeft;
break;
case 8 or -7:
currentScopeState = ScopeState.Left;
break;
case -6 or -5:
currentScopeState = ScopeState.TopLeft;
break;
case -4 or -3:
currentScopeState = ScopeState.Top;
break;
case -2 or -1:
currentScopeState = ScopeState.TopRight;
break;
default:
break;
}
return currentScopeState;
}
#endregion
} }
} }

View file

@ -46,7 +46,6 @@ namespace ZoFo.GameCore.GameObjects
animationId = animationId, animationId = animationId,
IdEntity = Id IdEntity = Id
}); });
} }
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
{ {

View file

@ -9,6 +9,8 @@ using ZoFo.GameCore.GameManagers.CollisionManager;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
using ZoFo.GameCore.Graphics; using ZoFo.GameCore.Graphics;
using System.Diagnostics;
using ZoFo.GameCore.GUI;
namespace ZoFo.GameCore.GameObjects; namespace ZoFo.GameCore.GameObjects;
@ -22,16 +24,17 @@ public class Player : LivingEntity
//public bool IsTryingToShoot { get; set; } //public bool IsTryingToShoot { get; set; }
private float speed; private float speed;
private int health; private int health;
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(AppManager.Instance.AssetManager.Player); public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(AppManager.Instance.AssetManager.Player);
private LootData lootData; private LootData lootData;
//public bool isTryingToInteract { get; set; } public bool IsTryingToInteract { get; set; }
public bool IsTryingToShoot { get; set; }
public Player(Vector2 position) : base(position) public Player(Vector2 position) : base(position)
{ {
graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30); graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30);
collisionComponent.stopRectangle = new Rectangle(0, 20, 30, 10); collisionComponent.stopRectangle = new Rectangle(0, 20, 30, 10);
speed = 5; speed = 5;
//isTryingToInteract = false;
//IsTryingToShoot = false;
StartAnimation("player_look_down"); StartAnimation("player_look_down");
} }
@ -39,7 +42,35 @@ public class Player : LivingEntity
public override void Update() public override void Update()
{ {
#region анимация управления, стрельбы
switch(AppManager.Instance.InputManager.ConvertVector2ToState(InputPlayerRotation))
{
case ScopeState.Top:
break;
case ScopeState.Down:
break;
case ScopeState.Right:
//StartAnimation("player_running_top_rotate");
break;
case ScopeState.Left:
break;
case ScopeState.TopRight:
break;
case ScopeState.TopLeft:
break;
case ScopeState.DownRight:
break;
case ScopeState.DownLeft:
break;
}
#endregion
MovementLogic(); MovementLogic();
} }
public void MovementLogic() public void MovementLogic()
@ -54,10 +85,19 @@ public class Player : LivingEntity
} }
public void HandleInteract(UpdateInputInteraction updateInputInteraction) public void HandleInteract(UpdateInputInteraction updateInputInteraction)
{ {
//isTryingToInteract = true; IsTryingToInteract = true;
} }
public void HandleShoot(UpdateInputShoot updateInputShoot) public void HandleShoot(UpdateInputShoot updateInputShoot)
{ {
IsTryingToShoot = true;
Rectangle rectangle = new Rectangle((int)position.X, (int)position.Y, 200, 200);
Entity[] entities = AppManager.Instance.server.collisionManager.GetEntities(rectangle);
DebugHUD.DebugSet("ent[0]", entities[0].ToString());
if(entities != null){
foreach (Entity entity in entities){
AppManager.Instance.server.DeleteObject(entity);
}
}
} }
} }