foxygit / fake-08-xbox360 Log in
commit a0e2b7dac8abfe081315557e5f56450f078e009b
Author:     Jon Bell <jondbell@protonmail.com>
AuthorDate: Wed Apr 8 11:16:31 2020 -0600
Commit:     Jon Bell <jondbell@protonmail.com>
CommitDate: Wed Apr 8 11:16:31 2020 -0600

    implement unfilled rect
---
 source/fakecart.c |  5 +----
 source/graphics.c | 19 +++++++++++--------
 source/graphics.h |  4 ++--
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/source/fakecart.c b/source/fakecart.c
index fe29565..64a1181 100644
--- a/source/fakecart.c
+++ b/source/fakecart.c
@@ -25,16 +25,13 @@ void _draw() {

     cls();

-    rect(10, 10, 50, 50, 2);
-
-
     rectfill(0, 0, 127, 127, 10);

     rectfill(50, -1, 60, 10, 11);

     rectfill((short)r1x0, (short)r1y0, (short)r1x1, (short)r1y1, r1c);

-    rectfill((short)r2x1, (short)r2y1, (short)r2x0, (short)r2y0, r2c);
+    rect((short)r2x1, (short)r2y1, (short)r2x0, (short)r2y0, r2c);
 }

 void _update() {
diff --git a/source/graphics.c b/source/graphics.c
index a0c70a6..7a36303 100644
--- a/source/graphics.c
+++ b/source/graphics.c
@@ -62,15 +62,18 @@ void cls() {
 	memset(_pico8_fb, 0, sizeof(_pico8_fb));
 }

-void rect(short x, short y, short x1, short y1, uint16_t col) {
-	/*
-	char w = x1 - x;
-	char h = y1 - y;
-
-	char currentX = 0;
-	char currentY = 0;
-	*/
+void rect(short x1, short y1, short x2, short y2, uint16_t col) {
+	sortcoords(&x1, &x2);
+	sortcoords(&y1, &y2);

+	for (int i = x1; i <= x2; i++) {
+		for (int j = y1; j <= y2; j++) {
+			if (i >= 0 && i < 127 && j >= 0 && j < 127 &&
+				(i == x1 || i == x2 || j == y1 || j == y2) ) {
+				_pico8_fb[(i * 128) + j] = col;
+			}
+		}
+	}

 }

diff --git a/source/graphics.h b/source/graphics.h
index 9e8e6ef..a83632a 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -30,7 +30,7 @@ typedef struct {

 void cls();

-void rect(short x0, short y0, short x1, short y1, uint16_t col);
-void rectfill(short x, short y, short x1, short y1, uint16_t col);
+void rect(short x1, short y1, short x2, short y2, uint16_t col);
+void rectfill(short x1, short y1, short x2, short y2, uint16_t col);

 void flipBuffer(u8* fb);
\ No newline at end of file