fixed clipping when multiple collisions occur at the same time + added pause (U)

This commit is contained in:
Alexandre 2025-02-24 16:43:23 +01:00
parent 18bef7ada8
commit 0ab04bb603
6 changed files with 172 additions and 148 deletions

BIN
bin/back

Binary file not shown.

View File

@ -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

Binary file not shown.

Binary file not shown.

View File

@ -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,6 +126,7 @@ void processInput(GLFWwindow *window, float dtime) {
// horizontal movement
bool pressed = false;
if(!paused) {
if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
if(gamemode == 1) {
for(int k = 0; k < 10; k++) {
@ -246,9 +250,9 @@ void processInput(GLFWwindow *window, float dtime) {
if(glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS) {
if(!isMenuOpen() && !rPress) {
rPress = true;
reset_everything(window, 4, "levels/level_00/");
//reset_everything(window, 4, "levels/level_00/");
//reset_everything(window, 7, "levels/level_01/");
//reset_everything(window, 1, "levels/level_02/");
reset_everything(window, 1, "levels/level_02/");
}
} else {
rPress = false;
@ -260,6 +264,17 @@ void processInput(GLFWwindow *window, float dtime) {
reset_everything(window, newRoomCount, newRoomName);
//free(newRoomName);
}
}
// pause
if(glfwGetKey(window, GLFW_KEY_U) == GLFW_PRESS) {
if(!isMenuOpen() && !pPress) {
pPress = true;
paused = !paused;
}
} else {
pPress = false;
}
}
const char *vertexShaderSource = "#version 330 core\n"
@ -602,12 +617,18 @@ int main_alt() {
if(!isInMenu(window, shaderProgramR)) {
processInput(window, 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);
}
}
usleep(max(0, interval-(int)(1000000*delta)));

View File

@ -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) {