Camera stack

This commit is contained in:
Matt Thorson 2020-06-14 17:56:16 -07:00
parent 272ec43e69
commit 5fdc34c610
3 changed files with 23 additions and 2 deletions

View File

@ -205,7 +205,11 @@ namespace Strawberry
public virtual void Draw() public virtual void Draw()
{ {
if (Scene != null) if (Scene != null)
{
Draw.PushCamera(Scene.Camera.Round());
Scene.Draw(); Scene.Draw();
Draw.PopCamera();
}
if (Console.Enabled) if (Console.Enabled)
Strawberry.Console.Draw(); Strawberry.Console.Draw();

View File

@ -12,7 +12,6 @@ namespace Strawberry
static public void Draw() static public void Draw()
{ {
Calc.Log();
Draw.Rect(0, 0, Game.Width, Game.Height, .Black * 0.4f); Draw.Rect(0, 0, Game.Width, Game.Height, .Black * 0.4f);
} }
} }

View File

@ -1,11 +1,29 @@
using SDL2; using SDL2;
using System; using System;
using System.Collections;
namespace Strawberry namespace Strawberry
{ {
static public class Draw static public class Draw
{ {
static public Point Camera => Game.Scene != null ? Game.Scene.Camera.Round() : Point.Zero; static public Point Camera => cameraStack.Count > 0 ? cameraStack.Back : Point.Zero;
static private List<Point> cameraStack = new List<Point>() ~ delete _;
static public void PushCamera(Point camera, bool relative = true)
{
if (relative)
cameraStack.Add(Camera + camera);
else
cameraStack.Add(camera);
}
static public void PopCamera()
{
if (cameraStack.Count == 0)
Runtime.FatalError("Cannot Pop empty Camera Stack!");
cameraStack.PopBack();
}
static public void Rect(int x, int y, int w, int h, Color color) static public void Rect(int x, int y, int w, int h, Color color)
{ {