From 731e69d92e8e9a84cfc5c59df363d5e0cff30b64 Mon Sep 17 00:00:00 2001 From: Kaktus200020 Date: Fri, 18 Aug 2023 03:03:11 +0300 Subject: [PATCH] tiltedSlime --- .../LivingEntities/Monsters/Slime.cs | 111 ++++++++++++++---- DangerousD/GameCore/Managers/AppManager.cs | 2 +- .../GameCore/Managers/PhysicsManager.cs | 15 +++ 3 files changed, 107 insertions(+), 21 deletions(-) diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Slime.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Slime.cs index 0e5e954..e9cba93 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Slime.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Slime.cs @@ -13,7 +13,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public class Slime : CoreEnemy { private bool isGoRight = true; - private bool isDown = false; + private bool isDown = true; int leftBorder; int rightBorder; bool isAttaking = false; @@ -38,13 +38,14 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Attack() { - + } public void Jump() { var getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle(0, 0, 100, 100)); velocity.X = 0; Height = 32; + if (isGoRight && isDown) { if (GraphicsComponent.GetCurrentAnimation != "SlimeReadyJumpLeftBottom") @@ -54,8 +55,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters delay--; if (delay <= 0) { - isJumping = true; + velocity = new Vector2(5, -3); + acceleration.Y = 0; if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpLeftBottom") { GraphicsComponent.StartAnimation("SlimeJumpLeftBottom"); @@ -71,17 +73,19 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters } else if (!isGoRight && isDown) { - if (GraphicsComponent.GetCurrentAnimation != "SlimeReadyJumpRightTop") + if (GraphicsComponent.GetCurrentAnimation != "SlimeReadyJumpRightBottom") { - GraphicsComponent.StartAnimation("SlimeReadyJumpRightTop"); + GraphicsComponent.StartAnimation("SlimeReadyJumpRightBottom"); } delay--; if (delay <= 0) { + velocity = new Vector2(-5, -3); - if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpRightTop") + acceleration.Y = 0; + if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpRightBottom") { - GraphicsComponent.StartAnimation("SlimeJumpRightTop"); + GraphicsComponent.StartAnimation("SlimeJumpRightBottom"); } getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y - 5, 48, 5)); if (getCols.Count > 0) @@ -101,17 +105,20 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters delay--; if (delay <= 0) { - isJumping = true; + velocity = new Vector2(5, 3); + acceleration.Y = 0; if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpLeftTop") { GraphicsComponent.StartAnimation("SlimeJumpLeftTop"); } - getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height, 48, 5)); + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X+1, (int)Pos.Y + Height, 46, 5)); + if (getCols.Count > 0) { isJumping = false; isDown = true; + acceleration.Y = 10; } } @@ -126,15 +133,18 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters if (delay <= 0) { velocity = new Vector2(-5, 3); + acceleration.Y = 0; if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpRightTop") { GraphicsComponent.StartAnimation("SlimeJumpRightTop"); } - getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height, 48, 5)); + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X+1, (int)Pos.Y + Height, 46, 5)); if (getCols.Count > 0) { isJumping = false; isDown = true; + acceleration.Y = 10; + } } @@ -144,8 +154,8 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters } public override void Draw(SpriteBatch spriteBatch) { - spriteBatch.Draw(debugTexture, new Rectangle((int)Pos.X, (int)Pos.Y - 5, 48, 5), Color.White); - spriteBatch.Draw(debugTexture, new Rectangle((int)Pos.X, (int)Pos.Y + Height, 48, 5), Color.White); + + base.Draw(spriteBatch); } public override void Death() @@ -197,15 +207,24 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters velocity.X = -monster_speed; } - - if (Pos.X >= rightBorder) + 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, 51, 2)); } - - else if (Pos.X <= leftBorder) + else { - isGoRight = true; + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X-3, (int)Pos.Y + Height / 2 - 2, 51, 2)); + } + + + foreach(var item in getCols) + { + if(item is MapObject) + { + isGoRight = !isGoRight; + break; + } } } public override void Update(GameTime gameTime) @@ -227,8 +246,25 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters acceleration.Y = -acceleration.Y; } } - //if (!isAttaking){ Move(gameTime); } - + Attack(); + + if (!isJumping) + { + if (isDown) + { + Jump(); + } + else if(IsInAim()) + { + Jump(); + } + else + { + Move(gameTime); + } + + } + base.Update(gameTime); } @@ -237,10 +273,45 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { } + public bool IsInAim() + { + var getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height, 48, 5)); + + if (isGoRight && !isDown) + { + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X + Width, (int)Pos.Y + Height, 200, 500), false); + if (getCols.Count > 0) + { + return true; + } + } + else if (!isGoRight && !isDown) + { + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - 200, (int)Pos.Y + Height, 200, 500), false); + if (getCols.Count > 0) + { + return true; + } + } + + return false; + + } public override void Attack(GameTime gameTime) { } + 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); + } } } diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index 5e53677..e173abb 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -202,7 +202,7 @@ namespace DangerousD.GameCore case GameState.Lobby: break; case GameState.Game: - GameManager.mapManager.LoadLevel("lvl"); + GameManager.mapManager.LoadLevel("map"); break; case GameState.Death: break; diff --git a/DangerousD/GameCore/Managers/PhysicsManager.cs b/DangerousD/GameCore/Managers/PhysicsManager.cs index 7899c98..a2fd4f2 100644 --- a/DangerousD/GameCore/Managers/PhysicsManager.cs +++ b/DangerousD/GameCore/Managers/PhysicsManager.cs @@ -234,6 +234,21 @@ namespace DangerousD.GameCore.Managers } return intersected; } + public List CheckRectangle(Rectangle rectangle, bool player) + { + var gameObjects = AppManager.Instance.GameManager.GetPlayer1; + List intersected = new List(); + + + + if (gameObjects.Rectangle.Intersects(rectangle)) + { + intersected.Add(gameObjects); + } + + + return intersected; + } public List CheckRectangle(Rectangle rectangle) { var gameObjects = AppManager.Instance.GameManager.mapObjects;