From 5db6cee0fa89a1de3b7ff3bad578c0133a6e5936 Mon Sep 17 00:00:00 2001 From: bmvolf Date: Fri, 18 Aug 2023 11:39:54 +0300 Subject: [PATCH] fixed some bags --- DangerousD/Content/animations/playerShootLeft | 25 ++++++++- .../Content/animations/playerShootRight | 25 ++++++++- .../LivingEntities/Monsters/Zombie.cs | 19 ++++--- .../LivingEntities/Player/Player.cs | 52 +++++++++---------- 4 files changed, 84 insertions(+), 37 deletions(-) diff --git a/DangerousD/Content/animations/playerShootLeft b/DangerousD/Content/animations/playerShootLeft index f2b9f3b..e710737 100644 --- a/DangerousD/Content/animations/playerShootLeft +++ b/DangerousD/Content/animations/playerShootLeft @@ -1 +1,24 @@ -{"id":"playerShootLeft","textureName":"playerAnimation","startSpriteRectangle":{"X":201,"Y":34,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"4, 0"} +{ + "id": "playerShootLeft", + "textureName": "playerAnimation", + "startSpriteRectangle": { + "X": 201, + "Y": 34, + "Width": 32, + "Height": 32 + }, + "frameSecond": [ + { + "Item1": 0, + "Item2": 3 + }, + { + "Item1": 1, + "Item2": 20 + } + ], + "textureFrameInterval": 1, + "framesCount": 2, + "isCycle": false, + "offset": "4, 0" +} diff --git a/DangerousD/Content/animations/playerShootRight b/DangerousD/Content/animations/playerShootRight index 922862b..fd11db2 100644 --- a/DangerousD/Content/animations/playerShootRight +++ b/DangerousD/Content/animations/playerShootRight @@ -1 +1,24 @@ -{"id":"playerShootRight","textureName":"playerAnimation","startSpriteRectangle":{"X":201,"Y":1,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"4, 0"} +{ + "id": "playerShootRight", + "textureName": "playerAnimation", + "startSpriteRectangle": { + "X": 201, + "Y": 1, + "Width": 32, + "Height": 32 + }, + "frameSecond": [ + { + "Item1": 0, + "Item2": 3 + }, + { + "Item1": 1, + "Item2": 20 + } + ], + "textureFrameInterval": 1, + "framesCount": 2, + "isCycle": false, + "offset": "4, 0" +} diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs index 373795a..c1737f2 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs @@ -98,19 +98,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { if (isGoRight) { - if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight") - { - GraphicsComponent.StartAnimation("ZombieMoveRight"); - } + StartCicycleAnimation("ZombieMoveRight"); velocity.X = monster_speed; } else if (!isGoRight) { - if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft") - { - GraphicsComponent.StartAnimation("ZombieMoveLeft"); - } + StartCicycleAnimation("ZombieMoveLeft"); velocity.X = -monster_speed; } @@ -167,6 +161,15 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters rightBorder = 760; } } + public void SwitchToRight() + { + isGoRight = true; + } + + public void SwitchToLeft() + { + isGoRight = false; + } public override void Attack(GameTime gameTime) {} diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index f0a3d92..b8e68ba 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -134,43 +134,37 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities { if (bullets > 0) { - if (!isShooting) + if (!isAttacked) { - isShooting = true; - bullets--; - if (isRight) + if (!isShooting) { - if (GraphicsComponent.GetCurrentAnimation != "playerShootRight") + isShooting = true; + bullets--; + if (isRight) { - GraphicsComponent.StartAnimation("playerShootRight"); - } - var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)(Pos.Y - 10f), shootLength + 24, 10), typeof(Zombie)); - if (targets != null) - { - foreach (var target in targets) + StartCicycleAnimation("playerShootRight"); + var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)(Pos.Y - 10f), shootLength + 24, 10), typeof(Zombie)).OrderBy(x => (x.Pos - Pos).LengthSquared()); + if (targets != null) { - Zombie targetZombie = (Zombie)target; + Zombie targetZombie = (Zombie)targets.First(); targetZombie.TakeDamage(); } + SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X + 30, Pos.Y + 7)); } - SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X + 30, Pos.Y + 7)); - } - else - { - if (GraphicsComponent.GetCurrentAnimation != "playerShootLeft") + else { - GraphicsComponent.StartAnimation("playerShootLeft"); - } - var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - shootLength, (int)(Pos.Y - 10f), shootLength, 10), typeof(Zombie)); - if (targets != null) - { - foreach (var target in targets) + StartCicycleAnimation("playerShootLeft"); + var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - shootLength, (int)(Pos.Y - 10f), shootLength, 10), typeof(Zombie)); + if (targets != null) { - Zombie targetZombie = (Zombie)target; - targetZombie.TakeDamage(); + foreach (var target in targets) + { + Zombie targetZombie = (Zombie)target; + targetZombie.TakeDamage(); + } } + SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X - 12, Pos.Y + 7)); } - SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X - 12, Pos.Y + 7)); } } } @@ -190,7 +184,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) { @@ -201,6 +195,10 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities velocity.X = 0; } } + else + { + velocity.X = 0; + } base.Update(gameTime); }