From 5fdc34c61047555753e29c6317754d1cd55ba40a Mon Sep 17 00:00:00 2001 From: Matt Thorson Date: Sun, 14 Jun 2020 17:56:16 -0700 Subject: [PATCH] Camera stack --- src/Core/Game.bf | 4 ++++ src/Static/Console.bf | 1 - src/Static/Draw.bf | 20 +++++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Core/Game.bf b/src/Core/Game.bf index 3029ca3..58367b7 100644 --- a/src/Core/Game.bf +++ b/src/Core/Game.bf @@ -205,7 +205,11 @@ namespace Strawberry public virtual void Draw() { if (Scene != null) + { + Draw.PushCamera(Scene.Camera.Round()); Scene.Draw(); + Draw.PopCamera(); + } if (Console.Enabled) Strawberry.Console.Draw(); diff --git a/src/Static/Console.bf b/src/Static/Console.bf index 6ff2259..4fb2448 100644 --- a/src/Static/Console.bf +++ b/src/Static/Console.bf @@ -12,7 +12,6 @@ namespace Strawberry static public void Draw() { - Calc.Log(); Draw.Rect(0, 0, Game.Width, Game.Height, .Black * 0.4f); } } diff --git a/src/Static/Draw.bf b/src/Static/Draw.bf index a106400..33e2176 100644 --- a/src/Static/Draw.bf +++ b/src/Static/Draw.bf @@ -1,11 +1,29 @@ using SDL2; using System; +using System.Collections; namespace Strawberry { 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 cameraStack = new List() ~ 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) {