commit 1fd132a2b81ad5db91801c819193ffd495fbfb96
Author: Jon Bell <jondbell@protonmail.com>
AuthorDate: Wed Apr 8 11:04:28 2020 -0600
Commit: Jon Bell <jondbell@protonmail.com>
CommitDate: Wed Apr 8 11:04:28 2020 -0600
add sortcoords helper method
---
source/fakecart.c | 7 +++++--
source/graphics.c | 41 ++++++++++++++++++++++-------------------
source/main.c | 5 +++--
3 files changed, 30 insertions(+), 23 deletions(-)
diff --git a/source/fakecart.c b/source/fakecart.c
index 51d616b..cb68ad7 100644
--- a/source/fakecart.c
+++ b/source/fakecart.c
@@ -22,14 +22,17 @@ float r2dx = 2;
float r2dy = 2;
void _draw() {
-
+
cls();
rect(10, 10, 50, 50, 2);
+
+ rectfill(0, 0, 127, 127, 10);
+
rectfill((int)r1x0, (int)r1y0, (int)r1x1, (int)r1y1, r1c);
- rectfill((int)r2x0, (int)r2y0, (int)r2x1, (int)r2y1, r2c);
+ rectfill((int)r2x1, (int)r2y1, (int)r2x0, (int)r2y0, r2c);
}
void _update() {
diff --git a/source/graphics.c b/source/graphics.c
index 111e4ff..06fe22e 100644
--- a/source/graphics.c
+++ b/source/graphics.c
@@ -43,6 +43,21 @@ const Color PaletteColors[] = {
uint16_t _pico8_fb[128*128];
+void swap(char *x, char *y) {
+ char temp;
+ temp = *x;
+ *x = *y;
+ *y = temp;
+
+ return;
+}
+
+void sortcoords(char *expectedLower, char *expectedHigher){
+ if (*expectedHigher < *expectedLower) {
+ swap(expectedLower, expectedHigher);
+ }
+}
+
void cls() {
memset(_pico8_fb, 0, sizeof(_pico8_fb));
}
@@ -59,26 +74,14 @@ void rect(char x, char y, char x1, char y1, uint16_t col) {
}
-void rectfill(char x, char y, char x1, char y1, uint16_t col) {
- char holder;
- if (x1 < x) {
- holder = x;
- x = x1;
- x1 = holder;
- }
- if (y1 < y) {
- holder = y;
- y = y1;
- y1 = holder;
- }
+void rectfill(char x1, char y1, char x2, char y2, uint16_t col) {
+ sortcoords(&x1, &x2);
+ sortcoords(&y1, &y2);
- int width = x1 - x;
- int height = y1 - y;
-
- for (int i = 0; i < width; i++) {
- for (int j = 0; j < height; j++) {
- if (x < 128 && y < 128) {
- _pico8_fb[((x + i) * 128) + (y + j)] = col;
+ for (int i = x1; i <= x2; i++) {
+ for (int j = y1; j <= y2; j++) {
+ if (i >= 0 && i < 127 && j >= 0 && j < 127) {
+ _pico8_fb[(i * 128) + j] = col;
}
}
}
diff --git a/source/main.c b/source/main.c
index 3955bb2..06b1c6e 100644
--- a/source/main.c
+++ b/source/main.c
@@ -17,6 +17,8 @@ int main(int argc, char **argv)
int frames = 0;
gfxInitDefault();
+ consoleInit(GFX_BOTTOM, NULL);
+
// Main loop
while (aptMainLoop())
{
@@ -38,7 +40,7 @@ int main(int argc, char **argv)
u8* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
//clear whole framebuffer
- memset(fb, 128, 240*400*3);
+ memset(fb, 192, 240*400*3);
//cart draw
_draw();
@@ -47,7 +49,6 @@ int main(int argc, char **argv)
flipBuffer(fb);
frames++;
-
}
gfxExit();