Some fixes

This commit is contained in:
AnloGames 2023-08-17 18:46:46 +03:00
parent 005ce1cfb8
commit d3a0c64596
2 changed files with 19 additions and 20 deletions

View file

@ -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()

View file

@ -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;