#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
    #include <windows.h>
    #define cross_sleep(ms) Sleep(ms)       // Windows Sleep takes milliseconds
#else
    #include <unistd.h>
    #define cross_sleep(ms) usleep(ms * 1000) // POSIX usleep takes microseconds
#endif

const float g = -9.81;
float obj_x = 0;
float obj_y = 100;
float obj_vel_x = 3;
float obj_vel_y = 0;
float ground_y = 0;
float time = 0;

int main() {
    printf(">= SIMULATION PARAMETERS =<\n");
    printf("g= %f\nX= %f Y= %f GROUND_Y= %f\nVEL_X= %.f  VEL_Y= %f\n\n", g, obj_x, obj_y, ground_y, obj_vel_x, obj_vel_y);
    while (obj_y > ground_y){
        // Add to the vel;
        obj_vel_y += 0.001 * g;

        // calculate change based on new vel
        obj_y += obj_vel_y * 0.001;
        obj_x += obj_vel_x * 0.001;
        printf("\r[%.2fs] X: %.2f Y: %.2f VEL_X: %.2f VEL_Y: %.2f", time, obj_x, obj_y, obj_vel_x, obj_vel_y);
        fflush(stdout);

        cross_sleep(1); 
        time += 0.001;
    }
    printf("\n\n>= Object End Stats =<\n");
    printf("X: %.2f, Y: %.2f, VEL_X: %.2f, VEL_Y: %.2f TIME: %f\n", obj_x, obj_y, obj_vel_x, obj_vel_y, time);
    return 0;
}