Some fixes
This commit is contained in:
parent
005ce1cfb8
commit
d3a0c64596
2 changed files with 19 additions and 20 deletions
|
@ -14,6 +14,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
public class Player : LivingEntity
|
public class Player : LivingEntity
|
||||||
{
|
{
|
||||||
bool isAlive = true;
|
bool isAlive = true;
|
||||||
|
bool isJump = false;
|
||||||
public int health;
|
public int health;
|
||||||
public bool isGoRight = false;
|
public bool isGoRight = false;
|
||||||
public Vector2 playerVelocity;
|
public Vector2 playerVelocity;
|
||||||
|
@ -32,7 +33,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
AppManager.Instance.InputManager.MovEventJump += AnimationJump;
|
AppManager.Instance.InputManager.MovEventJump += AnimationJump;
|
||||||
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;
|
||||||
|
|
||||||
|
@ -65,7 +66,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
}
|
}
|
||||||
public void Death(string monsterName)
|
public void Death(string monsterName)
|
||||||
{
|
{
|
||||||
if(monsterName == "Zombie")
|
/*if(monsterName == "Zombie")
|
||||||
{
|
{
|
||||||
DeathRectangle deathRectangle = new DeathRectangle(Pos, "DeathFrom" + monsterName);
|
DeathRectangle deathRectangle = new DeathRectangle(Pos, "DeathFrom" + monsterName);
|
||||||
deathRectangle.Gr.actionOfAnimationEnd += (a) =>
|
deathRectangle.Gr.actionOfAnimationEnd += (a) =>
|
||||||
|
@ -76,14 +77,12 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
isAlive = false;
|
isAlive = false;*/
|
||||||
}
|
}
|
||||||
public void AnimationJump()
|
public void AnimationJump()
|
||||||
{
|
{
|
||||||
if (Keyboard.GetState().IsKeyDown(Keys.Escape))
|
velocity.Y = -30;
|
||||||
{
|
isJump = true;
|
||||||
velocity.Y = -300;
|
|
||||||
}
|
|
||||||
// здесь будет анимация
|
// здесь будет анимация
|
||||||
}
|
}
|
||||||
public void Shoot()
|
public void Shoot()
|
||||||
|
@ -95,40 +94,36 @@ 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;
|
||||||
base.Update(gameTime);
|
if (velocity.Y == 0)
|
||||||
if (!isVisible)
|
|
||||||
{
|
{
|
||||||
|
isJump = false;
|
||||||
}
|
}
|
||||||
|
base.Update(gameTime);
|
||||||
Move(gameTime);
|
Move(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 != "ZombieMoveRight")
|
if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight")
|
||||||
{
|
{
|
||||||
GraphicsComponent.StartAnimation("ZombieMoveRight");
|
GraphicsComponent.StartAnimation("ZombieMoveRight");
|
||||||
}
|
}
|
||||||
_pos = playerVelocity * delta;
|
velocity.X = 10;
|
||||||
}
|
}
|
||||||
else if (!isGoRight)
|
else if (Keyboard.GetState().IsKeyDown(Keys.A))
|
||||||
{
|
{
|
||||||
if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft")
|
if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft")
|
||||||
{
|
{
|
||||||
GraphicsComponent.StartAnimation("ZombieMoveLeft");
|
GraphicsComponent.StartAnimation("ZombieMoveLeft");
|
||||||
}
|
}
|
||||||
_pos= -playerVelocity * delta;
|
velocity.X = -10;
|
||||||
}
|
}
|
||||||
if (_pos.X >= rightBorder)
|
if (Keyboard.GetState().IsKeyDown(Keys.Space) && !isJump)
|
||||||
{
|
{
|
||||||
isGoRight = false;
|
AnimationJump();
|
||||||
}
|
|
||||||
if (_pos.X >= leftBorder)
|
|
||||||
{
|
|
||||||
isGoRight = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void MoveDown()
|
public void MoveDown()
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Add table
Reference in a new issue