From d3a0c6459637e6502e43627903aa013365f5c448 Mon Sep 17 00:00:00 2001 From: AnloGames <7383an@gmail.com> Date: Thu, 17 Aug 2023 18:46:46 +0300 Subject: [PATCH] Some fixes --- .../LivingEntities/Player/Player.cs | 35 ++++++++----------- .../GameCore/Graphics/GraphicsComponent.cs | 4 +++ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index 742d3dd..d4e616b 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -14,6 +14,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities public class Player : LivingEntity { bool isAlive = true; + bool isJump = false; public int health; public bool isGoRight = false; public Vector2 playerVelocity; @@ -32,7 +33,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities AppManager.Instance.InputManager.MovEventJump += AnimationJump; 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; @@ -65,7 +66,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities } public void Death(string monsterName) { - if(monsterName == "Zombie") + /*if(monsterName == "Zombie") { DeathRectangle deathRectangle = new DeathRectangle(Pos, "DeathFrom" + monsterName); deathRectangle.Gr.actionOfAnimationEnd += (a) => @@ -76,14 +77,12 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities } }; } - isAlive = false; + isAlive = false;*/ } public void AnimationJump() { - if (Keyboard.GetState().IsKeyDown(Keys.Escape)) - { - velocity.Y = -300; - } + velocity.Y = -30; + isJump = true; // здесь будет анимация } public void Shoot() @@ -95,40 +94,36 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities { GraphicsComponent.CameraPosition = (_pos-new Vector2(200, 350)).ToPoint(); velocity.X = 0.5f; - base.Update(gameTime); - if (!isVisible) + if (velocity.Y == 0) { - + isJump = false; } + base.Update(gameTime); Move(gameTime); } public void Move(GameTime gameTime) { float delta = (float)gameTime.ElapsedGameTime.TotalSeconds; - if (isGoRight) + if (Keyboard.GetState().IsKeyDown(Keys.D)) { if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight") { GraphicsComponent.StartAnimation("ZombieMoveRight"); } - _pos = playerVelocity * delta; + velocity.X = 10; } - else if (!isGoRight) + else if (Keyboard.GetState().IsKeyDown(Keys.A)) { if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft") { GraphicsComponent.StartAnimation("ZombieMoveLeft"); } - _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; + AnimationJump(); } } 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;