From b43c3a457dc6caefccd9c28e0e3a76ad4013d55d Mon Sep 17 00:00:00 2001 From: bmvolf Date: Fri, 18 Aug 2023 16:52:38 +0300 Subject: [PATCH 1/4] added up shooting --- .../Content/animations/playerShootBoomUpLeft | 1 + .../Content/animations/playerShootBoomUpRight | 24 ++++ .../LivingEntities/Monsters/CoreEnemy.cs | 4 +- .../LivingEntities/Monsters/Zombie.cs | 4 +- .../LivingEntities/Player/Player.cs | 126 ++++++++++++++---- .../GameCore/GameObjects/LivingEntity.cs | 2 + 6 files changed, 128 insertions(+), 33 deletions(-) create mode 100644 DangerousD/Content/animations/playerShootBoomUpLeft create mode 100644 DangerousD/Content/animations/playerShootBoomUpRight diff --git a/DangerousD/Content/animations/playerShootBoomUpLeft b/DangerousD/Content/animations/playerShootBoomUpLeft new file mode 100644 index 0000000..093eb3c --- /dev/null +++ b/DangerousD/Content/animations/playerShootBoomUpLeft @@ -0,0 +1 @@ +{"id":"playerShootBoomUpLeft","textureName":"playerAnimation","startSpriteRectangle":{"X":267,"Y":34,"Width":24,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/playerShootBoomUpRight b/DangerousD/Content/animations/playerShootBoomUpRight new file mode 100644 index 0000000..3f70e03 --- /dev/null +++ b/DangerousD/Content/animations/playerShootBoomUpRight @@ -0,0 +1,24 @@ +{ + "id": "playerShootBoomUpRight", + "textureName": "playerAnimation", + "startSpriteRectangle": { + "X": 267, + "Y": 1, + "Width": 24, + "Height": 32 + }, + "frameSecond": [ + { + "Item1": 0, + "Item2": 3 + }, + { + "Item1": 1, + "Item2": 20 + } + ], + "textureFrameInterval": 1, + "framesCount": 2, + "isCycle": false, + "offset": "0, 0" +} diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs index 38b1cc0..5f33df9 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs @@ -36,9 +36,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities public abstract void Move(GameTime gameTime); - public void TakeDamage(int damage) + public virtual void TakeDamage() { - monster_health -= damage; + monster_health--; if (monster_health <= 0) { Death(); diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs index 90fdfc2..dd4463b 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs @@ -32,6 +32,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters rightBorder = (int)position.X + 100; physicsManager = new PhysicsManager(); Random random = new Random(); + monster_health = 2; if(random.Next(0, 2) == 0) { isGoRight = true; @@ -174,10 +175,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Attack(GameTime gameTime) {} - public void TakeDamage() + public override void TakeDamage() { monster_health--; - GraphicsComponent.StartAnimation("ZombieRightAttack"); Particle particle = new Particle(Pos); if (monster_health <= 0) { diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index e076bc0..55e6a7b 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -10,6 +10,7 @@ using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Graphics; using DangerousD.GameCore.GameObjects.LivingEntities.Monsters; using DangerousD.GameCore.Network; +using DangerousD.GameCore.GameObjects.MapObjects; namespace DangerousD.GameCore.GameObjects.LivingEntities { @@ -65,6 +66,10 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities { bullets++; } + if(a == "playerShootBoomUpRight" || a == "playerShootBoomUpLeft") + { + isShooting = false; + } }; } @@ -73,7 +78,8 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities public bool IsAlive { get { return isAlive; } } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "playerMoveLeft", "playerMoveRight", "DeathFromZombie", "playerRightStay", "playerStayLeft", - "playerJumpRight" , "playerJumpLeft", "playerShootLeft", "playerShootRight", "playerReload", "smokeAfterShoot", "playerShootUpRight", "playerShootUpLeft"}, "playerReload"); + "playerJumpRight" , "playerJumpLeft", "playerShootLeft", "playerShootRight", "playerReload", "smokeAfterShoot", "playerShootUpRight", "playerShootUpLeft", "playerShootBoomUpRight", + "playerShootBoomUpLeft"}, "playerReload"); public void Attack() { @@ -145,28 +151,45 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities bullets--; if (isRight) { - StartCicycleAnimation("playerShootRight"); - var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)(Pos.Y - 10f), shootLength + 24, 10), typeof(Zombie)).OrderBy(x => (x.Pos - Pos).LengthSquared()); - if (targets.Count() > 0) + if (!isUping) { - Zombie targetZombie = (Zombie)targets.First(); - targetZombie.TakeDamage(); - } - SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X + 30, Pos.Y + 7)); - } - else - { - StartCicycleAnimation("playerShootLeft"); - var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - shootLength, (int)(Pos.Y - 10f), shootLength, 10), typeof(Zombie)); - if (targets != null) - { - foreach (var target in targets) + StartCicycleAnimation("playerShootRight"); + var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)(Pos.Y - 10f), shootLength + 24, 10), typeof(Zombie)).OrderBy(x => (x.Pos - Pos).LengthSquared()); + if (targets.Count() > 0) { - Zombie targetZombie = (Zombie)target; + Zombie targetZombie = (Zombie)targets.First(); targetZombie.TakeDamage(); } + SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X + 30, Pos.Y + 7)); + } + else + { + StartCicycleAnimation("playerShootBoomUpRight"); + Bullet bullet = new Bullet(new Vector2(Pos.X + 16, Pos.Y)); + bullet.ShootUpRight(); + SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X + 12, Pos.Y - 8)); + } + } + else if(!isRight) + { + if (!isUping) + { + StartCicycleAnimation("playerShootLeft"); + var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)(Pos.Y - 10f), shootLength + 24, 10), typeof(Zombie)).OrderBy(x => (x.Pos - Pos).LengthSquared()); + if (targets.Count() > 0) + { + Zombie targetZombie = (Zombie)targets.First(); + targetZombie.TakeDamage(); + } + SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X - 12, Pos.Y + 7)); + } + else + { + StartCicycleAnimation("playerShootBoomUpLeft"); + Bullet bullet = new Bullet(new Vector2(Pos.X, Pos.Y)); + bullet.ShootUpLeft(); + SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X - 6, Pos.Y - 7)); } - SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X - 12, Pos.Y + 7)); } } } @@ -230,14 +253,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities } else if (AppManager.Instance.InputManager.VectorMovementDirection.X == 0)//стоит { - if (bullets < 5) - { - if (GraphicsComponent.GetCurrentAnimation != "playerReload") - { - GraphicsComponent.StartAnimation("playerReload"); - } - } - else if (isRight) + if (isRight) { if (isUping) { @@ -246,6 +262,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities GraphicsComponent.StartAnimation("playerShootUpRight"); } } + else if (bullets < 5) + { + if (GraphicsComponent.GetCurrentAnimation != "playerReload") + { + GraphicsComponent.StartAnimation("playerReload"); + } + } else { GraphicsComponent.StartAnimation("playerRightStay"); @@ -260,6 +283,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities GraphicsComponent.StartAnimation("playerShootUpLeft"); } } + else if (bullets < 5) + { + if (GraphicsComponent.GetCurrentAnimation != "playerReload") + { + GraphicsComponent.StartAnimation("playerReload"); + } + } else { GraphicsComponent.StartAnimation("playerStayLeft"); @@ -279,13 +309,51 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities isOnGround = false; } - public class Bullet : GameObjects.LivingEntity + public class Bullet : LivingEntity { public Bullet(Vector2 position) : base(position) { + Height = 5; + Width = 5; + } + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "playerMoveLeft"}, "playerMoveLeft"); + Vector2 direction; + Vector2 maindirection; + public void ShootUpRight() + { + direction = new Vector2(1, -1); + acceleration = Vector2.Zero; + velocity = new Vector2(10, 10) * direction; + maindirection = velocity; + } + public void ShootUpLeft() + { + direction = new Vector2(-1, -1); + acceleration = Vector2.Zero; + velocity = new Vector2(10, 10) * direction; + maindirection = velocity; + } + public override void OnCollision(GameObject gameObject) + { + if (gameObject is not Player) + { + if (gameObject is CoreEnemy) + { + CoreEnemy enemy = (CoreEnemy)gameObject; + enemy.TakeDamage(); + AppManager.Instance.GameManager.Remove(this); + } + base.OnCollision(gameObject); + } + } + public override void Update(GameTime gameTime) + { + if (maindirection!=velocity) + { + AppManager.Instance.GameManager.Remove(this); + } + base.Update(gameTime); } - protected override GraphicsComponent GraphicsComponent { get; } = new("ZombieMoveLeft"); - } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntity.cs b/DangerousD/GameCore/GameObjects/LivingEntity.cs index 78ea17c..72d61f4 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntity.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntity.cs @@ -10,6 +10,8 @@ public abstract class LivingEntity : Entity public Vector2 velocity; public Vector2 acceleration; + public Vector2 Acceleration { get; private set; } + public LivingEntity(Vector2 position) : base(position) { acceleration = new Vector2(0, 30); From 91db8f92d005a96848d2ad3b17565cc50d7abd10 Mon Sep 17 00:00:00 2001 From: polten0 Date: Fri, 18 Aug 2023 17:37:48 +0300 Subject: [PATCH 2/4] AddDeathAnimations --- DangerousD/Content/animations/DeathFromGhost | 1 + DangerousD/Content/animations/DeathFromHunchman | 1 + DangerousD/Content/animations/DeathFromSilasMaster | 1 + DangerousD/Content/animations/DeathFromSlime | 1 + DangerousD/Content/animations/DeathFromSpider | 1 + DangerousD/Content/animations/DeathFromWerewolf | 1 + 6 files changed, 6 insertions(+) create mode 100644 DangerousD/Content/animations/DeathFromGhost create mode 100644 DangerousD/Content/animations/DeathFromHunchman create mode 100644 DangerousD/Content/animations/DeathFromSilasMaster create mode 100644 DangerousD/Content/animations/DeathFromSlime create mode 100644 DangerousD/Content/animations/DeathFromSpider create mode 100644 DangerousD/Content/animations/DeathFromWerewolf diff --git a/DangerousD/Content/animations/DeathFromGhost b/DangerousD/Content/animations/DeathFromGhost new file mode 100644 index 0000000..b4ef48e --- /dev/null +++ b/DangerousD/Content/animations/DeathFromGhost @@ -0,0 +1 @@ +{"id":"DeathFromGhost","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":246,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/DeathFromHunchman b/DangerousD/Content/animations/DeathFromHunchman new file mode 100644 index 0000000..a00ed27 --- /dev/null +++ b/DangerousD/Content/animations/DeathFromHunchman @@ -0,0 +1 @@ +{"id":"DeathFromHunchman","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":1,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/DeathFromSilasMaster b/DangerousD/Content/animations/DeathFromSilasMaster new file mode 100644 index 0000000..3f9a76b --- /dev/null +++ b/DangerousD/Content/animations/DeathFromSilasMaster @@ -0,0 +1 @@ +{"id":"DeathFromSilasMaster","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":295,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/DeathFromSlime b/DangerousD/Content/animations/DeathFromSlime new file mode 100644 index 0000000..5a692f6 --- /dev/null +++ b/DangerousD/Content/animations/DeathFromSlime @@ -0,0 +1 @@ +{"id":"DeathFromSlime","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":50,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/DeathFromSpider b/DangerousD/Content/animations/DeathFromSpider new file mode 100644 index 0000000..98a08a5 --- /dev/null +++ b/DangerousD/Content/animations/DeathFromSpider @@ -0,0 +1 @@ +{"id":"DeathFromSpider","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":148,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/DeathFromWerewolf b/DangerousD/Content/animations/DeathFromWerewolf new file mode 100644 index 0000000..8f0b150 --- /dev/null +++ b/DangerousD/Content/animations/DeathFromWerewolf @@ -0,0 +1 @@ +{"id":"DeathFromWerewolf","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":197,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"} From d87770f9ec15069794438bf2237eadbf66be1d5a Mon Sep 17 00:00:00 2001 From: Kaktus200020 Date: Fri, 18 Aug 2023 17:19:44 +0300 Subject: [PATCH 3/4] WereWolfAdding --- DangerousD/Content/map.tmx | 5 + .../LivingEntities/Monsters/FrankBalls.cs | 15 ++- .../LivingEntities/Monsters/Slime.cs | 16 ++- .../LivingEntities/Monsters/Werewolf.cs | 102 ++++++++++++++++-- DangerousD/GameCore/Managers/AppManager.cs | 2 +- 5 files changed, 126 insertions(+), 14 deletions(-) diff --git a/DangerousD/Content/map.tmx b/DangerousD/Content/map.tmx index 9afca4d..bcc7b83 100644 --- a/DangerousD/Content/map.tmx +++ b/DangerousD/Content/map.tmx @@ -71,5 +71,10 @@ + + + + + diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs index 9400485..720fd96 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs @@ -17,6 +17,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters private bool isFlyRight = true; private bool isFlyUp = true; private bool isAttacking = false; + private int hp; public Rectangle Collision { @@ -32,6 +33,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters monster_speed = 3; velocity = new Vector2(3,-3); acceleration = Vector2.Zero; + hp = 10; } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "BallMoveRight" }, "BallMoveRight"); @@ -39,7 +41,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Update(GameTime gameTime) { Move(gameTime); - AppManager.Instance.DebugHUD.Set(name, velocity.ToString()); + + Death(); + base.Update(gameTime); } public override void Attack() @@ -60,7 +64,10 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Death() { - + if (hp <= 0) + { + AppManager.Instance.GameManager.Remove(this); + } } public override void Move(GameTime gameTime) @@ -75,6 +82,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { isFlyRight = false; velocity.X = -velocity.X; + hp--; } } else @@ -84,6 +92,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { isFlyRight = true; velocity.X = -velocity.X; + hp--; } } if (isFlyUp) @@ -94,6 +103,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { isFlyUp = false; velocity.Y = -velocity.Y; + hp--; } } else @@ -103,6 +113,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { isFlyUp = true; velocity.Y = -velocity.Y; + hp--; } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Slime.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Slime.cs index 41a2fcc..afdbf9b 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Slime.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Slime.cs @@ -173,7 +173,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters } public override void Death() { + + Particle particle = new Particle(Pos); + + AppManager.Instance.GameManager.Remove(this); } public override void Move(GameTime gameTime) @@ -220,7 +224,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters velocity.X = -monster_speed; } - var getCols= AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 50, 2)); ; + var getCols= AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 50, 2)); if (isGoRight) { getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 51, 2)); @@ -348,5 +352,15 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters } base.OnCollision(gameObject); } + public void TakeDamage() + { + monster_health--; + + Particle particle = new Particle(Pos); + if (monster_health <= 0) + { + Death(); + } + } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Werewolf.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Werewolf.cs index 837932f..bb6cd6f 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Werewolf.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Werewolf.cs @@ -12,24 +12,33 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public class Werewolf : CoreEnemy { - private bool isAttack; + private bool isJump; + int delay; public Werewolf(Vector2 position) : base(position) { name = "Wolf"; - monster_speed = 4; - Width = 78; - Height = 96; + monster_speed = 3; + Width = 39; + Height = 48; + delay = 10; + monster_health = 3; } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "WolfMoveRight", "WolfMoveLeft", "WolfJumpRight", "WolfJumpLeft" }, "WolfMoveRight"); public override void Update(GameTime gameTime) { - if (!isAttack) + if(!isJump ) + { + Jump(); + } + if(isOnGround) { Move(gameTime); + } + base.Update(gameTime); } @@ -41,11 +50,18 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Death() { + for (int i = 0; i < 5; i++) + { + Particle particle = new Particle(Pos); + } + AppManager.Instance.GameManager.Remove(this); } public override void Move(GameTime gameTime) { + isJump = false; + if (isGoRight) { if (GraphicsComponent.GetCurrentAnimation != "WolfMoveRight") @@ -62,23 +78,89 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters } velocity.X = -monster_speed; } - if (Pos.X >= rightBoarder) + var getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 50, 2)); + if (isGoRight) { - isGoRight = false; + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, Width+4, 2)); } - else if (Pos.X <= leftBoarder) + else { - isGoRight = true; + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - 3, (int)Pos.Y + Height / 2 - 2, Width +3, 2)); + } + + + foreach (var item in getCols) + { + if (item is MapObject) + { + isGoRight = !isGoRight; + break; + } } } public override void Attack(GameTime gameTime) { } - + public void Jump() + { + var getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 50, 2)); + if (isGoRight) + { + getCols= AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y, Width+100, Height),false); + if(getCols.Count > 0) + { + isJump = true; + if (GraphicsComponent.GetCurrentAnimation != "WolfJumpRight") + { + GraphicsComponent.StartAnimation("WolfJumpRight"); + } + velocity.Y = -7; + velocity.X = 6; + } + + } + else + { + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X-100, (int)Pos.Y, 100, Height), false); + if (getCols.Count > 0) + { + isJump = true; + if (GraphicsComponent.GetCurrentAnimation != "WolfJumpLeft") + { + GraphicsComponent.StartAnimation("WolfJumpLeft"); + } + velocity.Y = -7; + velocity.X = -6; + } + + } + + } + public override void OnCollision(GameObject gameObject) + { + /*/if (gameObject is Player) + { + if (AppManager.Instance.GameManager.players[0].IsAlive) + { + AppManager.Instance.GameManager.players[0].Death(name); + } + } + base.OnCollision(gameObject);/*/ + } public void Target() { throw new NotImplementedException(); } + public void TakeDamage() + { + monster_health--; + + Particle particle = new Particle(Pos); + if (monster_health <= 0) + { + Death(); + } + } } } diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index 9a1e46a..8bb94c1 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -201,7 +201,7 @@ namespace DangerousD.GameCore break; case GameState.Game: - GameManager.mapManager.LoadLevel("lvl"); + GameManager.mapManager.LoadLevel("map"); GameManager.FindBorders(); From 1ed1dd635f7147b56573a377bf23502c4efcdb5b Mon Sep 17 00:00:00 2001 From: Kaktus200020 Date: Fri, 18 Aug 2023 17:42:26 +0300 Subject: [PATCH 4/4] GhostAdding --- DangerousD/Content/animations/GhostAttack | 2 +- DangerousD/Content/map.tmx | 2 +- .../LivingEntities/Monsters/Ghost.cs | 57 +++++++++++++++---- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/DangerousD/Content/animations/GhostAttack b/DangerousD/Content/animations/GhostAttack index 7ada2dc..8425c93 100644 --- a/DangerousD/Content/animations/GhostAttack +++ b/DangerousD/Content/animations/GhostAttack @@ -1 +1 @@ -{"id":"GhostAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":101,"Y":503,"Width":24,"Height":31},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"0, 0"} +{"id":"GhostAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":101,"Y":503,"Width":24,"Height":31},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":50,"framesCount":2,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/map.tmx b/DangerousD/Content/map.tmx index bcc7b83..a02975a 100644 --- a/DangerousD/Content/map.tmx +++ b/DangerousD/Content/map.tmx @@ -71,7 +71,7 @@ - + diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs index 214a4c2..57ab2c4 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs @@ -17,11 +17,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters isGoRight = true; monster_speed = 3; name = "Ghost"; - Width = 48; - Height = 62; + Width = 24; + Height = 30; GraphicsComponent.StartAnimation("GhostSpawn"); - acceleration = Vector2.Zero; - + acceleration = new Vector2(0,1); + monster_health = 1; } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "GhostMoveRight", "GhostMoveLeft", "GhostSpawn", "GhostAttack" }, "GhostMoveRight"); @@ -38,13 +38,32 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Attack() { - + velocity.X = 0; + isAttack = true; + if (GraphicsComponent.GetCurrentAnimation != "GhostAttack") + { + GraphicsComponent.StartAnimation("GhostAttack"); + } + + AppManager.Instance.GameManager.players[0].Death(name); } public override void Death() { } + public override void OnCollision(GameObject gameObject) + { + if (gameObject is Player) + { + if (AppManager.Instance.GameManager.players[0].IsAlive) + { + Attack(); + + } + } + base.OnCollision(gameObject); + } public override void Move(GameTime gameTime) { @@ -64,17 +83,24 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters } velocity.X = -monster_speed; } - if (Pos.X >= rightBoarder) + var getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 50, 2)); + if (isGoRight) { - isGoRight = false; + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, Width + 4, 2)); } - else if (Pos.X <= leftBoarder) + else { - isGoRight = true; + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - 3, (int)Pos.Y + Height / 2 - 2, Width + 3, 2)); } - if (true) - { + + foreach (var item in getCols) + { + if (item is MapObject) + { + isGoRight = !isGoRight; + break; + } } } @@ -82,7 +108,16 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { } + public void TakeDamage() + { + monster_health--; + + if (monster_health <= 0) + { + Death(); + } + } public void Target() { throw new NotImplementedException();