Merge branch 'main' into livingEntities

This commit is contained in:
bmvolf 2023-08-17 20:00:08 +03:00
commit a3d9efdea7
5 changed files with 67 additions and 29 deletions

View file

@ -1 +1,20 @@
{"id":"playerMoveLeft","textureName":"playerAnimation","startSpriteRectangle":{"X":26,"Y":1,"Width":24,"Height":32},"frameSecond":[{"Item1":0,"Item2":8}],"textureFrameInterval":1,"framesCount":4,"isCycle":true,"offset":"0, 0"} {
"id": "playerMoveLeft",
"textureName": "playerAnimation",
"startSpriteRectangle": {
"X": 26,
"Y": 34,
"Width": 24,
"Height": 32
},
"frameSecond": [
{
"Item1": 0,
"Item2": 8
}
],
"textureFrameInterval": 1,
"framesCount": 4,
"isCycle": true,
"offset": "0, 0"
}

View file

@ -1 +1,20 @@
{"id":"playerMoveRight","textureName":"playerAnimation","startSpriteRectangle":{"X":26,"Y":34,"Width":24,"Height":32},"frameSecond":[{"Item1":0,"Item2":8}],"textureFrameInterval":1,"framesCount":4,"isCycle":true,"offset":"0, 0"} {
"id": "playerMoveRight",
"textureName": "playerAnimation",
"startSpriteRectangle": {
"X": 26,
"Y": 1,
"Width": 24,
"Height": 32
},
"frameSecond": [
{
"Item1": 0,
"Item2": 8
}
],
"textureFrameInterval": 1,
"framesCount": 4,
"isCycle": true,
"offset": "0, 0"
}

View file

@ -13,7 +13,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{ {
public class Zombie : CoreEnemy public class Zombie : CoreEnemy
{ {
private bool isGoRight = true;
float leftBorder; float leftBorder;
float rightBorder; float rightBorder;
bool isAttaking = false; bool isAttaking = false;
@ -28,6 +27,15 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
leftBorder = (int)position.X - 50; leftBorder = (int)position.X - 50;
rightBorder = (int)position.X + 50; rightBorder = (int)position.X + 50;
physicsManager = new PhysicsManager(); physicsManager = new PhysicsManager();
Random random = new Random();
if(random.Next(0, 2) == 0)
{
isGoRight = true;
}
else
{
isGoRight = false;
}
} }
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft"); protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft");
@ -112,7 +120,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
public override void Target() public override void Target()
{ {
if (AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - 50, (int)Pos.Y, Width + 100, Height), typeof(Player)) != null) if (AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - 50, (int)Pos.Y, Width + 100, Height), typeof(Player)).Count > 0)
{ {
if (isGoRight && this._pos.X <= AppManager.Instance.GameManager.players[0].Pos.X) if (isGoRight && this._pos.X <= AppManager.Instance.GameManager.players[0].Pos.X)
{ {

View file

@ -16,6 +16,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
bool isAlive = true; bool isAlive = true;
bool isRight; bool isRight;
string stayAnimation; string stayAnimation;
bool isJump = false;
public int health; public int health;
public bool isGoRight = false; public bool isGoRight = false;
public Vector2 playerVelocity; public Vector2 playerVelocity;
@ -31,20 +32,15 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
AppManager.Instance.InputManager.ShootEvent += Shoot; AppManager.Instance.InputManager.ShootEvent += Shoot;
AppManager.Instance.InputManager.MovEventJump += AnimationJump; AppManager.Instance.InputManager.MovEventJump += Jump;
AppManager.Instance.InputManager.MovEventDown += MoveDown; AppManager.Instance.InputManager.MovEventDown += MoveDown;
playerVelocity = new Vector2(100, 0); velocity = new Vector2(0, 0);
rightBorder = (int)position.X + 100; rightBorder = (int)position.X + 100;
leftBorder = (int)position.X - 100; leftBorder = (int)position.X - 100;
} }
private void AnimationJump()
{
velocity.Y = -300;
}
public bool IsAlive { get { return isAlive; } } public bool IsAlive { get { return isAlive; } }
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "playerMoveLeft", "playerMoveRight", "DeathFromZombie", "playerRightStay", "playerStayLeft", protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "playerMoveLeft", "playerMoveRight", "DeathFromZombie", "playerRightStay", "playerStayLeft",
@ -89,12 +85,8 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
} }
public void Jump() public void Jump()
{ {
velocity.Y = -300; velocity.Y = -30;
//сюда анимацию и доделать isJump = true;
if (Keyboard.GetState().IsKeyDown(Keys.Escape))
{
velocity.Y = -300;
}
// здесь будет анимация // здесь будет анимация
} }
public void Shoot() public void Shoot()
@ -106,9 +98,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
{ {
GraphicsComponent.CameraPosition = (_pos-new Vector2(200, 350)).ToPoint(); GraphicsComponent.CameraPosition = (_pos-new Vector2(200, 350)).ToPoint();
velocity.X = 0.5f; velocity.X = 0.5f;
if (!isVisible) if (velocity.Y == 0)
{ {
isJump = false;
} }
Move(gameTime); Move(gameTime);
base.Update(gameTime); base.Update(gameTime);
@ -117,29 +109,25 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
public void Move(GameTime gameTime) public void Move(GameTime gameTime)
{ {
float delta = (float)gameTime.ElapsedGameTime.TotalSeconds; float delta = (float)gameTime.ElapsedGameTime.TotalSeconds;
if (isGoRight) if (Keyboard.GetState().IsKeyDown(Keys.D))
{ {
if (GraphicsComponent.GetCurrentAnimation != "playerMoveRight") if (GraphicsComponent.GetCurrentAnimation != "playerMoveRight")
{ {
GraphicsComponent.StartAnimation("playerMoveRight"); GraphicsComponent.StartAnimation("playerMoveRight");
} }
_pos = playerVelocity * delta; velocity.X = 10;
} }
else if (!isGoRight) else if (Keyboard.GetState().IsKeyDown(Keys.A))
{ {
if (GraphicsComponent.GetCurrentAnimation != "playerMoveLeft") if (GraphicsComponent.GetCurrentAnimation != "playerMoveLeft")
{ {
GraphicsComponent.StartAnimation("playerMoveLeft"); GraphicsComponent.StartAnimation("playerMoveLeft");
} }
_pos= -playerVelocity * delta; velocity.X = -10;
} }
if (_pos.X >= rightBorder) if (Keyboard.GetState().IsKeyDown(Keys.Space) && !isJump)
{ {
isGoRight = false; Jump();
}
if (_pos.X >= leftBorder)
{
isGoRight = true;
} }
} }
public void MoveDown() public void MoveDown()

View file

@ -198,6 +198,10 @@ namespace DangerousD.GameCore.Graphics
private void buildSourceRectangle() private void buildSourceRectangle()
{ {
sourceRectangle = new Rectangle(); sourceRectangle = new Rectangle();
if (currentAnimation == null)
{
currentAnimation = neitralAnimation;
}
sourceRectangle.X = currentAnimation.StartSpriteRectangle.X + currentFrame * sourceRectangle.X = currentAnimation.StartSpriteRectangle.X + currentFrame *
(currentAnimation.StartSpriteRectangle.Width + currentAnimation.TextureFrameInterval); (currentAnimation.StartSpriteRectangle.Width + currentAnimation.TextureFrameInterval);
sourceRectangle.Y = currentAnimation.StartSpriteRectangle.Y; sourceRectangle.Y = currentAnimation.StartSpriteRectangle.Y;