diff --git a/DangerousD/Content/animations/playerMoveLeft b/DangerousD/Content/animations/playerMoveLeft index 404639c..d167573 100644 --- a/DangerousD/Content/animations/playerMoveLeft +++ b/DangerousD/Content/animations/playerMoveLeft @@ -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" +} diff --git a/DangerousD/Content/animations/playerMoveRight b/DangerousD/Content/animations/playerMoveRight index 5ed3010..42d7327 100644 --- a/DangerousD/Content/animations/playerMoveRight +++ b/DangerousD/Content/animations/playerMoveRight @@ -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" +} diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs index f4d636c..4ab4494 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs @@ -13,7 +13,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public class Zombie : CoreEnemy { - private bool isGoRight = true; float leftBorder; float rightBorder; bool isAttaking = false; @@ -28,6 +27,15 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters leftBorder = (int)position.X - 50; rightBorder = (int)position.X + 50; 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 { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft"); @@ -112,7 +120,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters } 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) { diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index 67e8845..066bf4d 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -16,6 +16,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities bool isAlive = true; bool isRight; string stayAnimation; + bool isJump = false; public int health; public bool isGoRight = false; public Vector2 playerVelocity; @@ -31,20 +32,15 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities AppManager.Instance.InputManager.ShootEvent += Shoot; - AppManager.Instance.InputManager.MovEventJump += AnimationJump; + AppManager.Instance.InputManager.MovEventJump += Jump; AppManager.Instance.InputManager.MovEventDown += MoveDown; - playerVelocity = new Vector2(100, 0); + velocity = new Vector2(0, 0); rightBorder = (int)position.X + 100; leftBorder = (int)position.X - 100; } - private void AnimationJump() - { - velocity.Y = -300; - } - public bool IsAlive { get { return isAlive; } } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "playerMoveLeft", "playerMoveRight", "DeathFromZombie", "playerRightStay", "playerStayLeft", @@ -89,12 +85,8 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities } public void Jump() { - velocity.Y = -300; - //сюда анимацию и доделать - if (Keyboard.GetState().IsKeyDown(Keys.Escape)) - { - velocity.Y = -300; - } + velocity.Y = -30; + isJump = true; // здесь будет анимация } public void Shoot() @@ -106,9 +98,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities { GraphicsComponent.CameraPosition = (_pos-new Vector2(200, 350)).ToPoint(); velocity.X = 0.5f; - if (!isVisible) + if (velocity.Y == 0) { - + isJump = false; } Move(gameTime); base.Update(gameTime); @@ -117,29 +109,25 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities public void Move(GameTime gameTime) { float delta = (float)gameTime.ElapsedGameTime.TotalSeconds; - if (isGoRight) + if (Keyboard.GetState().IsKeyDown(Keys.D)) { if (GraphicsComponent.GetCurrentAnimation != "playerMoveRight") { GraphicsComponent.StartAnimation("playerMoveRight"); } - _pos = playerVelocity * delta; + velocity.X = 10; } - else if (!isGoRight) + else if (Keyboard.GetState().IsKeyDown(Keys.A)) { if (GraphicsComponent.GetCurrentAnimation != "playerMoveLeft") { GraphicsComponent.StartAnimation("playerMoveLeft"); } - _pos= -playerVelocity * delta; + velocity.X = -10; } - if (_pos.X >= rightBorder) + if (Keyboard.GetState().IsKeyDown(Keys.Space) && !isJump) { - isGoRight = false; - } - if (_pos.X >= leftBorder) - { - isGoRight = true; + Jump(); } } public void MoveDown() diff --git a/DangerousD/GameCore/Graphics/GraphicsComponent.cs b/DangerousD/GameCore/Graphics/GraphicsComponent.cs index 32851e2..e4546b5 100644 --- a/DangerousD/GameCore/Graphics/GraphicsComponent.cs +++ b/DangerousD/GameCore/Graphics/GraphicsComponent.cs @@ -198,6 +198,10 @@ namespace DangerousD.GameCore.Graphics private void buildSourceRectangle() { sourceRectangle = new Rectangle(); + if (currentAnimation == null) + { + currentAnimation = neitralAnimation; + } sourceRectangle.X = currentAnimation.StartSpriteRectangle.X + currentFrame * (currentAnimation.StartSpriteRectangle.Width + currentAnimation.TextureFrameInterval); sourceRectangle.Y = currentAnimation.StartSpriteRectangle.Y;