foxygit / fake-08-xbox360 Log in
commit 655515cb506d4e1ef3eb1e5a0bf62f2c39c145c3
Author:     Jon Bell <jondbell@protonmail.com>
AuthorDate: Wed Apr 8 08:05:42 2020 -0600
Commit:     Jon Bell <jondbell@protonmail.com>
CommitDate: Wed Apr 8 08:05:42 2020 -0600

    add movement test to fakecart
---
 source/fakecart.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
 source/graphics.c |  6 ++----
 source/graphics.h |  2 +-
 source/main.c     |  6 ++++--
 4 files changed, 49 insertions(+), 9 deletions(-)

diff --git a/source/fakecart.c b/source/fakecart.c
index 0207861..51d616b 100644
--- a/source/fakecart.c
+++ b/source/fakecart.c
@@ -3,15 +3,55 @@
 #include "graphics.h"


+float r1x0 = 10;
+float r1y0 = 10;
+float r1x1 = 50;
+float r1y1 = 50;
+float r1c = 2;
+
+float r2x0 = 60;
+float r2y0 = 60;
+float r2x1 = 100;
+float r2y1 = 100;
+float r2c = 3;
+
+float r1dx = .5;
+float r1dy = 2;
+
+float r2dx = 2;
+float r2dy = 2;

 void _draw() {
+
+    cls();
+
     rect(10, 10, 50, 50, 2);

-    rectfill(10, 10, 50, 50, 2);
+    rectfill((int)r1x0, (int)r1y0, (int)r1x1, (int)r1y1, r1c);

-    rectfill(60, 60, 100, 100, 3);
+    rectfill((int)r2x0, (int)r2y0, (int)r2x1, (int)r2y1, r2c);
 }

 void _update() {
+    if (r1x0 < 0 || r1x1 > 128){
+        r1dx = -1 * r1dx;
+    }
+
+    if (r1y0 < 0 || r1y1 > 128){
+        r1dy = -1 * r1dy;
+    }
+
+    if (r2x0 < 0 || r2x1 > 128){
+        r2dx = -1 * r2dx;
+    }
+
+    if (r2y0 < 0 || r2y1 > 128){
+        r2dy = -1 * r2dy;
+    }
+
+    r1x0 = r1dx + r1x0;
+    r1x1 = r1dx + r1x1;
+    r1y0 = r1dy + r1y0;
+    r1y1 = r1dy + r1y1;

 }
\ No newline at end of file
diff --git a/source/graphics.c b/source/graphics.c
index d0c1ff2..cb67c9f 100644
--- a/source/graphics.c
+++ b/source/graphics.c
@@ -43,10 +43,8 @@ const Color PaletteColors[] = {

 uint16_t _pico8_fb[128*128];

-void clearscreen(u8* fb, int time) {
-
-	memset(fb, BgGray.Red, 240*400*3);
-
+void cls() {
+	memset(_pico8_fb, 0, sizeof(_pico8_fb));
 }

 void rect(char x, char y, char x1, char y1, uint16_t col) {
diff --git a/source/graphics.h b/source/graphics.h
index 9ea61a7..6be0e66 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -28,7 +28,7 @@ typedef struct {
 } Color;


-void clearscreen(u8* fb, int time);
+void cls();

 void rect(char x0, char y0, char x1, char y1, uint16_t col);
 void rectfill(char x, char y, char x1, char y1, uint16_t col);
diff --git a/source/main.c b/source/main.c
index d428c92..3955bb2 100644
--- a/source/main.c
+++ b/source/main.c
@@ -37,11 +37,13 @@ int main(int argc, char **argv)
 		_update();

 		u8* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
+		//clear whole framebuffer
+		memset(fb, 128, 240*400*3);

-    	clearscreen(fb, frames);
-
+		//cart draw
 		_draw();

+		//send pico 8 screen to framebuffer
 		flipBuffer(fb);

     	frames++;