From 0ff6c7ddea4388ed09f69d55f7df3cdfe83be0e7 Mon Sep 17 00:00:00 2001 From: Timofey06 Date: Thu, 17 Aug 2023 16:26:09 +0300 Subject: [PATCH] AddCamera --- .../GameCore/GameObjects/LivingEntities/Player/Player.cs | 6 ++++++ DangerousD/GameCore/Graphics/GraphicsComponent.cs | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index 0122b50..04eec1b 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -47,5 +47,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities { velocity.Y = -300; } + public override void Update(GameTime gameTime) + { + GraphicsComponent.CameraPosition = (_pos-new Vector2(200, 350)).ToPoint(); + velocity.X = 0.5f; + base.Update(gameTime); + } } } diff --git a/DangerousD/GameCore/Graphics/GraphicsComponent.cs b/DangerousD/GameCore/Graphics/GraphicsComponent.cs index beb6928..32851e2 100644 --- a/DangerousD/GameCore/Graphics/GraphicsComponent.cs +++ b/DangerousD/GameCore/Graphics/GraphicsComponent.cs @@ -164,8 +164,9 @@ namespace DangerousD.GameCore.Graphics scale = destinationRectangle.Width / sourceRectangle.Width; destinationRectangle.Height = (int)(sourceRectangle.Height * scale); } - - + + destinationRectangle.X -= CameraPosition.X; + destinationRectangle.Y -= CameraPosition.Y; _spriteBatch.Draw(texture, destinationRectangle, sourceRectangle, Color.White); } @@ -187,6 +188,8 @@ namespace DangerousD.GameCore.Graphics destinationRectangle.Height = (int)(sourceRectangle.Height * scale); } + destinationRectangle.X -= CameraPosition.X; + destinationRectangle.Y -= CameraPosition.Y; _spriteBatch.Draw(texture, destinationRectangle, sourceRectangle, Color.White); @@ -215,5 +218,6 @@ namespace DangerousD.GameCore.Graphics interval = lastInterval; } } + public static Point CameraPosition = new Point(0, 0); } }