diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index f035c0d..005a6ba 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -14,18 +14,26 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities { bool isAlive = true; public int health; + public bool isGoRight; + public Vector2 playerVelocity; + public int rightBorder; + public Player(Vector2 position) : base(position) { Width = 32; Height = 64; AppManager.Instance.InputManager.MovEventJump += Jump; AppManager.Instance.InputManager.ShootEvent += Shoot; - + playerVelocity = new Vector2(100, 0); + rightBorder = (int)position.X + 20; } public bool IsAlive { get { return isAlive; } } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack", "DeathFromZombie" }, "ZombieMoveLeft");//TODO: Change to player - + public void Update(GameTime gameTime) + { + Move(gameTime); + } public void Kill() { @@ -58,5 +66,30 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities { } + public void Move(GameTime gameTime) + { + float delta = (float)gameTime.ElapsedGameTime.TotalSeconds; + if (isGoRight) + { + if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight") + { + GraphicsComponent.StartAnimation("ZombieMoveRight"); + } + velocity = playerVelocity * delta; + } + else if (!isGoRight) + { + if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft") + { + GraphicsComponent.StartAnimation("ZombieMoveLeft"); + } + velocity = -playerVelocity * delta; + } + if (Pos.X >= rightBorder) + { + Pos.X = rightBorder + } + } + } }