From e7c375d9e7adbe9146dc40b08e55f7fd98b1a2ee Mon Sep 17 00:00:00 2001 From: Ivan Filipenkov Date: Fri, 18 Aug 2023 02:27:44 +0300 Subject: [PATCH] ladders somewhat work --- DangerousD/GameCore/GUI/DebugHUD.cs | 24 ++++++++++++++++++- .../LivingEntities/Player/Player.cs | 11 +++++++-- .../GameCore/Managers/PhysicsManager.cs | 5 +++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/DangerousD/GameCore/GUI/DebugHUD.cs b/DangerousD/GameCore/GUI/DebugHUD.cs index b56d90a..c4e3e55 100644 --- a/DangerousD/GameCore/GUI/DebugHUD.cs +++ b/DangerousD/GameCore/GUI/DebugHUD.cs @@ -11,6 +11,7 @@ namespace DangerousD.GameCore.GUI { private SpriteFont _spriteFont; private Dictionary _text = new(); + private List _log = new(); public void Initialize() { @@ -27,10 +28,11 @@ namespace DangerousD.GameCore.GUI public void Draw(SpriteBatch spriteBatch) { + var keysString = Join("\n", _text.Select(el => el.Key + ": " + el.Value).ToList()); spriteBatch.Begin(); spriteBatch.DrawString( _spriteFont, - Join("\n", _text.Select(el => el.Key + ": " + el.Value).ToList()), + keysString, new Vector2(10, 10), Color.Cyan, 0, @@ -39,6 +41,17 @@ namespace DangerousD.GameCore.GUI SpriteEffects.None, 0 ); + spriteBatch.DrawString( + _spriteFont, + Join("\n", _log), + new Vector2(10, 10 + _spriteFont.MeasureString(keysString).Y), + Color.Green, + 0, + Vector2.Zero, + 1, + SpriteEffects.None, + 0 + ); spriteBatch.End(); } @@ -46,5 +59,14 @@ namespace DangerousD.GameCore.GUI { _text[key] = value; } + + public void Log(string value) + { + _log.Add(value); + if (_log.Count > 30) + { + _log.RemoveAt(0); + } + } } } \ No newline at end of file diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index 9358d38..62bad69 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -29,6 +29,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities private bool isShooting = false; public GameObject objectAttack; private int bullets; + public bool FallingThroughPlatform = false; public Player(Vector2 position) : base(position) { @@ -153,6 +154,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities } public override void Update(GameTime gameTime) { + if (isOnGround && FallingThroughPlatform) + { + FallingThroughPlatform = false; + AppManager.Instance.DebugHUD.Log("not falling"); + } GraphicsComponent.SetCameraPosition(Pos); if (!isAttacked) { @@ -214,8 +220,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities } public void MoveDown() { - // ПОЧЕМУ - velocity.Y = -11; + FallingThroughPlatform = true; + isOnGround = false; + AppManager.Instance.DebugHUD.Log("FallingThroughPlatform"); } } diff --git a/DangerousD/GameCore/Managers/PhysicsManager.cs b/DangerousD/GameCore/Managers/PhysicsManager.cs index e41b848..dee4c27 100644 --- a/DangerousD/GameCore/Managers/PhysicsManager.cs +++ b/DangerousD/GameCore/Managers/PhysicsManager.cs @@ -77,6 +77,7 @@ namespace DangerousD.GameCore.Managers if (currentEntity is Player) { AppManager.Instance.DebugHUD.Set("velocity", currentEntity.velocity.ToString()); + AppManager.Instance.DebugHUD.Set("falling", (currentEntity as Player).FallingThroughPlatform.ToString()); AppManager.Instance.DebugHUD.Set("intersects y", ""); } foreach (var mapObject in mapObjects) @@ -107,7 +108,7 @@ namespace DangerousD.GameCore.Managers { foreach (var player in players) { - if (player.velocity.Y <= 0) + if (player.velocity.Y <= 0 || player.FallingThroughPlatform) { continue; } @@ -129,6 +130,8 @@ namespace DangerousD.GameCore.Managers } if (collidedY) { + // костыль потому что в CheckCollisionsLE_MO он спускается + newRect.Y -= (int)Math.Ceiling(player.velocity.Y); player.isOnGround = true; player.velocity.Y = 0; }