finished with rework
This commit is contained in:
97
test/main.c
97
test/main.c
@@ -4,8 +4,11 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <locale.h>
|
||||
#include <time.h>
|
||||
|
||||
#define jump tart_move_cursor
|
||||
#define FPS 60
|
||||
#define FRAME_TIME (1000.0 / FPS)
|
||||
|
||||
int e = 1;
|
||||
|
||||
@@ -33,6 +36,24 @@ void draw_button(tart_window *w,const t_char* label, tart_vec2 position) {
|
||||
}
|
||||
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[])
|
||||
{
|
||||
@@ -47,23 +68,29 @@ int main(int argc, char *argv[])
|
||||
tart_init(&w);
|
||||
tart_disable_cusor();
|
||||
|
||||
w.pallet[0].background.r = 0;
|
||||
w.pallet[0].background.g = 0;
|
||||
w.pallet[0].background.b = 0;
|
||||
w.pallet[0].forground.r = 0;
|
||||
w.pallet[0].forground.g = 0;
|
||||
w.pallet[0].forground.b = 0;
|
||||
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.pallet[1].forground.r = 0xff;
|
||||
w.pallet[1].forground.g = 0x00;
|
||||
w.pallet[1].forground.b = 0xcc;
|
||||
w.palette[1].forground.r = 0xff;
|
||||
w.palette[1].forground.g = 0x00;
|
||||
w.palette[1].forground.b = 0xcc;
|
||||
|
||||
w.pallet[2].forground.r = 0x3b;
|
||||
w.pallet[2].forground.g = 0x3b;
|
||||
w.pallet[2].forground.b = 0x3b;
|
||||
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);
|
||||
@@ -75,41 +102,61 @@ int main(int argc, char *argv[])
|
||||
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");
|
||||
if(w.pallet[1].forground.r == 254) {
|
||||
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.pallet[1].forground.r == 0) {
|
||||
if(w.palette[1].forground.r == 0) {
|
||||
color0 = 1;
|
||||
}
|
||||
if(w.pallet[1].forground.g == 254) {
|
||||
if(w.palette[1].forground.g == 254) {
|
||||
color1 = 0;
|
||||
}
|
||||
if(w.pallet[1].forground.g == 0) {
|
||||
if(w.palette[1].forground.g == 0) {
|
||||
color1 = 1;
|
||||
}
|
||||
if(w.pallet[1].forground.b == 254) {
|
||||
if(w.palette[1].forground.b == 254) {
|
||||
color2 = 0;
|
||||
}
|
||||
if(w.pallet[1].forground.b == 0) {
|
||||
if(w.palette[1].forground.b == 0) {
|
||||
color2 = 1;
|
||||
}
|
||||
|
||||
if(color0 == 1) {
|
||||
w.pallet[1].forground.r++;
|
||||
w.palette[1].forground.r++;
|
||||
}else {
|
||||
w.pallet[1].forground.r--;
|
||||
w.palette[1].forground.r--;
|
||||
}
|
||||
if(color1 == 1) {
|
||||
w.pallet[1].forground.g++;
|
||||
w.palette[1].forground.g++;
|
||||
}else {
|
||||
w.pallet[1].forground.g--;
|
||||
w.palette[1].forground.g--;
|
||||
}
|
||||
if(color2 == 1) {
|
||||
w.pallet[1].forground.b++;
|
||||
w.palette[1].forground.b++;
|
||||
}else {
|
||||
w.pallet[1].forground.b--;
|
||||
w.palette[1].forground.b--;
|
||||
}
|
||||
|
||||
|
||||
limit_fps(60);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user