diff --git a/; b/; new file mode 100644 index 0000000..d3bd993 --- /dev/null +++ b/; @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +int main (int argc, char *argv[]) { + struct tart_window window = tart_create_window(); + struct tart_buffer mainbuff = tart_create_buffer(109, {20,20},{20,20}); + struct tart_cell* cells = (struct tart_cell*)malloc(mainbuff.cell_count * sizeof(struct tart_cell)); + //for(int i = 1; i < mainbuff.cell_count; i += 2) { + // cells[i] = tart_create_cell('^', TART_STYLE_BLINKING, TART_COLOR_BLACK_FOREGROUND, TART_COLOR_WHITE_BACKGROUND); + //} + //for(int i = 0; i < + mainbuff.cell_count; i += 2) { + // cells[i] = tart_create_cell('^', TART_STYLE_BLINKING, TART_COLOR_RED_FOREGROUND, TART_COLOR_BLACK_BACKGROUND); + //} + tart_add_cells_to_buffer(&mainbuff, cells); + + struct tart_vec2 positions[4] = {{0,0},{0,1},{1,0},{1,1}}; + struct tart_cell cell = tart_create_cell('0', TART_STYLE_BLINKING, TART_COLOR_RED_FOREGROUND, TART_COLOR_GREEN_BACKGROUND); + struct tart_cell cellss[4] = {cell,cell,cell,cell}; + + struct tart_csprite sprite = tart_csprite(cellss,positions,4); + tart_draw_cell_position(&mainbuff, cell, {3,3}); + //tart_draw_csprite_position(&mainbuff, sprite, {2,2}); + + char t[1] = {'0'}; + tart_add_buffer(&window, mainbuff); + tart_draw_window(&window, t); + + return 0; +} diff --git a/includes/tart.h b/includes/tart.h index 65c8577..082d9c0 100644 --- a/includes/tart.h +++ b/includes/tart.h @@ -24,7 +24,7 @@ extern "C" { #define NULL_CELL (struct tart_cell){{0,0,0},{0,0,0},0,0,0} #define TART_CELL_DATA_SIZE 16 // todo add number #else -#define NULL_CELL (struct tart_cell){0,0,0,0} +#define NULL_CELL (struct tart_cell){0,0,0,' '} #define TART_CELL_DATA_SIZE 20 #endif #define TART_OK 0 diff --git a/source/tart.c b/source/tart.c index e54c4a7..aa06977 100644 --- a/source/tart.c +++ b/source/tart.c @@ -160,6 +160,7 @@ struct tart_csprite tart_csprite(struct tart_cell* cells, struct tart_vec2* posi sprite.bounds.y = positions[i].y; } } + sprite.size = size; return sprite; }; @@ -173,7 +174,7 @@ tart_byte tart_csprite_free(struct tart_csprite* sprite) { } tart_byte tart_draw_cell_position(struct tart_buffer * buffer, struct tart_cell cell, struct tart_vec2 position) { - if(buffer->size.y >= position.y && buffer->size.x >= position.x) { + if(buffer->size.x >= position.x && buffer->size.y >= position.y) { buffer->cells[(buffer->size.x * position.y) + position.x] = cell; } return TART_OK; @@ -190,7 +191,7 @@ tart_byte tart_draw_cstring_position(struct tart_buffer *buffer, struct tart_cst tart_byte tart_draw_csprite_position(struct tart_buffer * buffer, struct tart_csprite sprite, struct tart_vec2 basePosition) { for(int i = 0; i < sprite.size; i++) { - struct tart_vec2 position = {sprite.position[i].x + basePosition.x, sprite.position[i].y + basePosition.y}; + struct tart_vec2 position = {sprite.position[i].x + basePosition.x, sprite.position[i].y + basePosition.y}; tart_draw_cell_position(buffer, sprite.data[i], position); } return TART_OK; diff --git a/testing/render_test/main.cpp b/testing/render_test/main.cpp index 420e6dc..241d132 100644 --- a/testing/render_test/main.cpp +++ b/testing/render_test/main.cpp @@ -5,7 +5,7 @@ int main (int argc, char *argv[]) { struct tart_window window = tart_create_window(); - struct tart_buffer mainbuff = tart_create_buffer(109, {100,50},{20,20}); + struct tart_buffer mainbuff = tart_create_buffer(109, {20,20},{20,20}); struct tart_cell* cells = (struct tart_cell*)malloc(mainbuff.cell_count * sizeof(struct tart_cell)); for(int i = 1; i < mainbuff.cell_count; i += 2) { cells[i] = tart_create_cell('^', TART_STYLE_BLINKING, TART_COLOR_BLACK_FOREGROUND, TART_COLOR_WHITE_BACKGROUND); @@ -15,6 +15,16 @@ int main (int argc, char *argv[]) { } tart_add_cells_to_buffer(&mainbuff, cells); + struct tart_vec2 positions[4] = {{0,0},{0,1},{1,0},{3,2}}; + struct tart_cell cell = tart_create_cell('0', TART_STYLE_BLINKING, TART_COLOR_RED_FOREGROUND, TART_COLOR_GREEN_BACKGROUND); + struct tart_cell cellss[4] = {cell,cell,cell,cell}; + + struct tart_csprite sprite = tart_csprite(cellss,positions,4); + tart_draw_csprite_position(&mainbuff, sprite, {2,2}); + tart_draw_csprite_position(&mainbuff, sprite, {5,2}); + tart_draw_csprite_position(&mainbuff, sprite, {5,5}); + tart_draw_csprite_position(&mainbuff, sprite, {21,18}); + char t[1] = {'0'}; tart_add_buffer(&window, mainbuff); tart_draw_window(&window, t);