diff --git a/DangerousD/Content/Content.mgcb b/DangerousD/Content/Content.mgcb index 8296497..f16b512 100644 --- a/DangerousD/Content/Content.mgcb +++ b/DangerousD/Content/Content.mgcb @@ -237,7 +237,7 @@ /build:sliderBackground.png -#begin SmokeAnimation2.png +#begin smokeAnimation2.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index 6437e4f..6cd93bc 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -95,10 +95,10 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities } public Rectangle GetShootRectangle(bool isRight) { - if (isRight) + 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 { "playerMoveLeft"}, "playerMoveLeft"); + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "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); } @@ -407,4 +440,4 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities } } } -} +} \ No newline at end of file diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index 7689727..62c57b8 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -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 ) diff --git a/DangerousD/GameCore/Network/NetworkTask.cs b/DangerousD/GameCore/Network/NetworkTask.cs index f9b6072..17bf92b 100644 --- a/DangerousD/GameCore/Network/NetworkTask.cs +++ b/DangerousD/GameCore/Network/NetworkTask.cs @@ -38,11 +38,12 @@ namespace DangerousD.GameCore.Network /// /// /// - 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; }