diff --git a/DangerousD/Content/animation1.png b/DangerousD/Content/animation1.png new file mode 100644 index 0000000..bbc2157 Binary files /dev/null and b/DangerousD/Content/animation1.png differ diff --git a/DangerousD/Content/animations/playerReload b/DangerousD/Content/animations/playerReload new file mode 100644 index 0000000..2dd0586 --- /dev/null +++ b/DangerousD/Content/animations/playerReload @@ -0,0 +1 @@ +{"id":"playerReload","textureName":"playerAnimation","startSpriteRectangle":{"X":101,"Y":67,"Width":24,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/playerShootLeft b/DangerousD/Content/animations/playerShootLeft new file mode 100644 index 0000000..f2b9f3b --- /dev/null +++ b/DangerousD/Content/animations/playerShootLeft @@ -0,0 +1 @@ +{"id":"playerShootLeft","textureName":"playerAnimation","startSpriteRectangle":{"X":201,"Y":34,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"4, 0"} diff --git a/DangerousD/Content/animations/playerShootRight b/DangerousD/Content/animations/playerShootRight new file mode 100644 index 0000000..922862b --- /dev/null +++ b/DangerousD/Content/animations/playerShootRight @@ -0,0 +1 @@ +{"id":"playerShootRight","textureName":"playerAnimation","startSpriteRectangle":{"X":201,"Y":1,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"4, 0"} diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs index 06c41a1..188dfb9 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs @@ -27,8 +27,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters Height = 40; monster_speed = 3; name = "Zombie"; - leftBorder = (int)position.X - 50; - rightBorder = (int)position.X + 50; + monster_health = 2; + leftBorder = (int)position.X - 100; + rightBorder = (int)position.X + 100; physicsManager = new PhysicsManager(); Random random = new Random(); if(random.Next(0, 2) == 0) @@ -77,7 +78,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Death() { - + AppManager.Instance.GameManager.Remove(this); } public override void Move(GameTime gameTime) @@ -154,5 +155,15 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public void Attack(GameTime gameTime) {} + + public void TakeDamage() + { + monster_health--; + GraphicsComponent.StartAnimation("ZombieRightAttack"); + if (monster_health <= 0) + { + Death(); + } + } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index 65c5e23..066b1d4 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; using DangerousD.GameCore.GameObjects.PlayerDeath; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Graphics; -using DangerousD.GameCore.Network; +using DangerousD.GameCore.GameObjects.LivingEntities.Monsters; namespace DangerousD.GameCore.GameObjects.LivingEntities { @@ -25,8 +25,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities public int leftBorder; public bool isVisible = true; private bool isAttacked = false; - public bool isInvincible = false; + private bool isShooting = false; public GameObject objectAttack; + private int bullets; public Player(Vector2 position) : base(position) { @@ -37,21 +38,30 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities AppManager.Instance.InputManager.MovEventJump += Jump; AppManager.Instance.InputManager.MovEventDown += MoveDown; + AppManager.Instance.InputManager.ShootEvent += Shoot; velocity = new Vector2(0, 0); rightBorder = (int)position.X + 100; leftBorder = (int)position.X - 100; - } + bullets = 5; - public Player(Vector2 position, bool isInvincible = false) : this(position) - { - this.isInvincible = isInvincible; + this.GraphicsComponent.actionOfAnimationEnd += (a) => + { + if (a == "playerShootLeft" || a == "playerShootRight") + { + isShooting = false; + } + if (a == "playerReload") + { + bullets++; + } + }; } public bool IsAlive { get { return isAlive; } } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "playerMoveLeft", "playerMoveRight", "DeathFromZombie", "playerRightStay", "playerStayLeft", - "playerJumpRight" , "playerJumpLeft"}, "playerStayLeft"); + "playerJumpRight" , "playerJumpLeft", "playerShootLeft", "playerShootRight", "playerReload"}, "playerReload"); public void Attack() { @@ -59,6 +69,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities { isVisible = false; } + } public override void OnCollision(GameObject gameObject) { @@ -97,9 +108,47 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities } public void Shoot() { - + if (bullets > 0) + { + if (!isShooting) + { + isShooting = true; + bullets--; + if (isRight) + { + if (GraphicsComponent.GetCurrentAnimation != "playerShootRight") + { + GraphicsComponent.StartAnimation("playerShootRight"); + } + var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)(Pos.Y - 10f), 100, 10), typeof(Zombie)); + if (targets != null) + { + foreach (var target in targets) + { + Zombie targetZombie = (Zombie)target; + targetZombie.TakeDamage(); + } + } + } + else + { + if (GraphicsComponent.GetCurrentAnimation != "playerShootRight") + { + GraphicsComponent.StartAnimation("playerShootRight"); + } + var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)(Pos.Y - 10f), -100, 10), typeof(Zombie)); + if (targets != null) + { + foreach (var target in targets) + { + Zombie targetZombie = (Zombie)target; + targetZombie.TakeDamage(); + } + } + } + } + } } - public override void Update(GameTime gameTime) { GraphicsComponent.SetCameraPosition(Pos); @@ -118,25 +167,41 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities { float delta = (float)gameTime.ElapsedGameTime.TotalSeconds; velocity.X = 5 * AppManager.Instance.InputManager.VectorMovementDirection.X; - if (AppManager.Instance.InputManager.VectorMovementDirection.X > 0) + if (GraphicsComponent.GetCurrentAnimation != "playerShootLeft" && GraphicsComponent.GetCurrentAnimation != "playerShootRight") { - if (GraphicsComponent.GetCurrentAnimation != "playerMoveRight")//идёт направо + if (AppManager.Instance.InputManager.VectorMovementDirection.X > 0) { - GraphicsComponent.StartAnimation("playerMoveRight"); + isRight = true; + if (GraphicsComponent.GetCurrentAnimation != "playerMoveRight")//идёт направо + { + GraphicsComponent.StartAnimation("playerMoveRight"); + } } - } - else if (AppManager.Instance.InputManager.VectorMovementDirection.X < 0)//идёт налево - { - if (GraphicsComponent.GetCurrentAnimation != "playerMoveLeft") + else if (AppManager.Instance.InputManager.VectorMovementDirection.X < 0)//идёт налево { - GraphicsComponent.StartAnimation("playerMoveLeft"); + isRight = false; + if (GraphicsComponent.GetCurrentAnimation != "playerMoveLeft") + { + GraphicsComponent.StartAnimation("playerMoveLeft"); + } } - } - else if(AppManager.Instance.InputManager.VectorMovementDirection.X == 0)//стоит - { - if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft") + else if (AppManager.Instance.InputManager.VectorMovementDirection.X == 0)//стоит { - GraphicsComponent.StartAnimation("ZombieMoveLeft"); + if(bullets < 5) + { + if (GraphicsComponent.GetCurrentAnimation != "playerReload") + { + GraphicsComponent.StartAnimation("playerReload"); + } + } + else if (isRight) + { + GraphicsComponent.StartAnimation("playerRightStay"); + } + else if (!isRight) + { + GraphicsComponent.StartAnimation("playerStayLeft"); + } } } if (AppManager.Instance.multiPlayerStatus != MultiPlayerStatus.SinglePlayer)