From dff21f0484f6ae066a581cc89db8fb99fef914eb Mon Sep 17 00:00:00 2001 From: Kaktus200020 Date: Wed, 16 Aug 2023 17:10:50 +0300 Subject: [PATCH 1/4] CreateRayCast --- DangerousD/Content/Content.mgcb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/DangerousD/Content/Content.mgcb b/DangerousD/Content/Content.mgcb index b5e65dd..8d94070 100644 --- a/DangerousD/Content/Content.mgcb +++ b/DangerousD/Content/Content.mgcb @@ -13,6 +13,18 @@ #---------------------------------- Content ---------------------------------# +#begin animation1.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:animation1.png + #begin File.spritefont /importer:FontDescriptionImporter /processor:FontDescriptionProcessor From 6dab4794b0c392d7f9e6cb67e5aebdd5a02a380a Mon Sep 17 00:00:00 2001 From: Lev Date: Wed, 16 Aug 2023 17:58:27 +0300 Subject: [PATCH 2/4] =?UTF-8?q?RayCast=20=D1=81=20=D0=BE=D0=B4=D0=BD=D0=BE?= =?UTF-8?q?=D0=B9=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GameCore/Managers/PhysicsManager.cs | 59 ++++++++++++++----- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/DangerousD/GameCore/Managers/PhysicsManager.cs b/DangerousD/GameCore/Managers/PhysicsManager.cs index 8fc47c0..7ae99f9 100644 --- a/DangerousD/GameCore/Managers/PhysicsManager.cs +++ b/DangerousD/GameCore/Managers/PhysicsManager.cs @@ -144,11 +144,30 @@ namespace DangerousD.GameCore.Managers { rectangle.X = (int)(entity2.Pos.X + (i / length) * distance.X); rectangle.Y = (int)(entity2.Pos.Y + (i / length) * distance.Y); + } + + for (int i = 0; i < AppManager.Instance.GameManager.entities.Count; i++) + { + if (AppManager.Instance.GameManager.entities[i].Rectangle.Intersects(rectangle)) + { + return AppManager.Instance.GameManager.entities[i]; + } + } + for (int i = 0; i < AppManager.Instance.GameManager.mapObjects.Count; i++) + { + if (AppManager.Instance.GameManager.mapObjects[i].Rectangle.Intersects(rectangle)) + { + return AppManager.Instance.GameManager.mapObjects[i]; + } + } - //if (rectangle.Intersects(GameManager.Rectangle)) - //{ - // return game - //} + + for (int i = 0; i < AppManager.Instance.GameManager.livingEntities.Count; i++) + { + if (AppManager.Instance.GameManager.livingEntities[i].Rectangle.Intersects(rectangle)) + { + return AppManager.Instance.GameManager.livingEntities[i]; + } } return gameObject; } @@ -156,23 +175,35 @@ namespace DangerousD.GameCore.Managers { Rectangle rectangle; Vector2 direction = entity1.Pos - targetCast; - rectangle = new Rectangle((int)entity1.Pos.X, (int)entity1.Pos.Y, 1, 1); - GameObject gameObject = null; + rectangle = new Rectangle((int)targetCast.X, (int)targetCast.Y, 1, 1); double k = direction.Length(); for (int i = 0; i < k; i++) { - rectangle.X = (int)(entity1.Pos.X + (i / k) * direction.X); - rectangle.Y = (int)(entity1.Pos.Y + (i / k) * direction.X); - if (gameObject != null) + rectangle.X = (int)(targetCast.X + (i / k) * direction.X); + rectangle.Y = (int)(targetCast.Y + (i / k) * direction.X); + } + for (int i = 0; i < AppManager.Instance.GameManager.entities.Count; i++) + { + if (AppManager.Instance.GameManager.entities[i].Rectangle.Intersects(rectangle)) { - break; - return gameObject; + return AppManager.Instance.GameManager.entities[i]; + } + } + for (int i = 0; i < AppManager.Instance.GameManager.mapObjects.Count; i++) + { + if (AppManager.Instance.GameManager.mapObjects[i].Rectangle.Intersects(rectangle)) + { + return AppManager.Instance.GameManager.mapObjects[i]; + } + } + for (int i = 0; i < AppManager.Instance.GameManager.livingEntities.Count; i++) + { + if (AppManager.Instance.GameManager.livingEntities[i].Rectangle.Intersects(rectangle)) + { + return AppManager.Instance.GameManager.livingEntities[i]; } - } - - return null; } } From 469050e4cd5f8e2dbff49bb0262efc2ae9c74994 Mon Sep 17 00:00:00 2001 From: Timofey06 Date: Wed, 16 Aug 2023 19:17:10 +0300 Subject: [PATCH 3/4] NewPeregruzkaDlyDraw --- .../GameCore/Graphics/GraphicsComponent.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/DangerousD/GameCore/Graphics/GraphicsComponent.cs b/DangerousD/GameCore/Graphics/GraphicsComponent.cs index c5834ab..27c66a0 100644 --- a/DangerousD/GameCore/Graphics/GraphicsComponent.cs +++ b/DangerousD/GameCore/Graphics/GraphicsComponent.cs @@ -146,6 +146,28 @@ namespace DangerousD.GameCore.Graphics } + _spriteBatch.Draw(texture, + destinationRectangle, sourceRectangle, Color.White); + } + public void DrawAnimation(Rectangle destinationRectangle, SpriteBatch _spriteBatch, Rectangle sourceRectangle) + { + Texture2D texture = textures[texturesNames.FindIndex(x => x == currentAnimation.TextureName)]; + float scale; + if (currentAnimation.Offset.X != 0) + { + destinationRectangle.X -= (int)currentAnimation.Offset.X; + scale = destinationRectangle.Height / sourceRectangle.Height; + destinationRectangle.Width = (int)(sourceRectangle.Width * scale); + + } + else if (currentAnimation.Offset.Y != 0) + { + destinationRectangle.Y -= (int)currentAnimation.Offset.Y; + scale = destinationRectangle.Width / sourceRectangle.Width; + destinationRectangle.Height = (int)(sourceRectangle.Height * scale); + } + + _spriteBatch.Draw(texture, destinationRectangle, sourceRectangle, Color.White); } From 48106c2bdfb736f7e903e2c7a73c0de14221ba7b Mon Sep 17 00:00:00 2001 From: Timofey06 Date: Wed, 16 Aug 2023 19:34:11 +0300 Subject: [PATCH 4/4] AddDelegateOfAnimetionsEnd --- DangerousD/GameCore/Graphics/GraphicsComponent.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/DangerousD/GameCore/Graphics/GraphicsComponent.cs b/DangerousD/GameCore/Graphics/GraphicsComponent.cs index 27c66a0..024a3d2 100644 --- a/DangerousD/GameCore/Graphics/GraphicsComponent.cs +++ b/DangerousD/GameCore/Graphics/GraphicsComponent.cs @@ -10,6 +10,7 @@ namespace DangerousD.GameCore.Graphics { public class GraphicsComponent { + public Action actionOfAnimationEnd; private List animations; private List textures; private List texturesNames; @@ -115,9 +116,11 @@ namespace DangerousD.GameCore.Graphics if (!currentAnimation.IsCycle) { currentAnimation = neitralAnimation; + actionOfAnimationEnd(); } currentFrame = 0; + } buildSourceRectangle();