#define TART_UTF8 #include "../includes/tart.h" #include #include #include #include #include #define jump tart_move_cursor #define FPS 60 #define FRAME_TIME (1000.0 / FPS) int e = 1; void aOnExit() { //printf("shutting Down"); e = 0; } void draw_button(tart_window *w,const t_char* label, tart_vec2 position) { jump(w, (tart_vec2){position.x,position.y + 0}); tart_printf(w, 1, T"┏━━━"); int size = t_strlen(label); for(int i = 0; i < size; i++ ) { tart_printf(w, 1, T"━"); } tart_printf(w, 1, T"━━━┓"); jump(w, (tart_vec2){position.x,position.y + 1}); tart_printf(w, 1, T"┃ %ls ┃", label); jump(w, (tart_vec2){position.x,position.y + 2}); tart_printf(w, 1, T"┗━━━"); for(int i = 0; i < size; i++ ) { tart_printf(w, 1, T"━"); } tart_printf(w, 1, T"━━━┛"); } void limit_fps(int fps) { static struct timespec last_time; struct timespec current_time; double frame_time = 1.0 / fps; clock_gettime(CLOCK_MONOTONIC, ¤t_time); double elapsed = (current_time.tv_sec - last_time.tv_sec) + (current_time.tv_nsec - last_time.tv_nsec) / 1e9; if (elapsed < frame_time) { double sleep_time = frame_time - elapsed; struct timespec sleep = { (time_t)sleep_time, (long)(sleep_time * 1e9) }; nanosleep(&sleep, NULL); } last_time = current_time; } int main(int argc, char *argv[]) { signal(SIGINT, aOnExit); setlocale(LC_CTYPE, "en_US.UTF-8"); tart_window w; int color0 = 0; int color1 = 0; int color2 = 0; tart_create_window(&w, (tart_vec2){80,40}, "testing"); tart_init(&w); tart_disable_cusor(); w.palette[0].background.r = 0; w.palette[0].background.g = 0; w.palette[0].background.b = 0; w.palette[0].forground.r = 0; w.palette[0].forground.g = 0; w.palette[0].forground.b = 0; w.palette[1].forground.r = 0xff; w.palette[1].forground.g = 0x00; w.palette[1].forground.b = 0xcc; w.palette[2].forground.r = 0x3b; w.palette[2].forground.g = 0x3b; w.palette[2].forground.b = 0x3b; jump(&w, (tart_vec2){1,1}); jump(&w, (tart_vec2){1,2}); int x = 0; float xBounce = 30.0f; float xFlip = 0.1f; float yBounce = 30.0f; float yFlip = -0.40f; clock_t last_frame_time = clock(); double frame_time_ms; while(e != 0) { tart_draw(&w); draw_button(&w, T"This is really cool!", (tart_vec2){5,5}); tart_jump(&w, (tart_vec2){3,10}); tart_printf(&w,1, T"this is\na new line test\nyay"); tart_jump(&w, (tart_vec2){3+ 20,10}); tart_printf(&w,1, T"this is\na new line test\nyay"); tart_jump(&w, (tart_vec2){3,14}); tart_printf(&w,2, T"this is\na new line test\nyay"); tart_printf(&w,2, T"y position %f", yBounce); if((w.windowSize.x - 2 <= xBounce && xFlip > 0.0f) || (2 > xBounce && xFlip < 0.0f)) { xFlip *= -1 ; } if(((w.windowSize.y * 2) - 2 <= yBounce && yFlip > 0.0f) || (2 > yBounce && yFlip < 0.0f)) { yFlip *= -1 ; } yBounce += yFlip; xBounce += xFlip; tart_jump(&w, (tart_vec2){xBounce, yBounce/2}); if((int)yBounce % 2 == 0){ tart_printf(&w, 1, T"▀"); } else { tart_printf(&w, 1, T"▄"); } if(w.palette[1].forground.r == 254) { color0 = 0; } if(w.palette[1].forground.r == 0) { color0 = 1; } if(w.palette[1].forground.g == 254) { color1 = 0; } if(w.palette[1].forground.g == 0) { color1 = 1; } if(w.palette[1].forground.b == 254) { color2 = 0; } if(w.palette[1].forground.b == 0) { color2 = 1; } if(color0 == 1) { w.palette[1].forground.r++; }else { w.palette[1].forground.r--; } if(color1 == 1) { w.palette[1].forground.g++; }else { w.palette[1].forground.g--; } if(color2 == 1) { w.palette[1].forground.b++; }else { w.palette[1].forground.b--; } limit_fps(60); } tart_close(&w); tart_enable_cusor(); //printf("\e[?1049l"); printf("done\n"); return 0; }