From adc2d442430f0d1876bd9e38e5218059893c640c Mon Sep 17 00:00:00 2001 From: bmvolf Date: Thu, 17 Aug 2023 11:40:52 +0300 Subject: [PATCH] added player death --- .../LivingEntities/Player/DeathRectangle.cs | 3 +++ .../GameObjects/LivingEntities/Player/Player.cs | 12 +++++++----- DangerousD/GameCore/Graphics/GraphicsComponent.cs | 4 +--- DangerousD/GameCore/Managers/AppManager.cs | 2 ++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/DeathRectangle.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/DeathRectangle.cs index 1ddaf45..1867b60 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/DeathRectangle.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/DeathRectangle.cs @@ -20,6 +20,9 @@ namespace DangerousD.GameCore.GameObjects.PlayerDeath protected override GraphicsComponent GraphicsComponent { get; } = new(new List {"DeathFromZombie"}, "DeathFromZombie"); + + public GraphicsComponent Gr => GraphicsComponent; + private void PlayDeath(string deathName) { if (GraphicsComponent.GetCurrentAnimation != "DeathFromZombie") diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index 7f25a41..b194de9 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -16,10 +16,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities { Width = 32; Height = 64; - /*GraphicsComponent.actionOfAnimationEnd += () => - { - AppManager.Instance.ChangeGameState(GameState.GameOver); - };*/ } public bool IsAlive { get { return isAlive; } } @@ -35,7 +31,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities if(monsterName == "Zombie") { DeathRectangle deathRectangle = new DeathRectangle(Pos, "DeathFrom" + monsterName); - //GraphicsComponent.actionOfAnimationEnd(); + deathRectangle.Gr.actionOfAnimationEnd += (a) => + { + if (a == "DeathFrom" + monsterName) + { + AppManager.Instance.ChangeGameState(GameState.GameOver); + } + }; } isAlive = false; } diff --git a/DangerousD/GameCore/Graphics/GraphicsComponent.cs b/DangerousD/GameCore/Graphics/GraphicsComponent.cs index 6c86077..ca70881 100644 --- a/DangerousD/GameCore/Graphics/GraphicsComponent.cs +++ b/DangerousD/GameCore/Graphics/GraphicsComponent.cs @@ -11,7 +11,7 @@ namespace DangerousD.GameCore.Graphics public class GraphicsComponent { - public Action actionOfAnimationEnd; + public event Action actionOfAnimationEnd; private List animations; private List textures; private List texturesNames; @@ -29,13 +29,11 @@ namespace DangerousD.GameCore.Graphics private int interval; private int lastInterval; private Rectangle sourceRectangle; - public GraphicsComponent(List animationsId, string neitralAnimationId) { //this._spriteBatch = _spriteBatch; currentFrame = 0; lastInterval = 1; - LoadAnimations(animationsId, neitralAnimationId); currentAnimation = neitralAnimation; SetInterval(); diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index ab061b9..1e65ac7 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -162,6 +162,8 @@ namespace DangerousD.GameCore case GameState.Game: GameManager.mapManager.LoadLevel(""); break; + case GameState.GameOver: + break; default: throw new ArgumentOutOfRangeException(); }