add Animation of movement player
This commit is contained in:
parent
f2c73bb3af
commit
0ffad2cac7
13 changed files with 130 additions and 44 deletions
|
@ -5,18 +5,11 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Formats.Tar;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZoFo.GameCore.GUI;
|
||||
|
||||
namespace ZoFo.GameCore.GameManagers
|
||||
{
|
||||
public enum ScopeState { Idle, Left, Right, Top, Down, TopLeft, TopRight, DownLeft, DownRight }
|
||||
|
||||
public class InputManager
|
||||
{
|
||||
public event Action ShootEvent; // событие удара(когда нажат X, событие срабатывает)
|
||||
|
@ -176,7 +169,6 @@ namespace ZoFo.GameCore.GameManagers
|
|||
#region Обработка взаимодействия с collectable(например лутом). Вызывает событие OnInteract
|
||||
if (keyBoardState.IsKeyDown(Keys.E) && !isInteract)
|
||||
{
|
||||
|
||||
OnInteract?.Invoke();
|
||||
Debug.WriteLine("взаимодействие с Collectable");
|
||||
}
|
||||
|
@ -203,18 +195,33 @@ namespace ZoFo.GameCore.GameManagers
|
|||
DebugHUD.Instance.Set("controls", currentScopeState.ToString());
|
||||
}
|
||||
#region работа с ScopeState и Vector2
|
||||
/// <summary>
|
||||
/// возвращает число от -14 до 16, начиная с
|
||||
/// </summary>
|
||||
/// <param name="vector"></param>
|
||||
/// <returns></returns>
|
||||
public int ConvertAttackVector2ToState(Vector2 vector){
|
||||
int currentSection = (int)Math.Ceiling(Math.Atan2(vector.Y,
|
||||
vector.X) * (180 / Math.PI) / 360 * 32);
|
||||
return currentSection;
|
||||
}
|
||||
public ScopeState ConvertVector2ToState(Vector2 vector)
|
||||
{
|
||||
//if()
|
||||
int currentSection = (int)Math.Ceiling(Math.Atan2(vector.Y,
|
||||
int currentSection = 0;
|
||||
if(vector.X == 0f && vector.Y == 0f){
|
||||
currentScopeState = ScopeState.Idle;
|
||||
}
|
||||
else
|
||||
{
|
||||
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 -1:
|
||||
currentScopeState = ScopeState.Idle;
|
||||
break;
|
||||
case 0 or 1:
|
||||
currentScopeState = ScopeState.Right;
|
||||
break;
|
||||
|
@ -242,6 +249,11 @@ namespace ZoFo.GameCore.GameManagers
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
DebugHUD.DebugSet("current section", currentSection.ToString());
|
||||
DebugHUD.DebugSet("y", vector.Y.ToString());
|
||||
DebugHUD.DebugSet("x", vector.X.ToString());
|
||||
}
|
||||
return currentScopeState;
|
||||
}
|
||||
#endregion
|
||||
|
|
|
@ -8,6 +8,6 @@ namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player
|
|||
{
|
||||
internal interface IPlayerWeaponAttack
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
|
|||
using ZoFo.GameCore.Graphics;
|
||||
using System.Diagnostics;
|
||||
using ZoFo.GameCore.GUI;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ZoFo.GameCore.GameObjects;
|
||||
|
||||
|
@ -25,7 +26,9 @@ public class Player : LivingEntity
|
|||
private float speed;
|
||||
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.Animations, AppManager.Instance.AssetManager.Player.IdleAnimation);
|
||||
|
||||
public AnimatedGraphicsComponent animatedGraphicsComponent => graphicsComponent as AnimatedGraphicsComponent;
|
||||
|
||||
private LootData lootData;
|
||||
public bool IsTryingToInteract { get; set; }
|
||||
|
@ -42,47 +45,103 @@ public class Player : LivingEntity
|
|||
|
||||
public override void Update()
|
||||
{
|
||||
#region анимация управления, стрельбы
|
||||
var textureName = (graphicsComponent as AnimatedGraphicsComponent).CurrentAnimation.TextureName;
|
||||
var animatedGraphicsComponent = graphicsComponent as AnimatedGraphicsComponent;
|
||||
#region название current текстуры
|
||||
var idName = animatedGraphicsComponent.CurrentAnimation.Id;
|
||||
#endregion
|
||||
|
||||
#region анимация управления подбора лута
|
||||
DebugHUD.DebugSet("texture name", idName);
|
||||
switch(AppManager.Instance.InputManager.ConvertVector2ToState(InputPlayerRotation))
|
||||
{
|
||||
case ScopeState.Top:
|
||||
|
||||
if ((graphicsComponent as AnimatedGraphicsComponent).CurrentAnimation.TextureName!="player_run_right")
|
||||
(graphicsComponent as AnimatedGraphicsComponent).StartCyclingAnimation("player_run_right");
|
||||
if (idName!="player_run_up")
|
||||
StartAnimation("player_run_up");
|
||||
break;
|
||||
case ScopeState.Down:
|
||||
if (textureName!="player_run_down")
|
||||
animatedGraphicsComponent.StartCyclingAnimation("player_run_down");
|
||||
break;
|
||||
if (idName!="player_run_down")
|
||||
StartAnimation("player_run_down");
|
||||
break;
|
||||
case ScopeState.Right:
|
||||
if (textureName!="player_run_up")
|
||||
animatedGraphicsComponent.StartCyclingAnimation("player_run_up");
|
||||
break;
|
||||
case ScopeState.Left:
|
||||
if (textureName!="player_run_left")
|
||||
animatedGraphicsComponent.StartCyclingAnimation("player_run_left");
|
||||
break;
|
||||
if (idName!="player_run_right")
|
||||
StartAnimation("player_run_right");
|
||||
break;
|
||||
case ScopeState.TopRight:
|
||||
if (textureName!="player_run_right_up")
|
||||
animatedGraphicsComponent.StartCyclingAnimation("player_run_right_up");
|
||||
break;
|
||||
case ScopeState.TopLeft:
|
||||
if (textureName!="player_run_left_up")
|
||||
animatedGraphicsComponent.StartCyclingAnimation("player_run_left_up");
|
||||
if (idName!="player_run_right_up")
|
||||
StartAnimation("player_run_right_up");
|
||||
break;
|
||||
case ScopeState.DownRight:
|
||||
if (textureName!="player_run_right_down")
|
||||
animatedGraphicsComponent.StartCyclingAnimation("player_run_right_down");
|
||||
break;
|
||||
case ScopeState.DownLeft:
|
||||
if (textureName!="player_run_left_down")
|
||||
animatedGraphicsComponent.StartCyclingAnimation("player_run_left_down");
|
||||
if (idName!="player_run_right_down")
|
||||
StartAnimation("player_run_right_down");
|
||||
break;
|
||||
case ScopeState.Idle:
|
||||
if (idName!="player_look_down")
|
||||
StartAnimation("player_look_down");
|
||||
break;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region анимация поворота оружия
|
||||
int currentAttackSection = AppManager.Instance.InputManager.ConvertAttackVector2ToState(InputWeaponRotation);
|
||||
switch(currentAttackSection)
|
||||
{
|
||||
case 0 or 1:
|
||||
//right
|
||||
break;
|
||||
case 2 or 3:
|
||||
//down_right_right
|
||||
break;
|
||||
case 4 or 5:
|
||||
//down_right
|
||||
break;
|
||||
case 6 or 7:
|
||||
//down_right_left
|
||||
break;
|
||||
case 8 or 9:
|
||||
//down
|
||||
break;
|
||||
case 10 or 11:
|
||||
//down_left_right
|
||||
break;
|
||||
case 12 or 13:
|
||||
//down_left
|
||||
break;
|
||||
case 14 or 15:
|
||||
//down_left_left
|
||||
break;
|
||||
case 16 or -14:
|
||||
//left
|
||||
break;
|
||||
case -13 or -12:
|
||||
//top_left_left
|
||||
break;
|
||||
case -11 or -10:
|
||||
//top_left
|
||||
break;
|
||||
case -9 or -8:
|
||||
//top_left_right
|
||||
break;
|
||||
case -7 or -6:
|
||||
//top
|
||||
break;
|
||||
case -5 or -4:
|
||||
//top_right_left
|
||||
break;
|
||||
case -3 or -2:
|
||||
//top_right
|
||||
break;
|
||||
case -1 or 0:
|
||||
//top_right_right
|
||||
break;
|
||||
}
|
||||
#endregion
|
||||
|
||||
MovementLogic();
|
||||
}
|
||||
public void WeaponAttack(){
|
||||
|
||||
}
|
||||
public void MovementLogic()
|
||||
{
|
||||
|
@ -114,4 +173,9 @@ public class Player : LivingEntity
|
|||
}
|
||||
}
|
||||
}
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
//DrawDebugRectangle(spriteBatch, collisionComponent.stopRectangle.SetOrigin(position + new Vector2(10,10)), Color.Green);
|
||||
base.Draw(spriteBatch);
|
||||
}
|
||||
}
|
|
@ -1,13 +1,25 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZoFo.GameCore.GameManagers;
|
||||
using ZoFo.GameCore.GameManagers.CollisionManager;
|
||||
using ZoFo.GameCore.GameObjects.MapObjects.StopObjects;
|
||||
|
||||
namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player.PlayerAttacks
|
||||
{
|
||||
internal class SwordAttack : IPlayerWeaponAttack
|
||||
{
|
||||
Rectangle rectangle;
|
||||
public SwordAttack(){
|
||||
}
|
||||
public Rectangle Attack(Vector2 position){
|
||||
rectangle = new Rectangle((int)position.X, (int)position.Y, 30, 10);
|
||||
|
||||
return rectangle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,7 +136,6 @@ namespace ZoFo.GameCore.Graphics
|
|||
|
||||
buildSourceRectangle();
|
||||
SetInterval();
|
||||
|
||||
}
|
||||
|
||||
public void StartCyclingAnimation(string startedanimationId)
|
||||
|
@ -147,7 +146,6 @@ namespace ZoFo.GameCore.Graphics
|
|||
|
||||
buildSourceRectangle();
|
||||
SetInterval();
|
||||
|
||||
}
|
||||
|
||||
public void StopAnimation()
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"IsFullScreen":false,"MainVolume":1.0,"MusicVolume":1.0,"SoundEffectsVolume":1.0,"Resolution":{"X":1440,"Y":900}}
|
||||
{"IsFullScreen":false,"MainVolume":1.0,"MusicVolume":0.0,"SoundEffectsVolume":1.0,"Resolution":{"X":1440,"Y":900}}
|
Loading…
Add table
Reference in a new issue