Merge branch 'Camera'
This commit is contained in:
commit
0ff736e29d
4 changed files with 56 additions and 11 deletions
|
@ -752,7 +752,7 @@
|
||||||
</object>
|
</object>
|
||||||
</objectgroup>
|
</objectgroup>
|
||||||
<objectgroup id="10" name="Player" class="LivingEntities.Player">
|
<objectgroup id="10" name="Player" class="LivingEntities.Player">
|
||||||
<object id="47" x="-525" y="461.333">
|
<object id="47" x="-500" y="461.333">
|
||||||
<point/>
|
<point/>
|
||||||
</object>
|
</object>
|
||||||
</objectgroup>
|
</objectgroup>
|
||||||
|
|
|
@ -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.Content;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System;
|
using System;
|
||||||
|
@ -16,7 +17,7 @@ namespace DangerousD.GameCore.Graphics
|
||||||
private List<Texture2D> textures;
|
private List<Texture2D> textures;
|
||||||
private List<string> texturesNames;
|
private List<string> texturesNames;
|
||||||
private AnimationContainer currentAnimation;
|
private AnimationContainer currentAnimation;
|
||||||
static private int scaling=3;
|
static private int scaling = 4;
|
||||||
public AnimationContainer CurrentAnimation
|
public AnimationContainer CurrentAnimation
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -129,10 +130,10 @@ namespace DangerousD.GameCore.Graphics
|
||||||
{
|
{
|
||||||
if (!currentAnimation.IsCycle)
|
if (!currentAnimation.IsCycle)
|
||||||
{
|
{
|
||||||
if(actionOfAnimationEnd != null)
|
if (actionOfAnimationEnd != null)
|
||||||
{
|
{
|
||||||
actionOfAnimationEnd(currentAnimation.Id);
|
actionOfAnimationEnd(currentAnimation.Id);
|
||||||
}
|
}
|
||||||
currentAnimation = neitralAnimation;
|
currentAnimation = neitralAnimation;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -152,10 +153,10 @@ namespace DangerousD.GameCore.Graphics
|
||||||
{
|
{
|
||||||
Texture2D texture = textures[texturesNames.FindIndex(x => x == currentAnimation.TextureName)];
|
Texture2D texture = textures[texturesNames.FindIndex(x => x == currentAnimation.TextureName)];
|
||||||
float scale;
|
float scale;
|
||||||
if (currentAnimation.Offset.X!=0)
|
if (currentAnimation.Offset.X != 0)
|
||||||
{
|
{
|
||||||
destinationRectangle.X -= (int)currentAnimation.Offset.X;
|
destinationRectangle.X -= (int)currentAnimation.Offset.X;
|
||||||
scale=destinationRectangle.Height/sourceRectangle.Height;
|
scale = destinationRectangle.Height / sourceRectangle.Height;
|
||||||
destinationRectangle.Width = (int)(sourceRectangle.Width * scale);
|
destinationRectangle.Width = (int)(sourceRectangle.Width * scale);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -235,9 +236,26 @@ namespace DangerousD.GameCore.Graphics
|
||||||
}
|
}
|
||||||
public static void SetCameraPosition(Vector2 playerPosition)
|
public static void SetCameraPosition(Vector2 playerPosition)
|
||||||
{
|
{
|
||||||
CameraPosition=(playerPosition).ToPoint();
|
CameraPosition = (playerPosition).ToPoint();
|
||||||
CameraPosition.X -= 300;
|
CameraPosition.X -= 300;
|
||||||
CameraPosition.Y -= 200;
|
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);
|
public static Point CameraPosition = new Point(-700, 300);
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,6 +206,7 @@ namespace DangerousD.GameCore
|
||||||
break;
|
break;
|
||||||
case GameState.Game:
|
case GameState.Game:
|
||||||
GameManager.mapManager.LoadLevel("lvl");
|
GameManager.mapManager.LoadLevel("lvl");
|
||||||
|
GameManager.FindBorders();
|
||||||
break;
|
break;
|
||||||
case GameState.Death:
|
case GameState.Death:
|
||||||
break;
|
break;
|
||||||
|
@ -262,6 +263,7 @@ namespace DangerousD.GameCore
|
||||||
case NetworkTaskOperationEnum.AddConnectedPlayer:
|
case NetworkTaskOperationEnum.AddConnectedPlayer:
|
||||||
Player remoteConnectedPlayer = new Player(networkTask.position, true);
|
Player remoteConnectedPlayer = new Player(networkTask.position, true);
|
||||||
remoteConnectedPlayer.id = networkTask.objId;
|
remoteConnectedPlayer.id = networkTask.objId;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace DangerousD.GameCore
|
||||||
public PhysicsManager physicsManager;
|
public PhysicsManager physicsManager;
|
||||||
public List<Player> players;
|
public List<Player> players;
|
||||||
public List<GameObject> otherObjects = new();
|
public List<GameObject> otherObjects = new();
|
||||||
|
public Vector4 CameraBorder;
|
||||||
public Player GetPlayer1 { get; private set; }
|
public Player GetPlayer1 { get; private set; }
|
||||||
public GameManager()
|
public GameManager()
|
||||||
{
|
{
|
||||||
|
@ -42,6 +42,7 @@ namespace DangerousD.GameCore
|
||||||
players = new List<Player>();
|
players = new List<Player>();
|
||||||
mapManager = new MapManager(1);
|
mapManager = new MapManager(1);
|
||||||
physicsManager = new PhysicsManager();
|
physicsManager = new PhysicsManager();
|
||||||
|
CameraBorder = Vector4.Zero;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,6 +149,8 @@ namespace DangerousD.GameCore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < livingEntitiesWithoutPlayers.Count; i++)
|
for (int i = 0; i < livingEntitiesWithoutPlayers.Count; i++)
|
||||||
{
|
{
|
||||||
|
@ -160,5 +163,27 @@ namespace DangerousD.GameCore
|
||||||
|
|
||||||
physicsManager.UpdateCollisions(entities, livingEntities, mapObjects, players, gameTime);
|
physicsManager.UpdateCollisions(entities, livingEntities, mapObjects, players, gameTime);
|
||||||
}
|
}
|
||||||
|
public void FindBorders()
|
||||||
|
{
|
||||||
|
foreach (var item in GetAllGameObjects)
|
||||||
|
{
|
||||||
|
if (item.Pos.X<CameraBorder.X)
|
||||||
|
{
|
||||||
|
CameraBorder.X = item.Pos.X;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue