Merge branch 'networkFixes' into черешня

# Conflicts:
#	DangerousD/Content/Content.mgcb
#	DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs
This commit is contained in:
Ivan Filipenkov 2023-08-18 19:39:08 +03:00
commit 5e804df2b5
4 changed files with 57 additions and 17 deletions

View file

@ -237,7 +237,7 @@
/build:sliderBackground.png /build:sliderBackground.png
#begin SmokeAnimation2.png #begin smokeAnimation2.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255 /processorParam:ColorKeyColor=255,0,255,255

View file

@ -95,10 +95,10 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
} }
public Rectangle GetShootRectangle(bool isRight) public Rectangle GetShootRectangle(bool isRight)
{ {
if (isRight) if (isRight)
return new Rectangle((int)Pos.X, (int)(Pos.Y) + 10, shootLength + Width, Height / 2); return new Rectangle((int)Pos.X, (int)(Pos.Y) + 10, shootLength + Width, Height / 2);
else else
return new Rectangle((int)Pos.X-shootLength, (int)(Pos.Y) + 10, shootLength, Height / 2); return new Rectangle((int)Pos.X - shootLength, (int)(Pos.Y) + 10, shootLength, Height / 2);
} }
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
{ {
@ -124,7 +124,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
return; return;
} }
isAttacked = true; isAttacked = true;
if(monsterName == "Zombie") if (monsterName == "Zombie")
{ {
AnimationRectangle deathRectangle = new AnimationRectangle(Pos, "DeathFrom" + monsterName); AnimationRectangle deathRectangle = new AnimationRectangle(Pos, "DeathFrom" + monsterName);
deathRectangle.Gr.actionOfAnimationEnd += (a) => deathRectangle.Gr.actionOfAnimationEnd += (a) =>
@ -135,7 +135,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
} }
}; };
} }
else if(monsterName == "Spider") else if (monsterName == "Spider")
{ {
AnimationRectangle deathRectangle = new AnimationRectangle(Pos, "DeathFrom" + monsterName); AnimationRectangle deathRectangle = new AnimationRectangle(Pos, "DeathFrom" + monsterName);
deathRectangle.Gr.actionOfAnimationEnd += (a) => deathRectangle.Gr.actionOfAnimationEnd += (a) =>
@ -261,7 +261,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
FallingThroughPlatform = false; FallingThroughPlatform = false;
} }
GraphicsComponent.SetCameraPosition(Pos); GraphicsComponent.SetCameraPosition(Pos);
if (!isAttacked || AppManager.Instance.InputManager.InvincibilityCheat) if (!isAttacked || AppManager.Instance.InputManager.InvincibilityCheat)
{ {
if (!isShooting) if (!isShooting)
{ {
@ -348,11 +348,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
} }
} }
} }
if (AppManager.Instance.multiPlayerStatus != MultiPlayerStatus.SinglePlayer)
{
NetworkTask task = new NetworkTask(id, Pos);
AppManager.Instance.NetworkTasks.Add(task);
}
} }
public void MoveDown() public void MoveDown()
{ {
@ -367,7 +362,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
Height = 5; Height = 5;
Width = 5; Width = 5;
} }
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "playerMoveLeft"}, "playerMoveLeft"); protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "playerMoveLeft" }, "playerMoveLeft");
Vector2 direction; Vector2 direction;
Vector2 maindirection; Vector2 maindirection;
public void ShootUpRight() public void ShootUpRight()
@ -376,13 +371,51 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
acceleration = Vector2.Zero; acceleration = Vector2.Zero;
velocity = new Vector2(10, 10) * direction; velocity = new Vector2(10, 10) * direction;
maindirection = velocity; maindirection = velocity;
if (AppManager.Instance.multiPlayerStatus == MultiPlayerStatus.Client)
{
NetworkTask task = new NetworkTask(typeof(Bullet), Pos, id, velocity);
AppManager.Instance.NetworkTasks.Add(task);
AppManager.Instance.GameManager.Remove(this);
}
}
public void ShootRight()
{
direction = new Vector2(1, 0);
acceleration = Vector2.Zero;
velocity = new Vector2(10, 10) * direction;
maindirection = velocity;
if (AppManager.Instance.multiPlayerStatus == MultiPlayerStatus.Client)
{
NetworkTask task = new NetworkTask(typeof(Bullet), Pos, id, velocity);
AppManager.Instance.NetworkTasks.Add(task);
AppManager.Instance.GameManager.Remove(this);
}
}
public void ShootLeft()
{
direction = new Vector2(-1, 0);
acceleration = Vector2.Zero;
velocity = new Vector2(10, 10) * direction;
maindirection = velocity;
if (AppManager.Instance.multiPlayerStatus == MultiPlayerStatus.Client)
{
NetworkTask task = new NetworkTask(typeof(Bullet), Pos, id, velocity);
AppManager.Instance.NetworkTasks.Add(task);
AppManager.Instance.GameManager.Remove(this);
}
} }
public void ShootUpLeft() public void ShootUpLeft()
{ {
direction = new Vector2(-1, -1); direction = new Vector2(-1, -1);
acceleration = Vector2.Zero; acceleration = Vector2.Zero;
velocity = new Vector2(10, 10) * direction; velocity = new Vector2(10, 10) * direction;
maindirection = velocity; maindirection = velocity;
if (AppManager.Instance.multiPlayerStatus == MultiPlayerStatus.Client)
{
NetworkTask task = new NetworkTask(typeof(Bullet), Pos, id, velocity);
AppManager.Instance.NetworkTasks.Add(task);
AppManager.Instance.GameManager.Remove(this);
}
} }
public override void OnCollision(GameObject gameObject) public override void OnCollision(GameObject gameObject)
{ {
@ -391,7 +424,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
if (gameObject is CoreEnemy) if (gameObject is CoreEnemy)
{ {
CoreEnemy enemy = (CoreEnemy)gameObject; CoreEnemy enemy = (CoreEnemy)gameObject;
enemy.TakeDamage(); enemy.TakeDamage(1);
AppManager.Instance.GameManager.Remove(this); AppManager.Instance.GameManager.Remove(this);
} }
base.OnCollision(gameObject); base.OnCollision(gameObject);
@ -399,7 +432,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
} }
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)
{ {
if (maindirection!=velocity) if (maindirection != velocity)
{ {
AppManager.Instance.GameManager.Remove(this); AppManager.Instance.GameManager.Remove(this);
} }
@ -407,4 +440,4 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
} }
} }
} }
} }

View file

@ -236,6 +236,12 @@ namespace DangerousD.GameCore
SoundManager.StartSound(networkTask.name, networkTask.position, GameManager.GetPlayer1.Pos); SoundManager.StartSound(networkTask.name, networkTask.position, GameManager.GetPlayer1.Pos);
break; break;
case NetworkTaskOperationEnum.CreateEntity: case NetworkTaskOperationEnum.CreateEntity:
if (networkTask.type == typeof(Player.Bullet))
{
Player.Bullet bullet = new Player.Bullet(networkTask.position);
bullet.id = networkTask.objId;
bullet.velocity = networkTask.velocity;
}
break; break;
case NetworkTaskOperationEnum.SendPosition: case NetworkTaskOperationEnum.SendPosition:
if (networkTask.objId != GameManager.GetPlayer1.id ) if (networkTask.objId != GameManager.GetPlayer1.id )

View file

@ -38,11 +38,12 @@ namespace DangerousD.GameCore.Network
/// <param name="EntityType"></param> /// <param name="EntityType"></param>
/// <param name="EntityPosition"></param> /// <param name="EntityPosition"></param>
/// <param name="ParentId"></param> /// <param name="ParentId"></param>
public NetworkTask(Type EntityType, Vector2 EntityPosition, int ParentId) public NetworkTask(Type EntityType, Vector2 EntityPosition, int ParentId, Vector2 velocity)
{ {
operation = NetworkTaskOperationEnum.CreateEntity; operation = NetworkTaskOperationEnum.CreateEntity;
type = EntityType; type = EntityType;
position = EntityPosition; position = EntityPosition;
this.velocity = velocity;
objId = ParentId; objId = ParentId;
} }