diff --git a/.vscode/settings.json b/.vscode/settings.json index 84c97d3..3850c1e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -23,6 +23,8 @@ "stb_image.h": "c", "string.h": "c", "unistd.h": "c", - "pthread.h": "c" + "pthread.h": "c", + "maeth.h": "c", + "music.h": "c" } } \ No newline at end of file diff --git a/bin/back b/bin/back index aa29b75..00bb691 100755 Binary files a/bin/back and b/bin/back differ diff --git a/levels/level_02/room_0 b/levels/level_02/room_0 index 219e0ce..b92f358 100644 --- a/levels/level_02/room_0 +++ b/levels/level_02/room_0 @@ -62,41 +62,41 @@ Entities: [-33.0, 24.0, 18.0, 2.0, 2.0, 2.0, 0.71, 0.0, 92, 92, 92, 1, 0, 11, 1, 10.0] -[-5.0, 20.0, -18.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 0] // 3 - platforms -[-5.0, 20.0, -20.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 30] -[-5.0, 20.0, -22.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 60] -[-5.0, 20.0, -24.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 90] -[-5.0, 20.0, -26.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 120] -[-5.0, 20.0, -28.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 150] -[-5.0, 20.0, -30.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 180] -[-5.0, 20.0, -32.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 210] -[-5.0, 20.0, -34.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 240] -[-5.0, 20.0, -36.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 270] -[-5.0, 20.0, -38.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 300] -[-5.0, 20.0, -40.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 330] -[-5.0, 20.0, -42.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 0] +[-5.0, 20.0, -18.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 0] // 3 - platforms +[-5.0, 20.0, -20.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 30] +[-5.0, 20.0, -22.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 60] +[-5.0, 20.0, -24.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 90] +[-5.0, 20.0, -26.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 120] +[-5.0, 20.0, -28.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 150] +[-5.0, 20.0, -30.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 180] +[-5.0, 20.0, -32.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 210] +[-5.0, 20.0, -34.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 240] +[-5.0, 20.0, -36.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 270] +[-5.0, 20.0, -38.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 300] +[-5.0, 20.0, -40.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 330] +[-5.0, 20.0, -42.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 0] -[-5.0, 20.0, -18.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 0] -[-5.0, 20.0, -20.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 330] -[-5.0, 20.0, -22.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 300] -[-5.0, 20.0, -24.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 270] -[-5.0, 20.0, -26.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 240] -[-5.0, 20.0, -28.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 210] -[-5.0, 20.0, -30.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 180] -[-5.0, 20.0, -32.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 150] -[-5.0, 20.0, -34.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 120] -[-5.0, 20.0, -36.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 90] -[-5.0, 20.0, -38.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 60] -[-5.0, 20.0, -40.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 30] -[-5.0, 20.0, -42.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 1, 1, 0] +[-5.0, 20.0, -18.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 180] +[-5.0, 20.0, -20.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 210] +[-5.0, 20.0, -22.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 240] +[-5.0, 20.0, -24.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 270] +[-5.0, 20.0, -26.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 300] +[-5.0, 20.0, -28.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 330] +[-5.0, 20.0, -30.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 0] +[-5.0, 20.0, -32.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 30] +[-5.0, 20.0, -34.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 60] +[-5.0, 20.0, -36.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 90] +[-5.0, 20.0, -38.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 120] +[-5.0, 20.0, -40.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 150] +[-5.0, 20.0, -42.0, 4.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 4, 10.0, 0.0, 0.0, 3, 2, 180] -[ 12.0, 20.0, -20.0, 2.0, 8.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 11, 2, 15.0] // 3 - buttons -[-20.0, 20.0, -20.0, 2.0, 8.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 11, 3, 15.0] -[ 12.0, 20.0, -30.0, 2.0, 8.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 11, 4, 15.0] -[-20.0, 20.0, -30.0, 2.0, 8.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 11, 5, 15.0] -[ 12.0, 20.0, -40.0, 2.0, 8.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 11, 6, 15.0] -[-20.0, 20.0, -40.0, 2.0, 8.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 11, 7, 15.0] +[ 12.0, 20.0, -20.0, 2.0, 8.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 11, 2, 20.0] // 3 - buttons +[-20.0, 20.0, -20.0, 2.0, 8.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 11, 3, 20.0] +[ 12.0, 20.0, -30.0, 2.0, 8.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 11, 4, 20.0] +[-20.0, 20.0, -30.0, 2.0, 8.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 11, 5, 20.0] +[ 12.0, 20.0, -40.0, 2.0, 8.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 11, 6, 20.0] +[-20.0, 20.0, -40.0, 2.0, 8.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 11, 7, 20.0] [ 14.0, 20.0, -35.0, 2.0, 2.0, 2.0, 0.71, 0.0, 255, 255, 255, 1, 0, 12, 2, 0] // 3 - trigger blocks [ 15.5, 22.0, -35.0, 2.0, 2.0, 2.0, 0.71, 0.0, 255, 255, 255, 1, 0, 12, 3, 0] diff --git a/obj/entities.o b/obj/entities.o index 212ea3a..bd430b8 100644 Binary files a/obj/entities.o and b/obj/entities.o differ diff --git a/obj/generation.o b/obj/generation.o index eec1e29..0103707 100644 Binary files a/obj/generation.o and b/obj/generation.o differ diff --git a/obj/maeth.o b/obj/maeth.o index 5c03d41..26f0c20 100644 Binary files a/obj/maeth.o and b/obj/maeth.o differ diff --git a/obj/main.o b/obj/main.o index aa17ab1..b770e69 100644 Binary files a/obj/main.o and b/obj/main.o differ diff --git a/obj/menus.o b/obj/menus.o index 7c41704..7527d01 100644 Binary files a/obj/menus.o and b/obj/menus.o differ diff --git a/obj/music.o b/obj/music.o index e923ff1..3a15412 100644 Binary files a/obj/music.o and b/obj/music.o differ diff --git a/sound/audio/kahoot_theme.mp3 b/sound/audio/kahoot_theme.mp3 new file mode 100644 index 0000000..104d28e Binary files /dev/null and b/sound/audio/kahoot_theme.mp3 differ diff --git a/sound/audio/kahoot_theme.wav b/sound/audio/kahoot_theme.wav new file mode 100644 index 0000000..e6aac9f Binary files /dev/null and b/sound/audio/kahoot_theme.wav differ diff --git a/src/entities.c b/src/entities.c index 8eb1e65..b43ca22 100644 --- a/src/entities.c +++ b/src/entities.c @@ -16,6 +16,7 @@ #include "display.h" #include "menus.h" #include "proj.h" +#include "maeth.h" #include "entities.h" // ------------------------------------------------------------------------------------------------------------------------------------------------ // diff --git a/src/generation.c b/src/generation.c index 29fa3d0..52e9839 100644 --- a/src/generation.c +++ b/src/generation.c @@ -825,17 +825,17 @@ void generate_nearby_chunks(int render_dist) { void free_pool() { for(int k0 = 0; k0 < pool_size; k0++) { - printf("%d/%d\n", 1+k0, pool_size); fflush(stdout); + //printf("%d/%d\n", 1+k0, pool_size); fflush(stdout); for(int k = 0; k < pool[k0].area->map_size; k++) { - printf("%d-%d\n", k, pool[k0].area->map_size); + //printf("%d-%d\n", k, pool[k0].area->map_size); free(pool[k0].area->map[k]); } - printf("...\n"); fflush(stdout); + //printf("...\n"); fflush(stdout); for(int k = 0; k < pool[k0].area->tps_size; k++) { free(pool[k0].area->tps[k]->hitbox); free(pool[k0].area->tps[k]); } - printf("...\n"); fflush(stdout); + //printf("...\n"); fflush(stdout); for(int k = 0; k < pool[k0].area->ent_memlen; k++) { if(pool[k0].area->ents[k]->metai3 == -727) { // 6 and 7 // //free(pool[k0].area->ents[k]->metach1); @@ -848,7 +848,7 @@ void free_pool() { free(pool[k0].area->ents[k]->pos); free(pool[k0].area->ents[k]); } - printf("...\n"); fflush(stdout); + //printf("...\n"); fflush(stdout); free(pool[k0].area->ents); free(pool[k0].area->tps); free(pool[k0].area->map); diff --git a/src/maeth.c b/src/maeth.c index e3ad58a..ebb6220 100644 --- a/src/maeth.c +++ b/src/maeth.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "../include/glad/glad.h" #include #include @@ -14,8 +15,10 @@ #include "hash.h" #include "base.h" #include "menus.h" +#include "music.h" #include "maeth.h" +formula current_formula = NULL; // --------------------------------------------------------------------- // // between 1 and 20 int mathDiff = 3; @@ -28,19 +31,22 @@ int mathDoDmg = 1; // between 1 and 1000 int mathDmg = 500; + +// between 2 and 20 +int mathLength = 4; // --------------------------------------------------------------------- // // min bound for number gen (disregarding difficulty) int mthInf = 1; // max bound for number gen (disregarding difficulty) -int mthSup = 100; +int mthSup = 20; // whether or not to allow operations (SUM is always enabled) bool mthAllow[3]; // --------------------------------------------------------------------- // -int mthDiffSetting, mthAnsTSetting, mthDoDmgSetting, mthDmgSetting; +int mthDiffSetting, mthAnsTSetting, mthLengthSetting, mthDoDmgSetting, mthDmgSetting; int mthInfSetting, mthSupSetting; int mthExitSetting; @@ -56,18 +62,20 @@ void rebalance(void* arg) { void init_math_interfaces() { mthDiffSetting = button_create_onoff("difficulty", 128, 64, 64, -0.6f, 0.4f, 0.5f, 0.25f, SET_VAR, &mathDiff, 1, 20, INT, NULL, NULL); mthAnsTSetting = button_create_onoff("answer time", 255, 255, 64, -0.6f, 0.1f, 0.5f, 0.25f, SET_VAR, &mathAnsT, 1.0, 60.0, DOUBLE, NULL, NULL); - mthDoDmgSetting = button_create_onoff("damage if wrong", 255, 64, 64, -0.6f, -0.2f, 0.5f, 0.25f, SET_VAR, &mathDoDmg, 0, 1, INT, NULL, NULL); - mthDmgSetting = button_create_onoff("damage value", 128, 6, 6, -0.6f, -0.5f, 0.5f, 0.25f, SET_VAR, &mathDmg, 1, 1000, INT, NULL, NULL); + mthLengthSetting = button_create_onoff("length", 128, 128, 128, -0.6f, -0.2f, 0.5f, 0.25f, SET_VAR, &mathLength, 2, 20, INT, NULL, NULL); + mthDoDmgSetting = button_create_onoff("damage if wrong", 255, 64, 64, -0.6f, -0.5f, 0.5f, 0.25f, SET_VAR, &mathDoDmg, 0, 1, INT, NULL, NULL); + mthDmgSetting = button_create_onoff("damage value", 128, 6, 6, -0.6f, -0.8f, 0.5f, 0.25f, SET_VAR, &mathDmg, 1, 1000, INT, NULL, NULL); mthInfSetting = button_create_onoff("minimum val", 128, 128, 255, 0.1f, 0.4f, 0.5f, 0.25f, SET_VAR, &mthInf, 1, 32767, INT, NULL, NULL); mthSupSetting = button_create_onoff("maximum val", 128, 128, 255, 0.1f, 0.1f, 0.5f, 0.25f, SET_VAR, &mthSup, 1, 32767, INT, NULL, NULL); - mthExitSetting = button_create_onoff("back", 64, 255, 64,-0.25f, -0.8f, 0.5f, 0.25f, WARP, &welcome_start_i, 0, 1, INT, &rebalance, NULL); + mthExitSetting = button_create_onoff("back", 64, 255, 64, 0.25f, -0.8f, 0.5f, 0.25f, WARP, &welcome_start_i, 0, 1, INT, &rebalance, NULL); mthInterface = interface_create("math configs", 255, 192, 192, -0.4f , 0.7f, 0.8f, 0.25f); interface_link_button(mthInterface, mthDiffSetting); interface_link_button(mthInterface, mthAnsTSetting); + interface_link_button(mthInterface, mthLengthSetting); interface_link_button(mthInterface, mthDoDmgSetting); interface_link_button(mthInterface, mthDmgSetting); interface_link_button(mthInterface, mthInfSetting); @@ -82,26 +90,30 @@ void init_maeth() { } ctype get_ctype() { - int r = rand()%4; + int r = rand()%3; return (ctype)(1+r); } -formula create_formula_aux(int depth, int max_depth) { +formula create_formula_aux(int leng) { formula newF = malloc(sizeof(struct calcul)); - if(depth == max_depth) { + if(leng == 1 || leng == 0) { newF->calc1 = NULL; newF->calc2 = NULL; newF->operation = VALUE; newF->val = mthInf + rand()%(mthSup-mthInf); } else { - newF->calc1 = create_formula_aux(depth+1, max_depth); - newF->calc2 = create_formula_aux(depth+1, max_depth); + newF->calc1 = create_formula_aux(leng/2); + newF->calc2 = create_formula_aux(leng/2); newF->operation = get_ctype(); newF->val = 0; // irrelevant } return newF; } +formula create_formula() { + return create_formula_aux(mathLength); +} + int solve_formula(formula fm) { switch (fm->operation) { case VALUE: @@ -131,4 +143,170 @@ void free_formula(formula fm) { free_formula(fm->calc2); free(fm); } +} + +void display_formula_aux(unsigned int fragShader, formula fm, float* curx, float y, float size, float width, int r, int g, int b) { + float incr; + if(fm->operation != VALUE) { + gl_drawSymbol(fragShader, '(', *curx, y, size, r, g, b, width, &incr); + *curx += incr+4*width; + } + switch (fm->operation) { + case VALUE: + gl_drawInteger(fragShader, fm->val, *curx, y, size, r, g, b, width, 1); + *curx += (float)((fm->val==0)+ln_baseN(fm->val, 10))*(4*width+size); + break; + + case SUM: + display_formula_aux(fragShader, fm->calc1, curx, y, size, width, r, g, b); + gl_drawSymbol(fragShader, '+', *curx, y, size, r, g, b, width, &incr); + *curx += incr+4*width; + display_formula_aux(fragShader, fm->calc2, curx, y, size, width, r, g, b); + break; + + case DIFF: + display_formula_aux(fragShader, fm->calc1, curx, y, size, width, r, g, b); + gl_drawSymbol(fragShader, '-', *curx, y, size, r, g, b, width, &incr); + *curx += incr+4*width; + display_formula_aux(fragShader, fm->calc2, curx, y, size, width, r, g, b); + break; + + case MULT: + display_formula_aux(fragShader, fm->calc1, curx, y, size, width, r, g, b); + gl_drawSymbol(fragShader, '*', *curx, y, size, r, g, b, width, &incr); + *curx += incr+4*width; + display_formula_aux(fragShader, fm->calc2, curx, y, size, width, r, g, b); + break; + + case MODULO: + display_formula_aux(fragShader, fm->calc1, curx, y, size, width, r, g, b); + gl_drawSymbol(fragShader, '%', *curx, y, size, r, g, b, width, &incr); + *curx += incr+4*width; + display_formula_aux(fragShader, fm->calc2, curx, y, size, width, r, g, b); + break; + + default: + break; + } + if(fm->operation != VALUE) { + gl_drawSymbol(fragShader, ')', *curx, y, size, r, g, b, width, &incr); + *curx += incr+4*width; + } +} + +void free_maeth() { + if(current_formula != NULL) { + free_formula(current_formula); + } +} + +void display_formula(unsigned int fragShader, formula fm, float x, float y, float size, float width, int r, int g, int b) { + float curx = x; + display_formula_aux(fragShader, fm, &curx, y, size, width, r, g, b); +} + +// ---------------------------------------------------------------------------------------------------------------------------------------------------- // + +void generate_new_formula() { + if(current_formula != NULL) { + free_formula(current_formula); + } + current_formula = create_formula_aux(mathLength); +} + +void the_actual_main_math_function(GLFWwindow* window) { + generate_new_formula(); + int correct_answer = solve_formula(current_formula); + while(correct_answer == 0) { + generate_new_formula(); + correct_answer = solve_formula(current_formula); + } + struct timeval st, et; + gettimeofday(&st, NULL); + gettimeofday(&et, NULL); + bool solved = false; + int player_answer = 0; + int sign = 1; + bool mPress = false; + float ratio = 0.0f; + play_sound("sound/audio/kahoot_theme.wav"); + while(!solved && ratio < 1.0f) { + if(player_answer*sign == correct_answer) { + solved = true; + } + ratio = (float)((et.tv_sec-st.tv_sec + (et.tv_usec-st.tv_usec)/1000000.0f))/((float)mathAnsT); + + // ----------------------------------------------------------- // + if(glfwGetKey(window, GLFW_KEY_0) == GLFW_PRESS) { + if(!mPress) {player_answer = 10*player_answer ;} + mPress = true; + } else if(glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS) { + if(!mPress) {player_answer = 10*player_answer+1;} + mPress = true; + } else if(glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS) { + if(!mPress) {player_answer = 10*player_answer+2;} + mPress = true; + } else if(glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) { + if(!mPress) {player_answer = 10*player_answer+3;} + mPress = true; + } else if(glfwGetKey(window, GLFW_KEY_4) == GLFW_PRESS) { + if(!mPress) {player_answer = 10*player_answer+4;} + mPress = true; + } else if(glfwGetKey(window, GLFW_KEY_5) == GLFW_PRESS) { + if(!mPress) {player_answer = 10*player_answer+5;} + mPress = true; + } else if(glfwGetKey(window, GLFW_KEY_6) == GLFW_PRESS) { + if(!mPress) {player_answer = 10*player_answer+6;} + mPress = true; + } else if(glfwGetKey(window, GLFW_KEY_7) == GLFW_PRESS) { + if(!mPress) {player_answer = 10*player_answer+7;} + mPress = true; + } else if(glfwGetKey(window, GLFW_KEY_8) == GLFW_PRESS) { + if(!mPress) {player_answer = 10*player_answer+8;} + mPress = true; + } else if(glfwGetKey(window, GLFW_KEY_9) == GLFW_PRESS) { + if(!mPress) {player_answer = 10*player_answer+9;} + mPress = true; + } else + // ----------------------------------------------------------- // + if(glfwGetKey(window, GLFW_KEY_ENTER) == GLFW_PRESS) { + if(!mPress) {sign *= (-1);} + mPress = true; + } else if(glfwGetKey(window, GLFW_KEY_BACKSPACE) == GLFW_PRESS) { + if(!mPress) {player_answer /= 10;} + mPress = true; + } else { + mPress = false; + } + // ----------------------------------------------------------- // + if(glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) { + player_answer = correct_answer; + sign = 1; + } + // ----------------------------------------------------------- // + + gl_drawRect(fShader, -1.0f, 0.8f, 2.0f, 0.2f, 32, 32, 32); + display_formula(fShader, current_formula, -0.95f, 0.9f, 0.04f, 0.004f, 192, 192, 192); + + gl_drawRect(fShader, -0.7f, -0.1f, 1.4f, 0.2f, 32, 32, 32); + gl_drawInteger(fShader, player_answer*sign, 0.0f, 0.0f, 0.05f, 192, 192, 192, 0.004f, 0); + + gl_drawRect(fShader, -0.9f, -0.9f, 1.8f, 0.2f, 96, 96, 96); + gl_drawRect(fShader, -0.88f, -0.88f, 1.76f, 0.16f, 32, 32, 32); + gl_drawRect(fShader, -0.88f, -0.88f, 1.76f*ratio, 0.16f, 255*(ratio), 255*(1.0f-ratio), 0); + + gl_drawFloat(fShader, (1.0f-ratio)*((float)mathAnsT), 0.0f, -0.8f, 0.05f, 0, 0, 0, 0.004f, 0); + + glfwSwapBuffers(window); + glfwPollEvents(); + + gettimeofday(&et, NULL); + usleep(5000); + } + reset_music(); + if(solved) { + player_hp += 100; + } else { + player_hp -= mathDmg*mathDoDmg; + } } \ No newline at end of file diff --git a/src/maeth.h b/src/maeth.h index c650cc8..7427d27 100644 --- a/src/maeth.h +++ b/src/maeth.h @@ -13,5 +13,10 @@ typedef struct calcul* formula; void init_math_interfaces(); void init_maeth(); +void free_maeth(); + +void display_formula(unsigned int fragShader, formula fm, float x, float y, float size, float width, int r, int g, int b); + +void the_actual_main_math_function(GLFWwindow* window); #endif \ No newline at end of file diff --git a/src/main.c b/src/main.c index 90df99f..15df622 100644 --- a/src/main.c +++ b/src/main.c @@ -23,6 +23,7 @@ #include "entities.h" #include "display.h" #include "generation.h" +#include "maeth.h" #include "music.h" double sim_time; @@ -44,6 +45,9 @@ unsigned int textures[16]; bool paused = false; bool hardReset = true; +bool math_test = true; +int math_test_cd = 10; + double oldx, oldy, oldz; int oldchx, oldchy; void reset_everything(GLFWwindow *window, int count, char* folder) { @@ -598,6 +602,10 @@ int main_alt() { float delta = 0.0f; double deltad = 0.0; + float real_T = 0.01f; + + int count = 0; + clock_t finish = clock(); clock_t origin = clock(); @@ -633,14 +641,20 @@ int main_alt() { glUseProgram(shaderProgramR); glBindVertexArray(RVAO); - gl_drawInteger(shaderProgramR, (int)(1.0f/(delta)), 0.0f, -0.92f, 0.05, 32, 255, 32, 0.005, -1); + gl_drawInteger(shaderProgramR, (int)(1.0f/(real_T)), 0.0f, -0.92f, 0.05, 32, 255, 32, 0.005, -1); gl_drawInteger(shaderProgramR, triCount, 0.0f, 0.92f, 0.04f, 128, 128, 128, 0.005f, 1); gl_drawData(shaderProgramR); + //dpstst(shaderProgramR); + gl_drawDamageFadeout(shaderProgramR); gl_drawButtonTimers(shaderProgramR); - if(!isInMenu(window, shaderProgramR)) { + bool isinmenu = isInMenu(window, shaderProgramR); + if(!isinmenu) { + math_test_cd = max(math_test_cd-1, 0); + } + if(!isinmenu && !math_test) { processInput(window, delta); if(!paused) { if(gamemode == 0) { @@ -656,7 +670,14 @@ int main_alt() { gl_drawString(shaderProgramR, "press u to resume", 0.0f, -0.1f, 0.08f, 128, 128, 255, 0.005f, 0); } } + if(math_test_cd == 0 && math_test) { + glfwSwapBuffers(window); + glfwPollEvents(); + the_actual_main_math_function(window); + math_test = false; + } + finish = clock(); usleep(max(0, interval-(int)(1000000*delta))); sim_time += deltad; @@ -669,11 +690,15 @@ int main_alt() { lastDmg = player_hp; dmgCD = 0.5f; } - finish = clock(); delta = (float)slp_time;//+((float)finish - (float)origin)/CLOCKS_PER_SEC; deltad = slp_time;//+((double)finish - (double)origin)/CLOCKS_PER_SEC; + if(count%(fps/10)==0) { + real_T = ((float)finish - (float)origin)/CLOCKS_PER_SEC; + } origin = clock(); incr = 0.0f; + + count++; } printf("| 1/5 |\n"); fflush(stdout); @@ -688,6 +713,7 @@ int main_alt() { free_to_free(); free_ent_generator(); printf("Done\n"); fflush(stdout); + free_maeth(); // optional: de-allocate all resources once they've outlived their purpose: // ------------------------------------------------------------------------ @@ -716,5 +742,6 @@ int main(int argc, char** argv) { switchRoom = false; newRoomName = "templates/"; //play_sound("sound/audio/tetris_2.wav"); + //tstst(); return main_alt(); } \ No newline at end of file diff --git a/src/menus.c b/src/menus.c index 2e5897e..acc3cf3 100644 --- a/src/menus.c +++ b/src/menus.c @@ -127,6 +127,50 @@ void gl_drawDigit(unsigned int fragShader, int n, float x, float y, float size, } } +// if retval != NULL; it contains the width of the character +void gl_drawSymbol(unsigned int fragShader, char ch, float x, float y, float size, int r, int g, int b, float width, float* retval) { + if(ch == '+') { + gl_drawRect(fragShader, x-size/2-width, y-width, size+2*width, 2*width, r, g, b); + gl_drawRect(fragShader, x-width, y-size/2-width, 2*width, size+2*width, r, g, b); + if(retval != NULL) { + *retval = size; + } + } else if(ch == '-') { + gl_drawRect(fragShader, x-size/2-width, y-width, size+2*width, 2*width, r, g, b); + if(retval != NULL) { + *retval = size; + } + } else if(ch == '*' || ch == 'x') { + gl_drawChar(fragShader, 'x', x, y, 3*size/5, r, g, b, width); + if(retval != NULL) { + *retval = size; + } + } else if(ch == '%') { + gl_drawChar(fragShader, 'm', x, y, size, r, g, b, width); + if(retval != NULL) { + *retval = size; + } + } else if(ch == '(') { + gl_drawRect(fragShader, x-size/2-width, y-size/2-width, 2*width, size+2*width, r, g, b); + gl_drawRect(fragShader, x-size/2+width, y-size-width, 2*width, size/2+2*width, r, g, b); + gl_drawRect(fragShader, x-size/2+width, y+size/2-width, 2*width, size/2+2*width, r, g, b); + if(retval != NULL) { + *retval = 2*width; + } + } else if(ch == ')') { + gl_drawRect(fragShader, x-size/2+width, y-size/2-width, 2*width, size+2*width, r, g, b); + gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, size/2+2*width, r, g, b); + gl_drawRect(fragShader, x-size/2-width, y+size/2-width, 2*width, size/2+2*width, r, g, b); + if(retval != NULL) { + *retval = 2*width; + } + } else { + if(retval != NULL) { + *retval = 0.0f; + } + } +} + // 7-segment display // y is the middle of the text // side can be -1 (aligned right), 0 (centered) or 1 (aligned left) diff --git a/src/menus.h b/src/menus.h index 64ae804..0602dde 100644 --- a/src/menus.h +++ b/src/menus.h @@ -47,6 +47,8 @@ void gl_initDrawRect(unsigned int shaderProgram); void gl_drawInteger(unsigned int fragShader, int n, float x, float y, float size, int r, int g, int b, float width, int side); void gl_drawFloat(unsigned int fragShader, float n, float x, float y, float size, int r, int g, int b, float width, int side); +void gl_drawChar(unsigned int fragShader, char ch, float x, float y, float size, int r, int g, int b, float width); +void gl_drawSymbol(unsigned int fragShader, char ch, float x, float y, float size, int r, int g, int b, float width, float* retval); void gl_drawString(unsigned int fragShader, char* str, float x, float y, float size, int r, int g, int b, float width, int side); void gl_printf(unsigned int fragShader, float x, float y, float size, float width, int r, int g, int b, const char* str, ...); diff --git a/src/music.c b/src/music.c index 2f98e0b..c26c1aa 100644 --- a/src/music.c +++ b/src/music.c @@ -51,6 +51,18 @@ void end_music() { } } +void reset_music() { + FILE* endptr = fopen("sound/sem.txt", "w"); + fprintf(endptr, "0"); + fclose(endptr); + + usleep(100000); + + FILE* stptr = fopen("sound/sem.txt", "w"); + fprintf(stptr, "1"); + fclose(stptr); +} + char* get_name(char* filename) { char* res = malloc(sizeof(char)*100); res[0] = '.'; diff --git a/src/music.h b/src/music.h index 7ac867c..5497de0 100644 --- a/src/music.h +++ b/src/music.h @@ -2,6 +2,7 @@ #define MUSIC_H void init_music(); +void reset_music(); void end_music(); void play_sound(char* filename);