public BaseCamera(Character followTarget) { cameraDistance = originalCameraDistance; this.followTarget = followTarget; //Perspective allows objects to looks smaller/larger depending on distance Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)GameConstants.X_RESOLUTION / (float)GameConstants.Y_RESOLUTION, GameConstants.MIN_Z, GameConstants.MAX_Z); Position = followTarget.Position + cameraDistance; }
public void setFollowTarget(Character target) { followTarget = target; //placed here in order to be after the levelbuilder variables are set in Game1 - that's the only reason xLeftWall = (GameConstants.SINGLE_CELL_SIZE * LevelBuilder.startWall) - (GameConstants.X_RESOLUTION / 2); xRightWall = (GameConstants.SINGLE_CELL_SIZE * (LevelBuilder.levelwidth - 1 + LevelBuilder.startWall)) - (GameConstants.X_RESOLUTION / 2); yFloor = (GameConstants.SINGLE_CELL_SIZE * (LevelBuilder.startFloor+1)) - (GameConstants.Y_RESOLUTION / 2); }
/// <summary> /// Set camera to follow the character, while being bounded by the level and moving only when necessary. /// </summary> /// <param name="character"></param> private void CameraFollow(Character character) { if (followTarget.Position.Y <= yFloor + bottomSideCollsion) { Position = new Vector3(Position.X, yFloor + bottomSideCollsion, Position.Z); } /* if (followTarget.Position.Y <= Position.Y) { Position = new Vector3(Position.X, followTarget.Position.Y, Position.Z); }*/ else if (followTarget.Position.Y + bottomSideCollsion >= Position.Y + topSideCollsion) { Position = new Vector3(Position.X, followTarget.Position.Y - topSideCollsion + bottomSideCollsion, Position.Z); } else { Position = new Vector3(Position.X, followTarget.Position.Y - topSideCollsion + bottomSideCollsion, Position.Z); } if (followTarget.Position.X <= xLeftWall + leftSideCollsion) { Position = new Vector3(xLeftWall + leftSideCollsion, Position.Y, Position.Z); } else if (followTarget.Position.X >= xRightWall - leftSideCollsion) { Position = new Vector3(xRightWall - leftSideCollsion, Position.Y, Position.Z); } else if (followTarget.Position.X >= xLeftWall + leftSideCollsion) { Position = new Vector3(followTarget.Position.X, Position.Y, Position.Z); } }