diff --git a/DangerousD/Content/lvl.tmx b/DangerousD/Content/lvl.tmx index 5377e12..0f91aa8 100644 --- a/DangerousD/Content/lvl.tmx +++ b/DangerousD/Content/lvl.tmx @@ -752,7 +752,7 @@ - + diff --git a/DangerousD/GameCore/Graphics/GraphicsComponent.cs b/DangerousD/GameCore/Graphics/GraphicsComponent.cs index f218ba6..00d6298 100644 --- a/DangerousD/GameCore/Graphics/GraphicsComponent.cs +++ b/DangerousD/GameCore/Graphics/GraphicsComponent.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework; +using DangerousD.GameCore.Managers; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using System; @@ -16,7 +17,7 @@ namespace DangerousD.GameCore.Graphics private List textures; private List texturesNames; private AnimationContainer currentAnimation; - static private int scaling=3; + static private int scaling = 4; public AnimationContainer CurrentAnimation { get @@ -129,12 +130,12 @@ namespace DangerousD.GameCore.Graphics { if (!currentAnimation.IsCycle) { - if(actionOfAnimationEnd != null) + if (actionOfAnimationEnd != null) { actionOfAnimationEnd(currentAnimation.Id); - } + } currentAnimation = neitralAnimation; - + } currentFrame = 0; @@ -152,12 +153,12 @@ namespace DangerousD.GameCore.Graphics { Texture2D texture = textures[texturesNames.FindIndex(x => x == currentAnimation.TextureName)]; float scale; - if (currentAnimation.Offset.X!=0) + if (currentAnimation.Offset.X != 0) { destinationRectangle.X -= (int)currentAnimation.Offset.X; - scale=destinationRectangle.Height/sourceRectangle.Height; + scale = destinationRectangle.Height / sourceRectangle.Height; destinationRectangle.Width = (int)(sourceRectangle.Width * scale); - + } else if (currentAnimation.Offset.Y != 0) { @@ -235,9 +236,26 @@ namespace DangerousD.GameCore.Graphics } public static void SetCameraPosition(Vector2 playerPosition) { - CameraPosition=(playerPosition).ToPoint(); + CameraPosition = (playerPosition).ToPoint(); CameraPosition.X -= 300; CameraPosition.Y -= 200; + if (CameraPosition.X < AppManager.Instance.GameManager.CameraBorder.X) + { + CameraPosition.X = (int)AppManager.Instance.GameManager.CameraBorder.X; + } + if (CameraPosition.X > AppManager.Instance.GameManager.CameraBorder.Y - 460) + { + CameraPosition.X = (int)AppManager.Instance.GameManager.CameraBorder.Y - 460; + } + if (CameraPosition.Y < AppManager.Instance.GameManager.CameraBorder.Z) + { + CameraPosition.Y = (int)AppManager.Instance.GameManager.CameraBorder.Z; + } + if (CameraPosition.Y > AppManager.Instance.GameManager.CameraBorder.W - 470) + { + CameraPosition.Y = (int)AppManager.Instance.GameManager.CameraBorder.W - 470; + } + AppManager.Instance.DebugHUD.Set("CameraPosition", $"{CameraPosition.X}, {CameraPosition.Y}"); } public static Point CameraPosition = new Point(-700, 300); } diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index 6d57340..33327c7 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -206,6 +206,7 @@ namespace DangerousD.GameCore break; case GameState.Game: GameManager.mapManager.LoadLevel("lvl"); + GameManager.FindBorders(); break; case GameState.Death: break; @@ -262,6 +263,7 @@ namespace DangerousD.GameCore case NetworkTaskOperationEnum.AddConnectedPlayer: Player remoteConnectedPlayer = new Player(networkTask.position, true); remoteConnectedPlayer.id = networkTask.objId; + break; default: break; diff --git a/DangerousD/GameCore/Managers/GameManager.cs b/DangerousD/GameCore/Managers/GameManager.cs index 6f4cf57..53ffa61 100644 --- a/DangerousD/GameCore/Managers/GameManager.cs +++ b/DangerousD/GameCore/Managers/GameManager.cs @@ -28,7 +28,7 @@ namespace DangerousD.GameCore public PhysicsManager physicsManager; public List players; public List otherObjects = new(); - + public Vector4 CameraBorder; public Player GetPlayer1 { get; private set; } public GameManager() { @@ -42,6 +42,7 @@ namespace DangerousD.GameCore players = new List(); mapManager = new MapManager(1); physicsManager = new PhysicsManager(); + CameraBorder = Vector4.Zero; } @@ -148,6 +149,8 @@ namespace DangerousD.GameCore } } else + + { for (int i = 0; i < livingEntitiesWithoutPlayers.Count; i++) { @@ -160,5 +163,27 @@ namespace DangerousD.GameCore physicsManager.UpdateCollisions(entities, livingEntities, mapObjects, players, gameTime); } + public void FindBorders() + { + foreach (var item in GetAllGameObjects) + { + if (item.Pos.X CameraBorder.Y) + { + CameraBorder.Y = item.Pos.X; + } + if (item.Pos.Y < CameraBorder.Z) + { + CameraBorder.Z = item.Pos.X; + } + if (item.Pos.Y > CameraBorder.W) + { + CameraBorder.W = item.Pos.X; + } + } + } } } \ No newline at end of file