68 lines
2.3 KiB
C
68 lines
2.3 KiB
C
#include <stdio.h>
|
|
#include "pico/stdlib.h"
|
|
|
|
// sleep: sleep_ms(miliseconds)
|
|
// get input char: int ch = getchar(); then reference as %c in printf
|
|
// stdio_init_all: at the very front to initalize stdio
|
|
// printf works as normal
|
|
|
|
int physics(const float g, float obj_x, float obj_y, float obj_vel_x, float obj_vel_y, float ground_y) {
|
|
|
|
float time = 0;
|
|
printf("\n>= 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);
|
|
|
|
sleep_ms(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;
|
|
}
|
|
|
|
int main() {
|
|
stdio_init_all();
|
|
sleep_ms(1000);
|
|
while (1) {
|
|
printf("\n========================================\n");
|
|
printf("BUGS-P-0 A-1-i Under-dev Proto\n");
|
|
printf("----------------------------------------\n");
|
|
printf("[1] Physics simulation\n");
|
|
printf("[2] Nothing!\n");
|
|
printf("[h] Help\n");
|
|
printf("[c] Credits\n");
|
|
printf("[x] Exit\n");
|
|
int choice = getchar();
|
|
if (choice == '1') {
|
|
physics(-9.81, 0, 1, 40, 20, 0);
|
|
printf("Press any key to continue...\n");
|
|
getchar();
|
|
} else if (choice == '2') {
|
|
printf("Nothing here!\n");
|
|
printf("Press any key to continue...\n");
|
|
getchar();
|
|
} else if (choice == 'h') {
|
|
printf("No help is provided!\n");
|
|
printf("Press any key to continue...\n");
|
|
getchar();
|
|
} else if (choice == 'c') {
|
|
printf("P7MJ original!\n");
|
|
printf("Press any key to continue...\n");
|
|
getchar();
|
|
} else if (choice == 'x') {
|
|
printf("\nThe system has been halted. Please unplug the power source...");
|
|
return 0;
|
|
} else {
|
|
printf("Invalid option: %c\n", choice);
|
|
}
|
|
}
|
|
} |