fix InputManager and add some logic in player for his attack
This commit is contained in:
parent
fef09f3d4a
commit
3742690e5c
4 changed files with 81 additions and 21 deletions
|
@ -205,6 +205,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
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
@ -198,36 +199,44 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
prevCurrentScopeState = currentScopeState;
|
prevCurrentScopeState = currentScopeState;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
DebugHUD.Instance.Set("controls", currentScopeState.ToString());
|
DebugHUD.Instance.Set("controls", currentScopeState.ToString());
|
||||||
}
|
}
|
||||||
#region работа с ScopeState и Vector2
|
#region работа с ScopeState и Vector2
|
||||||
public ScopeState ConvertVector2ToState(Vector2 vector){
|
public ScopeState ConvertVector2ToState(Vector2 vector)
|
||||||
int currentSection = (int)Math.Ceiling(Math.Atan2(InputMovementDirection.Y,
|
{
|
||||||
InputMovementDirection.X) * 180 / Math.PI * 16 / 360);
|
//if()
|
||||||
switch(currentSection){
|
int currentSection = (int)Math.Ceiling(Math.Atan2(vector.Y,
|
||||||
case 1 or 0 or 16:
|
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;
|
currentScopeState = ScopeState.Right;
|
||||||
break;
|
break;
|
||||||
case 2 or 3:
|
case 2 or 3:
|
||||||
currentScopeState = ScopeState.StraightRight;
|
currentScopeState = ScopeState.DownRight;
|
||||||
break;
|
break;
|
||||||
case 4 or 5:
|
case 4 or 5:
|
||||||
currentScopeState = ScopeState.Straight;
|
currentScopeState = ScopeState.Down;
|
||||||
break;
|
break;
|
||||||
case 6 or 7:
|
case 6 or 7:
|
||||||
currentScopeState = ScopeState.StraightLeft;
|
currentScopeState = ScopeState.DownLeft;
|
||||||
break;
|
break;
|
||||||
case 8 or 9:
|
case 8 or -7:
|
||||||
currentScopeState = ScopeState.Left;
|
currentScopeState = ScopeState.Left;
|
||||||
break;
|
break;
|
||||||
case 10 or 11:
|
case -6 or -5:
|
||||||
currentScopeState = ScopeState.BackLeft;
|
currentScopeState = ScopeState.TopLeft;
|
||||||
break;
|
break;
|
||||||
case 12 or 13:
|
case -4 or -3:
|
||||||
currentScopeState = ScopeState.Back;
|
currentScopeState = ScopeState.Top;
|
||||||
break;
|
break;
|
||||||
case 14 or 15:
|
case -2 or -1:
|
||||||
currentScopeState = ScopeState.BackRight;
|
currentScopeState = ScopeState.TopRight;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -236,4 +245,4 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -46,7 +46,6 @@ namespace ZoFo.GameCore.GameObjects.Entities
|
||||||
animationId = animationId,
|
animationId = animationId,
|
||||||
IdEntity = Id
|
IdEntity = Id
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
public override void Draw(SpriteBatch spriteBatch)
|
public override void Draw(SpriteBatch spriteBatch)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,6 +8,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.Entities.LivingEntities.Player;
|
namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
|
||||||
|
|
||||||
|
@ -21,7 +23,7 @@ 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(new List<string> { "player_look_down" }, "player_look_down");
|
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "player_look_down", "player_running_top_rotate" }, "player_look_down");
|
||||||
private LootData lootData;
|
private LootData lootData;
|
||||||
public bool IsTryingToInteract { get; set; }
|
public bool IsTryingToInteract { get; set; }
|
||||||
public bool IsTryingToShoot { get; set; }
|
public bool IsTryingToShoot { get; set; }
|
||||||
|
@ -39,7 +41,35 @@ public class Player : LivingEntity
|
||||||
|
|
||||||
public override void Update()
|
public override void Update()
|
||||||
{
|
{
|
||||||
//StartAnimation("wood");
|
#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()
|
||||||
|
@ -59,5 +89,14 @@ public class Player : LivingEntity
|
||||||
public void HandleShoot(UpdateInputShoot updateInputShoot)
|
public void HandleShoot(UpdateInputShoot updateInputShoot)
|
||||||
{
|
{
|
||||||
IsTryingToShoot = true;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue