A stealth-based 2D platformer where you don't have to kill anyone unless you want to. https://www.semicolin.games
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.2 KiB

  1. using Microsoft.Xna.Framework;
  2. using System;
  3. // Good background reading, eventually:
  4. // https://gamasutra.com/blogs/ItayKeren/20150511/243083/Scroll_Back_The_Theory_and_Practice_of_Cameras_in_SideScrollers.php
  5. namespace SemiColinGames {
  6. public class Camera {
  7. // Screen size in pixels is 1920x1080 divided by 4.
  8. private Rectangle bbox = new Rectangle(0, 0, 480, 270);
  9. public int Width { get => bbox.Width; }
  10. public int Height { get => bbox.Height; }
  11. public int Left { get => bbox.Left; }
  12. public int Top { get => bbox.Top; }
  13. public Point HalfSize { get => new Point(Width / 2, Height / 2); }
  14. public Matrix Projection {
  15. get => Matrix.CreateOrthographicOffCenter(Left, Left + Width, Height, 0, -1, 1);
  16. }
  17. public void Update(Point player, int worldWidth) {
  18. int diff = player.X - bbox.Center.X;
  19. if (Math.Abs(diff) > 16) {
  20. bbox.Offset((int) (diff * 0.1), 0);
  21. }
  22. if (bbox.Left < 0) {
  23. bbox.Offset(-bbox.Left, 0);
  24. }
  25. if (bbox.Right > worldWidth) {
  26. bbox.Offset(worldWidth - bbox.Right, 0);
  27. }
  28. Debug.AddToast($"p: {player.X}, {player.Y} c: {bbox.Center.X}");
  29. }
  30. }
  31. }