2020-01-18 03:41:45 +00:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
// Good background reading, eventually:
|
|
|
|
// https://gamasutra.com/blogs/ItayKeren/20150511/243083/Scroll_Back_The_Theory_and_Practice_of_Cameras_in_SideScrollers.php
|
|
|
|
namespace SemiColinGames {
|
|
|
|
class Camera {
|
|
|
|
private Rectangle bbox = new Rectangle(0, 0, 1920 / 4, 1080 / 4);
|
|
|
|
|
|
|
|
public int Width { get => bbox.Width; }
|
|
|
|
public int Height { get => bbox.Height; }
|
|
|
|
public int Left { get => bbox.Left; }
|
2020-02-04 22:37:42 +00:00
|
|
|
public int Top { get => bbox.Top; }
|
2020-01-18 03:41:45 +00:00
|
|
|
|
2020-01-29 23:01:41 +00:00
|
|
|
public void Update(Point player, int worldWidth) {
|
2020-01-18 03:41:45 +00:00
|
|
|
int diff = player.X - bbox.Center.X;
|
|
|
|
if (Math.Abs(diff) > 16) {
|
|
|
|
bbox.Offset((int) (diff * 0.1), 0);
|
|
|
|
}
|
|
|
|
if (bbox.Left < 0) {
|
|
|
|
bbox.Offset(-bbox.Left, 0);
|
|
|
|
}
|
2020-01-29 23:01:41 +00:00
|
|
|
if (bbox.Right > worldWidth) {
|
|
|
|
bbox.Offset(worldWidth - bbox.Right, 0);
|
|
|
|
}
|
2020-01-29 21:32:15 +00:00
|
|
|
Debug.AddToast($"p: {player.X}, {player.Y} c: {bbox.Center.X}");
|
2020-01-18 03:41:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|