2019-12-17 20:37:32 +00:00
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using System;
|
2019-12-09 01:04:22 +00:00
|
|
|
|
|
2019-12-17 22:20:26 +00:00
|
|
|
|
// Good background reading, eventually:
|
|
|
|
|
// https://gamasutra.com/blogs/ItayKeren/20150511/243083/Scroll_Back_The_Theory_and_Practice_of_Cameras_in_SideScrollers.php
|
2020-01-08 22:56:57 +00:00
|
|
|
|
namespace SemiColinGames {
|
2019-12-09 01:04:22 +00:00
|
|
|
|
class Camera {
|
2019-12-17 22:53:38 +00:00
|
|
|
|
private Rectangle bbox = new Rectangle(0, 0, 1920 / 4, 1080 / 4);
|
2019-12-17 20:37:32 +00:00
|
|
|
|
|
|
|
|
|
public int Width { get => bbox.Width; }
|
|
|
|
|
public int Height { get => bbox.Height; }
|
|
|
|
|
public int Left { get => bbox.Left; }
|
|
|
|
|
|
|
|
|
|
public void Update(GameTime time, Point player) {
|
|
|
|
|
int diff = player.X - bbox.Center.X;
|
|
|
|
|
// TODO: use the actual center of the player's bbox.
|
|
|
|
|
if (Math.Abs(diff) > 16) {
|
|
|
|
|
bbox.Offset((int) (diff * 0.1), 0);
|
|
|
|
|
}
|
|
|
|
|
if (bbox.Left < 0) {
|
|
|
|
|
bbox.Offset(-bbox.Left, 0);
|
|
|
|
|
}
|
2019-12-17 23:04:06 +00:00
|
|
|
|
Debug.Toast($"p: {player.X}, {player.Y} c: {bbox.Center.X}");
|
2019-12-17 20:37:32 +00:00
|
|
|
|
}
|
2019-12-09 01:04:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|