Merge pull request #93 from progtime-net/PlayerAttack

Player attack
This commit is contained in:
SergoDobro 2024-08-20 14:37:29 +03:00 committed by GitHub
commit 2af8b374ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 187 additions and 46 deletions

View file

@ -185,6 +185,33 @@
#begin Textures/Animations/player_right_idle.animation
/copy:Textures/Animations/player_right_idle.animation
#begin Textures/Animations/player_run_down.animation
/copy:Textures/Animations/player_run_down.animation
#begin Textures/Animations/player_run_left_down.animation
/copy:Textures/Animations/player_run_left_down.animation
#begin Textures/Animations/player_run_left_up.animation
/copy:Textures/Animations/player_run_left_up.animation
#begin Textures/Animations/player_run_left.animation
/copy:Textures/Animations/player_run_left.animation
#begin Textures/Animations/player_run_right_down.animation
/copy:Textures/Animations/player_run_right_down.animation
#begin Textures/Animations/player_run_right_up.animation
/copy:Textures/Animations/player_run_right_up.animation
#begin Textures/Animations/player_run_right.animation
/copy:Textures/Animations/player_run_right.animation
#begin Textures/Animations/player_run_right.zip
/copy:Textures/Animations/player_run_right.zip
#begin Textures/Animations/player_run_up.animation
/copy:Textures/Animations/player_run_up.animation
#begin Textures/Animations/player_running_top_rotate.animation
/copy:Textures/Animations/player_running_top_rotate.animation

View file

@ -0,0 +1 @@
{"id":"player_run_down","textureName":"Textures/AnimationTextures/Character/hr-level1_running","startSpriteRectangle":{"X":0,"Y":528,"Width":88,"Height":132},"frameSecond":[{"Item1":0,"Item2":2}],"textureFrameInterval":0,"framesCount":22,"isCycle":true,"offset":"0, 0"}

View file

@ -0,0 +1 @@
{"id":"player_run_left","textureName":"Textures/AnimationTextures/Character/hr-level1_running","startSpriteRectangle":{"X":0,"Y":792,"Width":88,"Height":132},"frameSecond":[{"Item1":0,"Item2":2}],"textureFrameInterval":0,"framesCount":22,"isCycle":true,"offset":"0, 0"}

View file

@ -0,0 +1 @@
{"id":"player_run_left_down","textureName":"Textures/AnimationTextures/Character/hr-level1_running","startSpriteRectangle":{"X":0,"Y":660,"Width":88,"Height":132},"frameSecond":[{"Item1":0,"Item2":2}],"textureFrameInterval":0,"framesCount":22,"isCycle":true,"offset":"0, 0"}

View file

@ -0,0 +1 @@
{"id":"player_run_left_up","textureName":"Textures/AnimationTextures/Character/hr-level1_running","startSpriteRectangle":{"X":0,"Y":924,"Width":88,"Height":132},"frameSecond":[{"Item1":0,"Item2":2}],"textureFrameInterval":0,"framesCount":22,"isCycle":true,"offset":"0, 0"}

View file

@ -0,0 +1 @@
{"id":"player_run_right","textureName":"Textures/AnimationTextures/Character/hr-level1_running","startSpriteRectangle":{"X":0,"Y":264,"Width":88,"Height":132},"frameSecond":[{"Item1":0,"Item2":2}],"textureFrameInterval":0,"framesCount":22,"isCycle":true,"offset":"0, 0"}

Binary file not shown.

View file

@ -0,0 +1 @@
{"id":"player_run_right_down","textureName":"Textures/AnimationTextures/Character/hr-level1_running","startSpriteRectangle":{"X":0,"Y":396,"Width":88,"Height":132},"frameSecond":[{"Item1":0,"Item2":2}],"textureFrameInterval":0,"framesCount":22,"isCycle":true,"offset":"0, 0"}

View file

@ -0,0 +1 @@
{"id":"player_run_right_up","textureName":"Textures/AnimationTextures/Character/hr-level1_running","startSpriteRectangle":{"X":0,"Y":132,"Width":88,"Height":132},"frameSecond":[{"Item1":0,"Item2":2}],"textureFrameInterval":0,"framesCount":22,"isCycle":true,"offset":"0, 0"}

View file

@ -0,0 +1 @@
{"id":"player_run_up","textureName":"Textures/AnimationTextures/Character/hr-level1_running","startSpriteRectangle":{"X":0,"Y":0,"Width":88,"Height":132},"frameSecond":[{"Item1":0,"Item2":2}],"textureFrameInterval":0,"framesCount":22,"isCycle":true,"offset":"0, 0"}

View file

@ -38,7 +38,7 @@ public abstract class AbstractGUI
public virtual void LoadContent()
{
Manager.LoadContent(AppManager.Instance.Content, "Font");
Manager.LoadContent(AppManager.Instance.Content, "Fonts/Font");
mouse = AppManager.Instance.Content.Load<Texture2D>("Textures/GUI/mouse");
}

View file

@ -12,7 +12,9 @@ public class AssetManager
public AssetContainer Player = new()
{
Animations = [ "player_look_down" ],
Animations = [ "player_look_down", "player_run_up", "player_run_down", "player_run_right",
"player_run_left", "player_run_right_up", "player_run_left_up", "player_run_right_down",
"player_run_left_down" ],
IdleAnimation = "player_look_down"
};
}

View file

@ -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, событие срабатывает)
@ -177,7 +170,6 @@ namespace ZoFo.GameCore.GameManagers
#region Обработка взаимодействия с collectable(например лутом). Вызывает событие OnInteract
if (keyBoardState.IsKeyDown(Keys.E) && !isInteract)
{
OnInteract?.Invoke();
Debug.WriteLine("взаимодействие с Collectable");
}
@ -204,18 +196,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;
@ -243,6 +250,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

View file

@ -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;
@ -24,12 +25,15 @@ public class Player : LivingEntity
public float health= 100;
public float MaxHealth = 100;
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(AppManager.Instance.AssetManager.Player.Animations, AppManager.Instance.AssetManager.Player.IdleAnimation);
public AnimatedGraphicsComponent animatedGraphicsComponent => graphicsComponent as AnimatedGraphicsComponent;
public float rad = 0;
public float MaxRad = 100;
public LootData lootData;
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(AppManager.Instance.AssetManager.Player);
public bool IsTryingToInteract { get; set; }
@ -42,8 +46,8 @@ public class Player : LivingEntity
lootData = new LootData();
lootData.loots = new Dictionary<string, int>();
graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30);
collisionComponent.stopRectangle = new Rectangle(0, 20, 30, 10);
speed = 5;
collisionComponent.stopRectangle = new Rectangle(0, 15, 30, 15);
speed = 2.5f;
StartAnimation("player_look_down");
}
@ -51,42 +55,109 @@ public class Player : LivingEntity
public override void Update()
{
#region название current текстуры
var idName = animatedGraphicsComponent.CurrentAnimation.Id;
#endregion
#region анимация управления подбора лута
DebugHUD.DebugSet("texture name", idName);
if (reloading>0)
{
reloading--;
}
#region анимация управления, стрельбы
switch(AppManager.Instance.InputManager.ConvertVector2ToState(InputPlayerRotation))
{
case ScopeState.Top:
if (idName!="player_run_up")
StartAnimation("player_run_up");
break;
case ScopeState.Down:
if (idName!="player_run_down")
StartAnimation("player_run_down");
break;
case ScopeState.Right:
//StartAnimation("player_running_top_rotate");
break;
case ScopeState.Left:
if (idName!="player_run_right")
StartAnimation("player_run_right");
break;
case ScopeState.TopRight:
break;
case ScopeState.TopLeft:
if (idName!="player_run_right_up")
StartAnimation("player_run_right_up");
break;
case ScopeState.DownRight:
break;
case ScopeState.DownLeft:
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()
{
@ -132,10 +203,6 @@ public class Player : LivingEntity
rect.Width += 100;
rect.Height += 100;
Entity[] entities = AppManager.Instance.server.collisionManager.GetEntities(rect, this);
AppManager.Instance.server.RegisterGameObject(new Particle(rect.Location.ToVector2()));
if (entities.Length>0)
{
DebugHUD.DebugSet("ent[0]", entities[0].ToString());
if (entities != null)
{
foreach (Entity entity in entities)
@ -147,5 +214,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);
}
}

View file

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

View file

@ -136,7 +136,16 @@ namespace ZoFo.GameCore.Graphics
buildSourceRectangle();
SetInterval();
}
public void StartCyclingAnimation(string startedanimationId)
{
currentFrame = 0;
currentAnimation = animations.Find(x => x.Id == startedanimationId);
currentAnimation.IsCycle = true;
buildSourceRectangle();
SetInterval();
}
public void StopAnimation()

View file

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