foxygit / fake-08-xbox360 Log in
commit eb8b2abf8f737c73dd400bb2202317a05dae791d
Author:     Jon Bell <jondbell@protonmail.com>
AuthorDate: Thu Apr 23 13:01:48 2020 -0600
Commit:     Jon Bell <jondbell@protonmail.com>
CommitDate: Thu Apr 23 13:01:48 2020 -0600

    Add (untested but simple) camera call
---
 source/graphics.cpp   | 12 ++++++++++++
 source/graphics.h     |  6 ++++++
 source/picoluaapi.cpp | 15 +++++++++++++++
 3 files changed, 33 insertions(+)

diff --git a/source/graphics.cpp b/source/graphics.cpp
index bd2f562..0116383 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -208,6 +208,9 @@ void Graphics::pset(short x, short y, uint8_t col){
 }

 void Graphics::_private_pset(short x, short y, uint8_t col) {
+	x = x - _gfxState_camera_x;
+	y = y - _gfxState_camera_y;
+
 	if (isOnScreen(x, y)){
 		_pico8_fb[(x * 128) + y] = col;
 	}
@@ -506,6 +509,15 @@ void Graphics::sset(uint8_t x, uint8_t y, uint8_t c){
 	this->spriteSheetData[combinedIdx] = (currentByte & ~mask) | (c & mask);
 }

+void Graphics::camera() {
+	this->camera(0, 0);
+}
+
+void Graphics::camera(short x, short y) {
+	_gfxState_camera_x = x;
+	_gfxState_camera_y = y;
+}
+
 void Graphics::flipBuffer(uint8_t* fb) {
 	short x, y;
     for(x = 0; x < 400; x++) {
diff --git a/source/graphics.h b/source/graphics.h
index 6a15061..a9407b2 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -43,6 +43,9 @@ class Graphics {
     short _gfxState_text_x;
 	short _gfxState_text_y;

+	short _gfxState_camera_x;
+	short _gfxState_camera_y;
+
 	//not actually part of graphics state memory?
 	short _gfxState_line_x;
 	short _gfxState_line_y;
@@ -150,6 +153,9 @@ class Graphics {
 	uint8_t sget(uint8_t x, uint8_t y);
 	void sset(uint8_t x, uint8_t y, uint8_t c);

+	void camera();
+	void camera(short x, short y);
+

 	void flipBuffer(uint8_t* fb);

diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index c43d951..6681f6d 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -366,6 +366,21 @@ int sset(lua_State *L) {
     return 0;
 }

+int camera(lua_State *L) {
+    short x = 0;
+    short y = 0;
+    if (lua_gettop(L) > 0) {
+        x = lua_tointeger(L,1);
+    }
+    if (lua_gettop(L) < 1) {
+        y = lua_tointeger(L,2);
+    }
+
+    _graphicsForLuaApi->camera(x, y);
+
+    return 0;
+}
+
 //Input

 //input api