diff --git a/bin/back b/bin/back index 067a49c..398539b 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 8ce6bcd..b17155b 100644 --- a/levels/level_02/room_0 +++ b/levels/level_02/room_0 @@ -1,16 +1,17 @@ Blocks : [-16.0, -1.0, -16.0, 32.0, 1.0, 32.0, 0.0, 0.0, 128, 128, 128] -[-5.0, 13.0, -5.0, 10.0, 1.0, 10.0, 0.0, 0.0, 255, 255, 255] -[-1.0, 0.0, -15.0, 2.0, 10.0, 2.0, 0.0, 0.0, 128, 128, 128] -[-1.0, 0.0, 13.0, 2.0, 10.0, 2.0, 0.0, 0.0, 128, 128, 128] -[-15.0, 0.0, -1.0, 2.0, 10.0, 2.0, 0.0, 0.0, 128, 128, 128] -[13.0, 0.0, -1.0, 2.0, 10.0, 2.0, 0.0, 0.0, 128, 128, 128] +[-4.0, 10.0, 0.0, 2.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192] Entities: -[-1.0, 15.0, -1.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 10, 0, 0] -[2.0 , 0.0 , 2.0 , 1.0, 1.0, 1.0, 0.0, 0.0, 255, 255, 255, 1 , 0, 6, hope you like parkour, 255, 192, 192] -[-2.0, 1.0 , -2.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 128, 1 , 0, 8, 50, 1, 128, 128, 128] -[-1.5, 1.5 , -1.5, 1.0, 1.0, 1.0, 0.0, 0.0, 192, 192, 192, 1 , 0, 7, levels/level_01/, 7, great, 192, 192, 192] +[-2.0, 1.0 , -2.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 128, 1, 0, 8, 100, 1, 128, 128, 128] +[-1.5, 1.5 , -1.5, 1.0, 1.0, 1.0, 0.0, 0.0, 192, 192, 192, 1, 0, 7, levels/level_01/, 7, great, 192, 192, 192] +[-8.0, 0.0, -8.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 9, 2.0, 2.0, 1] +[-6.0, 2.0, -8.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 9, 2.0, 2.0, 1] +[-4.0, 4.0, -8.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 9, 2.0, 2.0, 0] +[-4.0, 6.0, -6.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 9, 2.0, 2.0, 0] +[-4.0, 8.0, -4.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 9, 2.0, 2.0, 1] +[-4.0, 10.0, -2.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 9, 2.0, 2.0, 1] +[-4.0, 11.0, 7.0, 2.0, 1.0, 2.0, 0.0, 0.0, 192, 192, 192, 1, 0, 5, 0.0, 0.0, 5.0, 0.0, 0.0, 5.0] Weight : 0 diff --git a/obj/main.o b/obj/main.o index 06f4f74..8989f27 100644 Binary files a/obj/main.o and b/obj/main.o differ diff --git a/obj/move.o b/obj/move.o index 8598eae..2726477 100644 Binary files a/obj/move.o and b/obj/move.o differ diff --git a/src/main.c b/src/main.c index a16b098..22ad756 100644 --- a/src/main.c +++ b/src/main.c @@ -33,12 +33,15 @@ char* newRoomName; int newRoomCount; bool switchRoom; -double jPress = false; -double gPress = false; -double rPress = false; +bool jPress = false; +bool gPress = false; +bool rPress = false; +bool pPress = false; unsigned int textures[16]; +bool paused = false; + void reset_everything(GLFWwindow *window, int count, char* folder) { /*hashtbl_free(visited); free_proj(); @@ -123,142 +126,154 @@ void processInput(GLFWwindow *window, float dtime) { // horizontal movement bool pressed = false; - if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) { - if(gamemode == 1) { - for(int k = 0; k < 10; k++) { - camz -= creative_speed*cos(rot_hz)*cos(rot_vt)/10; - camx -= creative_speed*sin(rot_hz)*cos(rot_vt)/10; - camy += creative_speed*sin(rot_vt)/10; - if(is_colliding(dtime)) { - camz += creative_speed*cos(rot_hz)*cos(rot_vt)/10; - camx += creative_speed*sin(rot_hz)*cos(rot_vt)/10; - camy -= creative_speed*sin(rot_vt)/10; - k=11; - } - } - } else { - camvz = -speed*cos(rot_hz); - camvx = -speed*sin(rot_hz); - } - pressed = true; - //camvy = vtmult*speed*sin(rot_vt); - } - if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) { - if(gamemode == 1) { - for(int k = 0; k < 10; k++) { - camx -= creative_speed*cos(rot_hz)/10; - camz += creative_speed*sin(rot_hz)/10; - if(is_colliding(dtime)) { - camx += creative_speed*cos(rot_hz)/10; - camz -= creative_speed*sin(rot_hz)/10; - k=11; - } - } - } else { - camvx = -speed*cos(rot_hz); - camvz = speed*sin(rot_hz); - } - pressed = true; - } - if(glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) { - if(gamemode == 1) { - for(int k = 0; k < 10; k++) { - camz += creative_speed*cos(rot_hz)*cos(rot_vt)/10; - camx += creative_speed*sin(rot_hz)*cos(rot_vt)/10; - camy -= creative_speed*sin(rot_vt)/10; - if(is_colliding(dtime)) { + if(!paused) { + if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) { + if(gamemode == 1) { + for(int k = 0; k < 10; k++) { camz -= creative_speed*cos(rot_hz)*cos(rot_vt)/10; camx -= creative_speed*sin(rot_hz)*cos(rot_vt)/10; camy += creative_speed*sin(rot_vt)/10; - k=11; + if(is_colliding(dtime)) { + camz += creative_speed*cos(rot_hz)*cos(rot_vt)/10; + camx += creative_speed*sin(rot_hz)*cos(rot_vt)/10; + camy -= creative_speed*sin(rot_vt)/10; + k=11; + } } + } else { + camvz = -speed*cos(rot_hz); + camvx = -speed*sin(rot_hz); } - } else { - camvz = speed*cos(rot_hz); - camvx = speed*sin(rot_hz); + pressed = true; + //camvy = vtmult*speed*sin(rot_vt); } - pressed = true; - //camvy = -vtmult*speed*sin(rot_vt); - } - if(glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) { - if(gamemode == 1) { - for(int k = 0; k < 10; k++) { - camx += creative_speed*cos(rot_hz)/10; - camz -= creative_speed*sin(rot_hz)/10; - if(is_colliding(dtime)) { + if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) { + if(gamemode == 1) { + for(int k = 0; k < 10; k++) { camx -= creative_speed*cos(rot_hz)/10; camz += creative_speed*sin(rot_hz)/10; - k=11; + if(is_colliding(dtime)) { + camx += creative_speed*cos(rot_hz)/10; + camz -= creative_speed*sin(rot_hz)/10; + k=11; + } } + } else { + camvx = -speed*cos(rot_hz); + camvz = speed*sin(rot_hz); + } + pressed = true; + } + if(glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) { + if(gamemode == 1) { + for(int k = 0; k < 10; k++) { + camz += creative_speed*cos(rot_hz)*cos(rot_vt)/10; + camx += creative_speed*sin(rot_hz)*cos(rot_vt)/10; + camy -= creative_speed*sin(rot_vt)/10; + if(is_colliding(dtime)) { + camz -= creative_speed*cos(rot_hz)*cos(rot_vt)/10; + camx -= creative_speed*sin(rot_hz)*cos(rot_vt)/10; + camy += creative_speed*sin(rot_vt)/10; + k=11; + } + } + } else { + camvz = speed*cos(rot_hz); + camvx = speed*sin(rot_hz); + } + pressed = true; + //camvy = -vtmult*speed*sin(rot_vt); + } + if(glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) { + if(gamemode == 1) { + for(int k = 0; k < 10; k++) { + camx += creative_speed*cos(rot_hz)/10; + camz -= creative_speed*sin(rot_hz)/10; + if(is_colliding(dtime)) { + camx -= creative_speed*cos(rot_hz)/10; + camz += creative_speed*sin(rot_hz)/10; + k=11; + } + } + } else { + camvx = speed*cos(rot_hz); + camvz = -speed*sin(rot_hz); + } + pressed = true; + } + + // jumps + if(gamemode == 0 && njumps > 0 && glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) { + if(jPress) { + camvy = vtmult*speed; + njumps -= 1; + jPress = false; } } else { - camvx = speed*cos(rot_hz); - camvz = -speed*sin(rot_hz); + jPress = true; + } + if(!pressed) { + camvx *= (1.0-1.0*5.0*((double)dtime)); + camvz *= (1.0-1.0*5.0*((double)dtime)); + } + + // gamemode + if(glfwGetKey(window, GLFW_KEY_G) == GLFW_PRESS) { + if(!gPress) { + gPress = true; + gamemode = 1-gamemode; + njumps = 1; + camvx = 0.0; + camvy = 0.0; + camvz = 0.0; + } + } else { + gPress = false; + } + + // camera rotation + if(glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) { + rot_hz -= sensitivity; + } + if(glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) { + rot_hz += sensitivity; + } + + if(glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS) { + rot_vt = maxd(-3.14159/2.0, rot_vt-sensitivity); + } + if(glfwGetKey(window, GLFW_KEY_M) == GLFW_PRESS) { + rot_vt = mind(3.14159/2.0, rot_vt+sensitivity); + } + + // reset + if(glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS) { + if(!isMenuOpen() && !rPress) { + rPress = true; + //reset_everything(window, 4, "levels/level_00/"); + //reset_everything(window, 7, "levels/level_01/"); + reset_everything(window, 1, "levels/level_02/"); + } + } else { + rPress = false; + } + + if(!isMenuOpen() && switchRoom) { + //printf("-----\n"); + switchRoom = false; + reset_everything(window, newRoomCount, newRoomName); + //free(newRoomName); } - pressed = true; } - // jumps - if(gamemode == 0 && njumps > 0 && glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) { - if(jPress) { - camvy = vtmult*speed; - njumps -= 1; - jPress = false; - } - } else { - jPress = true; - } - if(!pressed) { - camvx *= (1.0-1.0*5.0*((double)dtime)); - camvz *= (1.0-1.0*5.0*((double)dtime)); - } - - // gamemode - if(glfwGetKey(window, GLFW_KEY_G) == GLFW_PRESS) { - if(!gPress) { - gPress = true; - gamemode = 1-gamemode; - njumps = 1; - camvx = 0.0; - camvy = 0.0; - camvz = 0.0; + // pause + if(glfwGetKey(window, GLFW_KEY_U) == GLFW_PRESS) { + if(!isMenuOpen() && !pPress) { + pPress = true; + paused = !paused; } } else { - gPress = false; - } - - // camera rotation - if(glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) { - rot_hz -= sensitivity; - } - if(glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) { - rot_hz += sensitivity; - } - - if(glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS) { - rot_vt = maxd(-3.14159/2.0, rot_vt-sensitivity); - } - if(glfwGetKey(window, GLFW_KEY_M) == GLFW_PRESS) { - rot_vt = mind(3.14159/2.0, rot_vt+sensitivity); - } - - // reset - if(glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS) { - if(!isMenuOpen() && !rPress) { - rPress = true; - reset_everything(window, 4, "levels/level_00/"); - //reset_everything(window, 7, "levels/level_01/"); - //reset_everything(window, 1, "levels/level_02/"); - } - } else { - rPress = false; - } - - if(!isMenuOpen() && switchRoom) { - //printf("-----\n"); - switchRoom = false; - reset_everything(window, newRoomCount, newRoomName); - //free(newRoomName); + pPress = false; } } @@ -602,12 +617,18 @@ int main_alt() { if(!isInMenu(window, shaderProgramR)) { processInput(window, delta); - if(gamemode == 0) { - movePlayerG(delta); + if(!paused) { + if(gamemode == 0) { + movePlayerG(delta); + } + teleport_on_edge(); + update_nearby_entities(delta, 1); + updateProj(delta); + } else { + gl_drawRectAlpha(shaderProgramR, -1.0f, -1.0f, 2.0f, 2.0f, 0, 0, 0, 128); + gl_drawString(shaderProgramR, "game Paused", 0.0f, 0.1f, 0.08f, 128, 128, 255, 0.005f, 0); + gl_drawString(shaderProgramR, "press u to resume", 0.0f, -0.1f, 0.08f, 128, 128, 255, 0.005f, 0); } - teleport_on_edge(); - update_nearby_entities(delta, 1); - updateProj(delta); } usleep(max(0, interval-(int)(1000000*delta))); diff --git a/src/move.c b/src/move.c index 5200d9b..d8fbed2 100644 --- a/src/move.c +++ b/src/move.c @@ -18,11 +18,11 @@ double sensitivity = 0.06; double fov = 90.0; double creative_speed = 0.5; -double speed = 5.0; -double vtmult = 1.5; +double speed = 6.0; +double vtmult = 2.25; double min_dist = 0.4; double friction = 0.3; -double gravity_factor = 9.8; +double gravity_factor = 25.0; // ---------------------------------------------------------------------------------------------------- // bool is_clipping = false; @@ -197,7 +197,7 @@ void updateF(cube_0* cb, double dtime) { double alpha = acos(dot3D(normal, (pt_2d){.x = camvx, .y = camvy, .z = camvz})/normv); double beta = 3.1415926535 - 2*alpha; - double nu = sqrt(2)*normv*sqrt(1-cos(beta)); + double nu = normv*sqrt(1-cos(beta)); pt_2d u = (pt_2d){.x = normal.x*nu, .y = normal.y*nu, .z = normal.z*nu}; @@ -205,9 +205,9 @@ void updateF(cube_0* cb, double dtime) { camvy += u.y; camvz += u.z; - camvx /= 1.41; - camvy /= 1.41; - camvz /= 1.41; + //camvx /= 1.41; + //camvy /= 1.41; + //camvz /= 1.41; is_clipping = false; } @@ -215,6 +215,7 @@ void updateF(cube_0* cb, double dtime) { } bool is_colliding(float dtime) { + bool globalCollision = false; for(int w = -1; w <= 1; w++) { for(int h = -1; h <= 1; h++) { room* vstd = hashtbl_find_opt(visited, player_chx+w, player_chy+h); @@ -225,7 +226,7 @@ bool is_colliding(float dtime) { if(updateForces) { updateF(vstd->map[k], (double)dtime); } - return true; + globalCollision = true; } } @@ -242,7 +243,7 @@ bool is_colliding(float dtime) { vstd = hashtbl_find_opt(visited, player_chx, player_chy); set_player_coords(old_chx, old_chy); resetProj(); - return true; + globalCollision = true; } } @@ -262,6 +263,7 @@ bool is_colliding(float dtime) { remove_entity(vstd->ents, &vstd->ent_memlen, &vstd->ent_len, k); is_clipping = false; exists = false; + k =- 1; } } if(exists && updateForces && vstd->ents[k]->entity_type != 0) { @@ -270,14 +272,14 @@ bool is_colliding(float dtime) { if(exists && (vstd->ents[k]->entity_type == 9 || vstd->ents[k]->entity_type == 4 || vstd->ents[k]->entity_type == 5)) { is_clipping = false; } - return true; + globalCollision = true; } } } } } } - return false; + return globalCollision; } void movePlayerG(float dtime) {