A WIP automation game
1using System.Numerics;
2using Raylib_cs;
3
4namespace Electropunk.World;
5
6public class View
7{
8 /* Never ever change this. This is the size that we render tiles at. */
9 public const int TileSize = 16;
10
11 public Vector2 GoalTarget = Vector2.Zero;
12 public float GoalZoom = 2f;
13
14 public Camera2D Camera = new(new Vector2(400, 300), new Vector2(0, 0), 0f, 2f);
15
16 public void Update()
17 {
18 if (Raylib.IsWindowResized())
19 Camera.Offset = Raylib.GetScreenCenter();
20
21 Camera.Target = Vector2.Lerp(Camera.Target, GoalTarget, 0.20f);
22 Camera.Zoom = Vector2.Lerp(new(0, Camera.Zoom), new(0, GoalZoom), 0.20f).Y; /* cursed? yes. very. */
23 }
24
25 public (Vector2, Vector2) GetWorldBounds()
26 {
27 Vector2 first = Raylib.GetScreenToWorld2D(new(0, 0), Camera);
28 Vector2 second = Raylib.GetScreenToWorld2D(new(Raylib.GetScreenWidth(), Raylib.GetScreenHeight()), Camera);
29 return (first, second);
30 }
31
32 public Rectangle GetWorldBoundsRec()
33 {
34 Vector2 first = Raylib.GetScreenToWorld2D(new(0, 0), Camera);
35 Vector2 second = Raylib.GetScreenToWorld2D(new(Raylib.GetScreenWidth(), Raylib.GetScreenHeight()), Camera);
36 return new(first, second - first);
37 }
38
39 public static Vector2 LevelPosToWorldPos(int x, int y) => new(x * TileSize, y * TileSize);
40}