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
#begin SmokeAnimation2.png
#begin smokeAnimation2.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255

View file

@ -98,7 +98,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
if (isRight)
return new Rectangle((int)Pos.X, (int)(Pos.Y) + 10, shootLength + Width, Height / 2);
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)
{
@ -124,7 +124,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
return;
}
isAttacked = true;
if(monsterName == "Zombie")
if (monsterName == "Zombie")
{
AnimationRectangle deathRectangle = new AnimationRectangle(Pos, "DeathFrom" + monsterName);
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);
deathRectangle.Gr.actionOfAnimationEnd += (a) =>
@ -261,7 +261,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
FallingThroughPlatform = false;
}
GraphicsComponent.SetCameraPosition(Pos);
if (!isAttacked || AppManager.Instance.InputManager.InvincibilityCheat)
if (!isAttacked || AppManager.Instance.InputManager.InvincibilityCheat)
{
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()
{
@ -367,7 +362,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
Height = 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 maindirection;
public void ShootUpRight()
@ -376,13 +371,51 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
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 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()
{
direction = new Vector2(-1, -1);
acceleration = Vector2.Zero;
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)
{
@ -391,7 +424,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
if (gameObject is CoreEnemy)
{
CoreEnemy enemy = (CoreEnemy)gameObject;
enemy.TakeDamage();
enemy.TakeDamage(1);
AppManager.Instance.GameManager.Remove(this);
}
base.OnCollision(gameObject);
@ -399,7 +432,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
}
public override void Update(GameTime gameTime)
{
if (maindirection!=velocity)
if (maindirection != velocity)
{
AppManager.Instance.GameManager.Remove(this);
}

View file

@ -236,6 +236,12 @@ namespace DangerousD.GameCore
SoundManager.StartSound(networkTask.name, networkTask.position, GameManager.GetPlayer1.Pos);
break;
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;
case NetworkTaskOperationEnum.SendPosition:
if (networkTask.objId != GameManager.GetPlayer1.id )

View file

@ -38,11 +38,12 @@ namespace DangerousD.GameCore.Network
/// <param name="EntityType"></param>
/// <param name="EntityPosition"></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;
type = EntityType;
position = EntityPosition;
this.velocity = velocity;
objId = ParentId;
}