added player death

This commit is contained in:
bmvolf 2023-08-17 11:40:52 +03:00
parent f7ef5e835b
commit adc2d44243
4 changed files with 13 additions and 8 deletions

View file

@ -20,6 +20,9 @@ namespace DangerousD.GameCore.GameObjects.PlayerDeath
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> {"DeathFromZombie"}, protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> {"DeathFromZombie"},
"DeathFromZombie"); "DeathFromZombie");
public GraphicsComponent Gr => GraphicsComponent;
private void PlayDeath(string deathName) private void PlayDeath(string deathName)
{ {
if (GraphicsComponent.GetCurrentAnimation != "DeathFromZombie") if (GraphicsComponent.GetCurrentAnimation != "DeathFromZombie")

View file

@ -16,10 +16,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
{ {
Width = 32; Width = 32;
Height = 64; Height = 64;
/*GraphicsComponent.actionOfAnimationEnd += () =>
{
AppManager.Instance.ChangeGameState(GameState.GameOver);
};*/
} }
public bool IsAlive { get { return isAlive; } } public bool IsAlive { get { return isAlive; } }
@ -35,7 +31,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
if(monsterName == "Zombie") if(monsterName == "Zombie")
{ {
DeathRectangle deathRectangle = new DeathRectangle(Pos, "DeathFrom" + monsterName); DeathRectangle deathRectangle = new DeathRectangle(Pos, "DeathFrom" + monsterName);
//GraphicsComponent.actionOfAnimationEnd(); deathRectangle.Gr.actionOfAnimationEnd += (a) =>
{
if (a == "DeathFrom" + monsterName)
{
AppManager.Instance.ChangeGameState(GameState.GameOver);
}
};
} }
isAlive = false; isAlive = false;
} }

View file

@ -11,7 +11,7 @@ namespace DangerousD.GameCore.Graphics
public class GraphicsComponent public class GraphicsComponent
{ {
public Action<string> actionOfAnimationEnd; public event Action<string> actionOfAnimationEnd;
private List<AnimationContainer> animations; private List<AnimationContainer> animations;
private List<Texture2D> textures; private List<Texture2D> textures;
private List<string> texturesNames; private List<string> texturesNames;
@ -29,13 +29,11 @@ namespace DangerousD.GameCore.Graphics
private int interval; private int interval;
private int lastInterval; private int lastInterval;
private Rectangle sourceRectangle; private Rectangle sourceRectangle;
public GraphicsComponent(List<string> animationsId, string neitralAnimationId) public GraphicsComponent(List<string> animationsId, string neitralAnimationId)
{ {
//this._spriteBatch = _spriteBatch; //this._spriteBatch = _spriteBatch;
currentFrame = 0; currentFrame = 0;
lastInterval = 1; lastInterval = 1;
LoadAnimations(animationsId, neitralAnimationId); LoadAnimations(animationsId, neitralAnimationId);
currentAnimation = neitralAnimation; currentAnimation = neitralAnimation;
SetInterval(); SetInterval();

View file

@ -162,6 +162,8 @@ namespace DangerousD.GameCore
case GameState.Game: case GameState.Game:
GameManager.mapManager.LoadLevel(""); GameManager.mapManager.LoadLevel("");
break; break;
case GameState.GameOver:
break;
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }