diff --git a/.vscode/settings.json b/.vscode/settings.json index 705d9a3..d935ccc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,6 +16,7 @@ "proj.h": "c", "entities.h": "c", "menus.h": "c", - "structure.h": "c" + "structure.h": "c", + "limits.h": "c" } } \ No newline at end of file diff --git a/bin/back b/bin/back index 0d23868..0af2dfc 100755 Binary files a/bin/back and b/bin/back differ diff --git a/levels/level_00/room_0 b/levels/level_00/room_0 deleted file mode 100644 index c513f43..0000000 --- a/levels/level_00/room_0 +++ /dev/null @@ -1,18 +0,0 @@ -Blocks : -[0.0, 0.0, 0.0, 10.0, 1.0, 10.0, 0.0, 0.0, 255, 255, 255] -[0.0, 9.0, 0.0, 10.0, 1.0, 10.0, 0.0, 0.0, 255, 255, 255] -[0.0, 1.0, 0.0, 1.0, 8.0, 1.0, 0.0, 0.0, 128, 128, 128] -[9.0, 1.0, 0.0, 1.0, 8.0, 1.0, 0.0, 0.0, 128, 128, 128] -[0.0, 1.0, 9.0, 1.0, 8.0, 1.0, 0.0, 0.0, 128, 128, 128] -[9.0, 1.0, 9.0, 1.0, 8.0, 1.0, 0.0, 0.0, 128, 128, 128] - -Teleporters : -[4.0, 1.0, 0.0, 2.0, 4.0, 1.0, 0.0, 0.0, 255, 0, 0; -1, 0] -[0.0, 1.0, 4.0, 1.0, 4.0, 2.0, 0.0, 0.0, 255, 255, 0; 0, -1] -[4.0, 1.0, 9.0, 2.0, 4.0, 1.0, 0.0, 0.0, 0, 255, 0; 1, 0] -[9.0, 1.0, 4.0, 1.0, 4.0, 2.0, 0.0, 0.0, 0, 0, 255; 0, 1] - -Weight : -50 - -$ \ No newline at end of file diff --git a/obj/base.o b/obj/base.o index eb81a7c..ae24806 100644 Binary files a/obj/base.o and b/obj/base.o differ diff --git a/obj/display.o b/obj/display.o index cb79fea..f6993a8 100644 Binary files a/obj/display.o and b/obj/display.o differ diff --git a/obj/entities.o b/obj/entities.o index e27ade8..d04f10f 100644 Binary files a/obj/entities.o and b/obj/entities.o differ diff --git a/obj/generation.o b/obj/generation.o index 06d1439..17eb6b9 100644 Binary files a/obj/generation.o and b/obj/generation.o differ diff --git a/obj/hash.o b/obj/hash.o index 4ea071c..1715c43 100644 Binary files a/obj/hash.o and b/obj/hash.o differ diff --git a/obj/main.o b/obj/main.o index 9dca130..a055971 100644 Binary files a/obj/main.o and b/obj/main.o differ diff --git a/obj/menus.o b/obj/menus.o index d9e483d..1e528a8 100644 Binary files a/obj/menus.o and b/obj/menus.o differ diff --git a/obj/move.o b/obj/move.o index bb4a603..edb98c2 100644 Binary files a/obj/move.o and b/obj/move.o differ diff --git a/obj/proj.o b/obj/proj.o index c67b085..36ff2be 100644 Binary files a/obj/proj.o and b/obj/proj.o differ diff --git a/src/entities.c b/src/entities.c index 8b44598..14a3501 100644 --- a/src/entities.c +++ b/src/entities.c @@ -192,4 +192,10 @@ void explodeOnHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) { fade_dmg = 255; } *hp = 0; +} + +// metai1 = id of the interface +// metach1 = text (unused outside of initialization) +void pop_text(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) { + interface_set(ent->metai1); } \ No newline at end of file diff --git a/src/entities.h b/src/entities.h index 0d6b797..cf8dbee 100644 --- a/src/entities.h +++ b/src/entities.h @@ -1,6 +1,8 @@ #ifndef ENTITIES_H #define ENTITIES_H +extern int build_text_box(char* msg, int red, int green, int blue); + bool is_colliding_with_map(cube_0* cb); bool is_colliding_with_tp(cube_0* cb); @@ -19,5 +21,6 @@ void money(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret); void explodeOnHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret); void translatePlayer(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret); void translatePlayerLine(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret); +void pop_text(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret); #endif \ No newline at end of file diff --git a/src/generation.c b/src/generation.c index 74883c2..5d1456d 100644 --- a/src/generation.c +++ b/src/generation.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "hash.h" #include "structure.h" @@ -30,7 +31,7 @@ int fct_entry_size; fct_entry* hashtbl_entities; void init_ent_generator(int n) { - //!\\ size = 10 now + //!\\ size = 30 now hashtbl_entities = malloc(sizeof(fct_entry)*n); fct_entry_size = n; for(int k = 0; k < 10; k++) { @@ -72,6 +73,19 @@ void init_ent_generator(int n) { hashtbl_entities[5].updatePos = &moving_xyz_line; hashtbl_entities[5].onHit = &translatePlayerLine; hashtbl_entities[5].onDeath = NULL; + + hashtbl_entities[6].id = 6; + hashtbl_entities[6].name = "TextBox"; + hashtbl_entities[6].updatePos = NULL; + hashtbl_entities[6].onHit = &pop_text; + hashtbl_entities[6].onDeath = NULL; + + // NOT IMPLEMENTED YET // + hashtbl_entities[7].id = 7; + hashtbl_entities[7].name = "WarpBox"; + hashtbl_entities[7].updatePos = NULL; + hashtbl_entities[7].onHit = &translatePlayerLine; + hashtbl_entities[7].onDeath = NULL; } fct_entry* get_entry(int k0) { @@ -132,6 +146,8 @@ void copy_room(room* src, room* dest, int chx, int chy) { dest->ents[k]->metad7 = src->ents[k]->metad7; dest->ents[k]->metad8 = src->ents[k]->metad8; dest->ents[k]->metad9 = src->ents[k]->metad9; + dest->ents[k]->metach1 = src->ents[k]->metach1; + dest->ents[k]->metach2 = src->ents[k]->metach2; *(dest->ents[k]->hitpoints) = *(src->ents[k]->hitpoints); dest->ents[k]->pos = create_cube_0( (*(src->ents[k]->pos)).x, (*(src->ents[k]->pos)).y, (*(src->ents[k]->pos)).z, @@ -258,6 +274,19 @@ int read_int(FILE* ptr, bool print) { return buffer*sign; } +char* read_string(FILE* ptr) { + char* res0 = malloc(sizeof(char)*51); + char c = fgetc(ptr); + int i = 0; + while(c != EOF && c != ',') { + res0[i] = c; + i += 1; + c = fgetc(ptr); + } + res0[i] = '\0'; + return res0; +} + double sign(double __x) { if(__x >= 0.0) { return 1.0; @@ -394,7 +423,10 @@ void parse_one_room(int id, char* filename) { pool[id].area->ents[k]->metad7 = entry->metad7; pool[id].area->ents[k]->metad8 = entry->metad8; pool[id].area->ents[k]->metad9 = entry->metad9; + pool[id].area->ents[k]->metach1 = entry->metach1; + pool[id].area->ents[k]->metach2 = entry->metach2; if(entry->id == 4) { + // sine platform double ccw = read_float(ptr); double cch = read_float(ptr); double ccd = read_float(ptr); @@ -411,13 +443,13 @@ void parse_one_room(int id, char* filename) { pool[id].area->ents[k]->metai2 = divd; pool[id].area->ents[k]->metai3 = phase; } else if(entry->id == 5) { + // linear platform double amp_x = read_float(ptr); double amp_y = read_float(ptr); double amp_z = read_float(ptr); double speed_x = read_float(ptr); double speed_y = read_float(ptr); double speed_z = read_float(ptr); - //printf("%lf, %lf, %lf, %lf, %lf, %lf\n", amp_x, amp_y, amp_z, speed_x, speed_y, speed_z); pool[id].area->ents[k]->metad1 = cx; pool[id].area->ents[k]->metad2 = cy; pool[id].area->ents[k]->metad3 = cz; @@ -430,32 +462,21 @@ void parse_one_room(int id, char* filename) { pool[id].area->ents[k]->metai1 = 1; pool[id].area->ents[k]->metai2 = 1; pool[id].area->ents[k]->metai3 = 1; + } else if(entry->id == 6) { + // text box + char* msg = read_string(ptr); + pool[id].area->ents[k]->metach1 = msg; + int ired = read_int(ptr, true); + int igreen = read_int(ptr, true); + int iblue = read_int(ptr, true); + pool[id].area->ents[k]->metai1 = build_text_box(msg, ired, igreen, iblue); + pool[id].area->ents[k]->metai2 = (-727); // random value to recognize } - //pool[id].area->ents[k]->updatePos = &speen2; - //pool[id].area->ents[k]->onHit = &detectHit ; - //pool[id].area->ents[k]->onDeath = NULL ; - //printf("\n"); } printf("3/3...\n"); fflush(stdout); - // debug - /*for(int k = 0; k < ncubes; k++) { - printf("(%lf, %lf, %lf), (%lf, %lf, %lf), (%lf, %lf), (%d, %d, %d)\n", - pool[id].area->map[k]->x, - pool[id].area->map[k]->y, - pool[id].area->map[k]->z, - pool[id].area->map[k]->w, - pool[id].area->map[k]->h, - pool[id].area->map[k]->d, - pool[id].area->map[k]->hz_angle, - pool[id].area->map[k]->vt_angle, - pool[id].area->map[k]->red, - pool[id].area->map[k]->green, - pool[id].area->map[k]->blue - ); - }*/ pool[id].weight = read_int(ptr, true); total_weight += pool[id].weight; @@ -609,6 +630,9 @@ void free_pool() { free(pool[k0].area->tps[k]); } for(int k = 0; k < pool[k0].area->ent_memlen; k++) { + if(pool[k0].area->ents[k]->metai2 == -727) { + free(pool[k0].area->ents[k]->metach1); + } free(pool[k0].area->ents[k]->hitpoints); free(pool[k0].area->ents[k]->pos); free(pool[k0].area->ents[k]); diff --git a/src/generation.h b/src/generation.h index e04a185..a9a7143 100644 --- a/src/generation.h +++ b/src/generation.h @@ -31,8 +31,12 @@ typedef struct fct_entry { double metad7; double metad8; double metad9; + char* metach1; + char* metach2; } fct_entry ; +extern int build_text_box(char* msg, int red, int green, int blue); + void init_ent_generator(int n); void copy_room(room* src, room* dest, int chx, int chy) ; @@ -44,6 +48,7 @@ void get_number_blocks(int* ret_cubes, int* ret_tps, int* ret_ent, FILE* ptr) ; void align_to(FILE* ptr, char ch) ; int read_int(FILE* ptr, bool print) ; double read_float(FILE* ptr) ; +char* read_string(FILE* ptr); void parse_one_room(int id, char* filename) ; void parse_rooms(int n_rooms, char* folder) ; diff --git a/src/main.c b/src/main.c index 3b8f799..43cfde1 100644 --- a/src/main.c +++ b/src/main.c @@ -37,10 +37,11 @@ void reset_everything(GLFWwindow *window, int count, char* folder) { //init_csts(); init_hashtbl(); - init_ent_generator(10); - init_proj(); init_interf(window); - parse_rooms(count, folder); + //build_all_menus(); + init_ent_generator(30); + init_proj(); + parse_rooms(7, "templates/"); } void processInput(GLFWwindow *window, float dtime) { @@ -250,10 +251,10 @@ int main_alt() { init_csts(); init_hashtbl(); - init_ent_generator(10); - init_proj(); init_interf(window); build_all_menus(); + init_ent_generator(30); + init_proj(); parse_rooms(7, "templates/"); // ---------------------------------------------------------------------------------------------------------------------------------------------- // diff --git a/src/menus.c b/src/menus.c index e598aad..ba13b2f 100644 --- a/src/menus.c +++ b/src/menus.c @@ -61,7 +61,7 @@ void gl_drawDigit(unsigned int fragShader, int n, float x, float y, float size, gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b); gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b); } else if(n == 1) { - gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b); + gl_drawRect(fragShader, x-width, y-size-width, 2*width, 2*size+2*width, r, g, b); } else if(n == 2) { gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b); gl_drawRect(fragShader, x+size/2-width, y-width, 2*width, size+2*width, r, g, b); @@ -138,19 +138,37 @@ void gl_drawInteger(unsigned int fragShader, int n, float x, float y, float size } void gl_drawFloat(unsigned int fragShader, float n, float x, float y, float size, int r, int g, int b, float width, int side) { - gl_drawInteger(fragShader, (int)(n*1000.0f), x, y, size, r, g, b, width, side); - int left = n; + int left = (int)(n*1000); + int acc = max(0, 5-ln_baseN(abs(left), 10)); float curx = x; + int countf = 0; if(left < 0) { left *= (-1); } if(side == 1) { - curx += (((n==0)+ln_baseN(abs((int)n), 10)-1)*(size+4*width)); + curx += (((left==0)+max(4, ln_baseN(abs(left), 10))-1)*(size+4*width)); } else if(side == 0) { - curx += (((n==0)+ln_baseN(abs((int)n), 10)-1)*(size+4*width))/2.0; + curx += (((left==0)+max(4, ln_baseN(abs(left), 10))-1)*(size+4*width))/2.0; + } + while(left > 0 || acc > 0) { + gl_drawDigit(fragShader, left%10, curx, y, size, r, g, b, width); + curx -= (size+4*width); + left = left/10; + countf += 1; + if(countf == 3) { + gl_drawRect(fragShader, curx+size/2+3*width/2, y-size-width, width, 2*width, r, g, b); + } + if(left == 0) { + acc -= 1; + } + } + if(n == 0) { + gl_drawDigit(fragShader, 0, curx, y, size, r, g, b, width); + curx -= (size+4*width); + } + if(n < 0) { + gl_drawRect(fragShader, curx-size/2-width, y, size+2*width, 2*width, r, g, b); } - curx -= (size+4*width)*3; // 0.001 rounding - gl_drawRect(fragShader, curx+size/2+2*width, y-size-width, 3*width, 3*width, r, g, b); } void gl_drawChar(unsigned int fragShader, char ch, float x, float y, float size, int r, int g, int b, float width) { @@ -338,6 +356,12 @@ void gl_printf(unsigned int fragShader, float x, float y, float size, float widt gl_drawInteger(fragShader, val, curx, y, size, r, g, b, width, 1); curx += (size+4*width)*(ln_baseN(abs(val), 10)); break; + case 'f': + float valf = (float)(va_arg(args, double)); + //printf("%d", val); + gl_drawFloat(fragShader, valf, curx, y, size, r, g, b, width, 1); + curx += (size+4*width)*(3+ln_baseN(abs((int)valf), 10)); + break; case 's': char* chval = (char*)(va_arg(args, const char*)); //printf("%s", chval); @@ -423,7 +447,7 @@ void display_interface(int int_id, unsigned int fragShader, float mx, float my) gl_drawString(fragShader, interfaceList[int_id].title, interfaceList[int_id].x+interfaceList[int_id].w/2.0f, interfaceList[int_id].y+interfaceList[int_id].h/2.0f, 0.7f*size, retcol, retcol, retcol, 0.7f*size/10.0f, 0); for(int k = 0; k < interfaceList[int_id].nButtons; k++) { - if(((int)(sim_time*10.0))%2 == 0 && is_hovering_button(interfaceList[int_id].buttons[k], mx, my)) { + if(is_hovering_button(interfaceList[int_id].buttons[k], mx, my)) { gl_drawRect(fragShader, buttonList[interfaceList[int_id].buttons[k]].x-0.015f, buttonList[interfaceList[int_id].buttons[k]].y-0.015f, buttonList[interfaceList[int_id].buttons[k]].w+0.03f, buttonList[interfaceList[int_id].buttons[k]].h+0.03f, 255, 255, 255); } display_button(interfaceList[int_id].buttons[k], fragShader); @@ -451,7 +475,7 @@ void menu_actions(GLFWwindow *window, int button, int action, int mods) { (*buttonList[but_id].onClick)(buttonList[but_id].arg); } //float prevIncr = incr+0.0001f; - float size = minf(interfaceList[*current_interface].h/2.1f, (interfaceList[*current_interface].w)/(get_string_len(interfaceList[*current_interface].title))); + float size = minf(interfaceList[*current_interface].h/2.1f, (interfaceList[*current_interface].w)/(3*(buttonList[but_id].cast != INT)+get_string_len(interfaceList[*current_interface].title))); int retcol = mn_get_color(interfaceList[*current_interface].red, interfaceList[*current_interface].green, interfaceList[*current_interface].blue); switch (buttonList[but_id].type) { case WARP: @@ -471,21 +495,21 @@ void menu_actions(GLFWwindow *window, int button, int action, int mods) { while(!halt) { toad = 0.0; mult = 1.0; - if(glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) { + if(glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) { pressed = true; if(!clicked) { clicked = true; - toad = 1.0; + toad = (buttonList[but_id].sup-buttonList[but_id].inf)/50.0; } } if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) { pressed = true; if(!clicked) { clicked = true; - toad = -1.0; + toad = (buttonList[but_id].inf-buttonList[but_id].sup)/50.0; } } - if(glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) { + if(glfwGetKey(window, GLFW_KEY_M) == GLFW_PRESS) { pressed = true; if(!clicked) { clicked = true; @@ -499,7 +523,7 @@ void menu_actions(GLFWwindow *window, int button, int action, int mods) { mult = 0.5; } } - if(glfwGetKey(window, GLFW_KEY_ENTER) == GLFW_PRESS) { + if(glfwGetKey(window, GLFW_KEY_ENTER) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) { halt = true; } @@ -509,24 +533,27 @@ void menu_actions(GLFWwindow *window, int button, int action, int mods) { fflush(stdout); gl_drawRect(fShader, buttonList[but_id].x, buttonList[but_id].y, buttonList[but_id].w, buttonList[but_id].h, buttonList[but_id].red, buttonList[but_id].green, buttonList[but_id].blue); + gl_drawRect(fShader, -1.0f, 0.7f, 2.0f, 0.3f, 0, 0, 0); + gl_drawString(fShader, "press a s m d to add subtract multiply or divide", 0.0f, 0.9f, 0.03f, 192, 192, 64, 0.002f, 0); + gl_printf(fShader, -0.8f, 0.8f, 0.03f, 0.003f, 255, 255, 255, "min %f", buttonList[but_id].inf); + gl_printf(fShader, 0.5f, 0.8f, 0.03f, 0.003f, 255, 255, 255, "max %f", buttonList[but_id].sup); switch (buttonList[but_id].cast) { case INT: int* valuei = (int*)buttonList[but_id].metadata; - *valuei = ((int)toad) + ((int)mult)*(*valuei); + *valuei = max(min(((int)toad) + ((int)mult)*(*valuei), (int)buttonList[but_id].sup), (int)buttonList[but_id].inf); gl_drawInteger(fShader, *valuei, buttonList[but_id].x+buttonList[but_id].w/2.0f, buttonList[but_id].y+buttonList[but_id].h/2.0f, size*0.7f, retcol, retcol, retcol, size/10.0f*0.7f, 0); break; case FLOAT: float* valuef = (float*)buttonList[but_id].metadata; - *valuef = ((float)toad) + ((float)mult)*(*valuef); + *valuef = maxf(minf(((float)toad) + ((float)mult)*(*valuef), (float)buttonList[but_id].sup), (float)buttonList[but_id].inf); gl_drawFloat(fShader, *valuef, buttonList[but_id].x+buttonList[but_id].w/2.0f, buttonList[but_id].y+buttonList[but_id].h/2.0f, size*0.7f, retcol, retcol, retcol, size/10.0f*0.7f, 0); break; case DOUBLE: double* valued = (double*)buttonList[but_id].metadata; - *valued = ((double)toad) + ((double)mult)*(*valued); - printf("(%lf, %lf) %lf\n", toad, mult, *valued); + *valued = maxd(mind(((double)toad) + ((double)mult)*(*valued), (double)buttonList[but_id].sup), (double)buttonList[but_id].inf); gl_drawFloat(fShader, (float)(*valued), buttonList[but_id].x+buttonList[but_id].w/2.0f, buttonList[but_id].y+buttonList[but_id].h/2.0f, size*0.7f, retcol, retcol, retcol, size/10.0f*0.7f, 0); break; @@ -540,7 +567,7 @@ void menu_actions(GLFWwindow *window, int button, int action, int mods) { //incr = prevIncr; //usleep(1000000/60); } - printf("EXIT\n"); + //printf("EXIT\n"); noMousePoll = false; break; @@ -582,6 +609,7 @@ bool isMenuOpen() { return (*current_interface != -1); } +int* numbers; void init_interf(GLFWwindow *window) { buttonList = malloc(sizeof(onoff_button)*MAX_BUTTON_SIZE); for(int k = 0; k < MAX_BUTTON_SIZE; k++) { @@ -593,6 +621,10 @@ void init_interf(GLFWwindow *window) { } bListId = 0; intListId = 0; + numbers = malloc(sizeof(int)*256); + for(int k = 0; k < 256; k++) { + numbers[k] = k; + } current_interface = malloc(sizeof(int)); *current_interface = -1; noMousePoll = false; @@ -602,7 +634,8 @@ void init_interf(GLFWwindow *window) { // returns the ID of the new button (-1 if error) // actn can be within {NONE, WARP, SET_VAR, EXIT} // if actn is WARP or SET_VAR then val shall not be NULL -int button_create_onoff(char* text, int red, int green, int blue, float x, float y, float w, float h, button_action actn, void* val, void_type cast, void (*onClick)(void*), void* arg) { +// min and max dont matter is actn is not SET_VAR +int button_create_onoff(char* text, int red, int green, int blue, float x, float y, float w, float h, button_action actn, void* val, double min, double max, void_type cast, void (*onClick)(void*), void* arg) { if(bListId < MAX_BUTTON_SIZE) { buttonList[bListId].id = bListId; @@ -620,6 +653,9 @@ int button_create_onoff(char* text, int red, int green, int blue, float x, float buttonList[bListId].metadata = val; buttonList[bListId].cast = cast; + buttonList[bListId].inf = min; + buttonList[bListId].sup = max; + buttonList[bListId].onClick = onClick; buttonList[bListId].arg = arg; @@ -700,27 +736,21 @@ void interface_set(int interface_id) { *current_interface = interface_id; } -/* - -*/ // build and link everything here -int zero = 0; -int one = 1; -int two = 2; -int three = 3; +int button_ok; void build_all_menus() { - int welcome_start_go = button_create_onoff("start", 0, 255, 255, -0.25f, 0.05f, 0.5f, 0.3f, EXIT, NULL, INT, NULL, NULL); - int welcome_start_settings = button_create_onoff("config", 96, 96, 96, -0.25f, -0.35f, 0.5f, 0.3f, WARP, &one, INT, NULL, NULL); + int welcome_start_go = button_create_onoff("start", 0, 255, 255, -0.25f, 0.05f, 0.5f, 0.3f, EXIT, NULL, 0.0, 0.0, INT, NULL, NULL); + int welcome_start_settings = button_create_onoff("config", 96, 96, 96, -0.25f, -0.35f, 0.5f, 0.3f, WARP, &(numbers[1]), INT, 0.0, 0.0, NULL, NULL); int welcome_start_i = interface_create("Welcome", 255, 255, 255, -0.4f, 0.7f, 0.8f, 0.25f); interface_link_button(welcome_start_i, welcome_start_go); interface_link_button(welcome_start_i, welcome_start_settings); - int settings_speed = button_create_onoff("speed", 0, 192, 192, -0.25f, 0.55f, 0.5f, 0.3f, SET_VAR, &speed, DOUBLE, NULL, NULL); - int settings_sensitivity = button_create_onoff("sensibility", 192, 192, 0, -0.25f, 0.2f, 0.5f, 0.3f, SET_VAR, &sensitivity, DOUBLE, NULL, NULL); - int settings_fov = button_create_onoff("fov", 192, 0, 192, -0.25f, -0.15f, 0.5f, 0.3f, SET_VAR, &fov, DOUBLE, NULL, NULL); - int settings_exit = button_create_onoff("back", 192, 64, 64, -0.25f, -0.5f, 0.5f, 0.3f, WARP, &zero, INT, NULL, NULL); + int settings_speed = button_create_onoff("speed", 0, 192, 192, -0.25f, 0.2f, 0.5f, 0.3f, SET_VAR, &speed, 0.1, 20.0, DOUBLE, NULL, NULL); + int settings_sensitivity = button_create_onoff("sensibility", 192, 192, 0, -0.25f, -0.15f, 0.5f, 0.3f, SET_VAR, &sensitivity, 0.01, 0.5, DOUBLE, NULL, NULL); + int settings_fov = button_create_onoff("fov", 192, 0, 192, -0.25f, -0.5f, 0.5f, 0.3f, SET_VAR, &fov, 30.0, 150.0, DOUBLE, NULL, NULL); + int settings_exit = button_create_onoff("back", 192, 64, 64, -0.25f, -0.85f, 0.5f, 0.3f, WARP, &(numbers[0]), INT, 0.0, 0.0, NULL, NULL); int settings_i = interface_create("Settings", 128, 128, 128, -0.4f , 0.7f, 0.8f, 0.25f); interface_link_button(settings_i, settings_speed); @@ -728,43 +758,22 @@ void build_all_menus() { interface_link_button(settings_i, settings_fov); interface_link_button(settings_i, settings_exit); + button_ok = button_create_onoff("ok", 32, 255, 32, -0.2f, -0.9f, 0.4f, 0.3f, EXIT, NULL, 0.0, 0.0, INT, NULL, NULL); interface_set(welcome_start_i); } +// returns the ID of the newly created interface +int build_text_box(char* msg, int red, int green, int blue) { + int intf = interface_create(msg, red, green, blue, -0.9f, 0.05f, 1.8f, 0.85f); + + interface_link_button(intf, button_ok); + + return intf; +} + void free_interf() { free(buttonList); free(interfaceList); free(current_interface); -} - -/* -typedef struct onoff_button { - int id; - - char* text; - float x; float y; float w; float h; - int red; - int green; - int blue; - - // {WARP, SET_VAR} - button_action type; - - // the value to change (if SET_VAR) or the destination interface (if WARP) - int* metadata; -} onoff_button; - -typedef struct interface { - int intfid; - - char* title; - float x; float y; float w; float h; - int red; - int green; - int blue; - - int* buttons; - int nButtons; - int nMemButtons; -} interface; -*/ \ No newline at end of file + free(numbers); +} \ No newline at end of file diff --git a/src/menus.h b/src/menus.h index 7739a1e..98c25d2 100644 --- a/src/menus.h +++ b/src/menus.h @@ -18,6 +18,9 @@ typedef struct onoff_button { void* metadata; void_type cast; + // limits + double inf; double sup; + // is called upon clicking button // this function is executed before metadata is used void (*onClick)(void* args); @@ -51,13 +54,14 @@ void init_interf(GLFWwindow *window); bool isInMenu(GLFWwindow *win, unsigned int fragShader); bool isMenuOpen(); -int button_create_onoff(char* text, int red, int green, int blue, float x, float y, float w, float h, button_action actn, void* val, void_type cast, void (*onClick)(void*), void* arg); +int button_create_onoff(char* text, int red, int green, int blue, float x, float y, float w, float h, button_action actn, void* val, double min, double max, void_type cast, void (*onClick)(void*), void* arg); int interface_create(char* title, int red, int green, int blue, float x, float y, float w, float h); void interface_link_button(int interface_id, int button_id); void interface_unlink_button(int interface_id, int button_id); void interface_set(int interface_id); void build_all_menus(); +int build_text_box(char* msg, int red, int green, int blue); void free_interf(); diff --git a/src/move.c b/src/move.c index 6e6097a..0282965 100644 --- a/src/move.c +++ b/src/move.c @@ -100,6 +100,10 @@ void set_player_coords(int old_chx, int old_chy) { return; } } + // no TP has been found, placing to the middle of the room + camx = 0.0; + camy = 10.0; + camz = 0.0; } pt_2d surface[3]; @@ -295,6 +299,7 @@ void movePlayerG(float dtime) { camz += camvz*dtime; camvx *= (1.0 - friction*((double)(dtime))); + camvy *= (1.0 - friction*((double)(dtime))); camvz *= (1.0 - friction*((double)(dtime))); if(camy <= -64) { diff --git a/src/structure.h b/src/structure.h index 3a23e55..eee0350 100644 --- a/src/structure.h +++ b/src/structure.h @@ -56,6 +56,8 @@ typedef struct entity { double metad7; double metad8; double metad9; + char* metach1; + char* metach2; int damage; int* hitpoints; diff --git a/templates/room_0 b/templates/room_0 index c513f43..b42c9a0 100644 --- a/templates/room_0 +++ b/templates/room_0 @@ -15,4 +15,30 @@ Teleporters : Weight : 50 -$ \ No newline at end of file +$ +entities: +[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..] + +if entityType = 4 (moving platform) + [.. amplitude_x, amplitude_y, amplitude_z, mult, divd, phase] with + amplitude_{x,y,z} = double[>= 0.0] + {mult,divd} = int + {phase} = int[0, 360] + +else if entityType = 5 (linear moving platform) + [.. amplitude_x, amplitude_y, amplitude_z, speed_x, speed_y, speed_z] with + amplitude_{x,y,z} = double[>= 0.0] + speed_{x,y,z} = double + +else if entityType = 6 (text box) + [.. text] with + text = {char*} + +// NOT IMPLEMENTED YET // +else if entityType = 7 (warp text box) + [.. text, r, g, b] with + text = {char*} (length <= 50) + {r,g,b} = int[0-256] + +else + [..] \ No newline at end of file diff --git a/templates/room_1 b/templates/room_1 index d891311..5ed89de 100644 --- a/templates/room_1 +++ b/templates/room_1 @@ -24,4 +24,30 @@ Entities : Weight : 50 -$ \ No newline at end of file +$ +entities: +[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..] + +if entityType = 4 (moving platform) + [.. amplitude_x, amplitude_y, amplitude_z, mult, divd, phase] with + amplitude_{x,y,z} = double[>= 0.0] + {mult,divd} = int + {phase} = int[0, 360] + +else if entityType = 5 (linear moving platform) + [.. amplitude_x, amplitude_y, amplitude_z, speed_x, speed_y, speed_z] with + amplitude_{x,y,z} = double[>= 0.0] + speed_{x,y,z} = double + +else if entityType = 6 (text box) + [.. text] with + text = {char*} + +// NOT IMPLEMENTED YET // +else if entityType = 7 (warp text box) + [.. text, r, g, b] with + text = {char*} (length <= 50) + {r,g,b} = int[0-256] + +else + [..] \ No newline at end of file diff --git a/templates/room_2 b/templates/room_2 index c0d60ec..c2abd0f 100644 --- a/templates/room_2 +++ b/templates/room_2 @@ -22,4 +22,30 @@ Entities : Weight : 50 -$ \ No newline at end of file +$ +entities: +[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..] + +if entityType = 4 (moving platform) + [.. amplitude_x, amplitude_y, amplitude_z, mult, divd, phase] with + amplitude_{x,y,z} = double[>= 0.0] + {mult,divd} = int + {phase} = int[0, 360] + +else if entityType = 5 (linear moving platform) + [.. amplitude_x, amplitude_y, amplitude_z, speed_x, speed_y, speed_z] with + amplitude_{x,y,z} = double[>= 0.0] + speed_{x,y,z} = double + +else if entityType = 6 (text box) + [.. text] with + text = {char*} + +// NOT IMPLEMENTED YET // +else if entityType = 7 (warp text box) + [.. text, r, g, b] with + text = {char*} (length <= 50) + {r,g,b} = int[0-256] + +else + [..] \ No newline at end of file diff --git a/templates/room_3 b/templates/room_3 index 215f62c..62fd62b 100644 --- a/templates/room_3 +++ b/templates/room_3 @@ -10,7 +10,36 @@ Teleporters : [9.0, 1.0, -5.0, 1.0, 2.0, 10.0, 0.0, 0.0, 0, 255, 0; 1, 0] [-5.0, 1.0, 9.0, 10.0, 2.0, 1.0, 0.0, 0.0, 0, 0, 255; 0, 1] +Entities : +[-1.0, 1.0, -1.0, 2.0, 2.0, 2.0, 0.0, 0.0, 0, 0, 0, 1, 0, 6, hey look a text box, 200, 200, 200] + Weight : 50 -$ \ No newline at end of file +$ +entities: +[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..] + +if entityType = 4 (moving platform) + [.. amplitude_x, amplitude_y, amplitude_z, mult, divd, phase] with + amplitude_{x,y,z} = double[>= 0.0] + {mult,divd} = int + {phase} = int[0, 360] + +else if entityType = 5 (linear moving platform) + [.. amplitude_x, amplitude_y, amplitude_z, speed_x, speed_y, speed_z] with + amplitude_{x,y,z} = double[>= 0.0] + speed_{x,y,z} = double + +else if entityType = 6 (text box) + [.. text] with + text = {char*} + +// NOT IMPLEMENTED YET // +else if entityType = 7 (warp text box) + [.. text, r, g, b] with + text = {char*} (length <= 50) + {r,g,b} = int[0-256] + +else + [..] \ No newline at end of file diff --git a/templates/room_4 b/templates/room_4 index c00fc1e..3d73a66 100644 --- a/templates/room_4 +++ b/templates/room_4 @@ -15,4 +15,30 @@ Entities : Weight : 50 -$ \ No newline at end of file +$ +entities: +[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..] + +if entityType = 4 (moving platform) + [.. amplitude_x, amplitude_y, amplitude_z, mult, divd, phase] with + amplitude_{x,y,z} = double[>= 0.0] + {mult,divd} = int + {phase} = int[0, 360] + +else if entityType = 5 (linear moving platform) + [.. amplitude_x, amplitude_y, amplitude_z, speed_x, speed_y, speed_z] with + amplitude_{x,y,z} = double[>= 0.0] + speed_{x,y,z} = double + +else if entityType = 6 (text box) + [.. text] with + text = {char*} + +// NOT IMPLEMENTED YET // +else if entityType = 7 (warp text box) + [.. text, r, g, b] with + text = {char*} (length <= 50) + {r,g,b} = int[0-256] + +else + [..] \ No newline at end of file diff --git a/templates/room_5 b/templates/room_5 index 618edcb..33146fb 100644 --- a/templates/room_5 +++ b/templates/room_5 @@ -31,5 +31,15 @@ else if entityType = 5 (linear moving platform) amplitude_{x,y,z} = double[>= 0.0] speed_{x,y,z} = double +else if entityType = 6 (text box) + [.. text] with + text = {char*} + +// NOT IMPLEMENTED YET // +else if entityType = 7 (warp text box) + [.. text, r, g, b] with + text = {char*} (length <= 50) + {r,g,b} = int[0-256] + else [..] \ No newline at end of file diff --git a/templates/room_6 b/templates/room_6 index 21f9c9a..f0562fa 100644 --- a/templates/room_6 +++ b/templates/room_6 @@ -31,5 +31,15 @@ else if entityType = 5 (linear moving platform) amplitude_{x,y,z} = double[>= 0.0] speed_{x,y,z} = double +else if entityType = 6 (text box) + [.. text] with + text = {char*} + +// NOT IMPLEMENTED YET // +else if entityType = 7 (warp text box) + [.. text, r, g, b] with + text = {char*} (length <= 50) + {r,g,b} = int[0-256] + else [..] \ No newline at end of file