But then I had a very good idea. I added F5.

This commit is contained in:
Alexandre 2025-05-11 16:49:14 +02:00
parent 946a721052
commit b18b1dc5ed
18 changed files with 109 additions and 51 deletions

BIN
bin/back

Binary file not shown.

View File

@ -24,7 +24,7 @@ Entities:
[-16.0, 0.0, -16.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 192, 1, 0, 6, yeet, 255, 255, 255]
[12.0, 0.0, 12.0, 4.0, 4.0, 4.0, 0.0, 0.0, 255, 255, 255, 1, 0, 8, 200, 1, 64, 64, 64]
[13.0, 1.0, 13.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 7, levels/level_04/, 1, keep going, 192, 192, 192]
[13.0, 1.0, 13.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 7, levels/level_04/, 1, prepare to jump, 192, 192, 192]
[-2.5, 30.0, -2.5, 1.0, 1.0, 1.0, 0.0, 0.0, 128, 128, 128, 1, 0, 0] // I should introduce for loops in these
[-1.5, 30.0, -2.5, 1.0, 1.0, 1.0, 0.0, 0.0, 128, 128, 128, 1, 0, 0]

View File

@ -2,38 +2,40 @@ Blocks:
[-16.0, -1.0, -16.0, 32.0, 1.0, 32.0, 0.0, 0.0, 192, 192, 192]
[-14.0, 0.0, -6.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[-14.0, 0.0, -2.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[-14.0, 0.0, 2.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[-14.0, 0.0, 6.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[-14.0, 0.0, 10.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[-14.0, 0.0, -6.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[-14.0, 0.0, -2.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[-14.0, 0.0, 2.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[-14.0, 0.0, 6.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[-14.0, 0.0, 10.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[-10.0, 0.0, -14.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[-10.0, 4.0, -10.0, 4.0, 1.5, 4.0, 0.0, 0.0, 128, 128, 128]
[-10.0, 0.0, -6.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[-10.0, 0.0, -14.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[-10.0, 0.0, -6.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[-10.0, 0.0, 10.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ -6.0, 0.0, -14.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[-10.0, 0.0, 10.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ -6.0, 0.0, -14.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ -6.0, 0.0, 2.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ -6.0, 0.0, 10.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ -2.0, 0.0, -14.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ -2.0, 0.0, 10.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ -6.0, 0.0, 2.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ -6.0, 0.0, 10.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ -2.0, 0.0, -14.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ -2.0, 0.0, 10.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ 2.0, 0.0, -14.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ 2.0, 0.0, 2.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ 2.0, 0.0, 10.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ 2.0, 0.0, -14.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ 2.0, 0.0, 2.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ 2.0, 0.0, 10.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ 6.0, 0.0, -14.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ 6.0, 0.0, 10.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ 6.0, 0.0, -14.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ 6.0, 0.0, 10.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ 10.0, 0.0, -14.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ 10.0, 2.0, -10.0, 4.0, 3.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ 10.0, 0.0, -6.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ 10.0, 0.0, -2.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ 10.0, 0.0, 2.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ 10.0, 0.0, 6.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ 10.0, 0.0, 10.0, 4.0, 5.5, 4.0, 0.0, 0.0, 128, 128, 128]
[ 10.0, 0.0, -14.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ 10.0, 2.0, -10.0, 4.0, 2.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ 10.0, 0.0, -6.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ 10.0, 0.0, -2.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ 10.0, 0.0, 2.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ 10.0, 0.0, 6.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[ 10.0, 0.0, 10.0, 4.0, 4.0, 4.0, 0.0, 0.0, 128, 128, 128]
[-14.0, 5.5, -14.0, 28.0, 1.0, 28.0, 0.0, 0.0, 128, 128, 128]
Entities:
[ -5.9, 0.1, -5.9, 3.8, 3.8, 3.8, 0.0, 0.0, 192, 129, 192, 1, 0, 10, 0.98, 1.0] // crates
@ -41,9 +43,8 @@ Entities:
[ -1.9, 0.1, 2.1, 3.8, 3.8, 3.8, 0.0, 0.0, 192, 129, 192, 1, 0, 10, 0.98, 1.0]
[ 6.1, 0.1, 2.1, 3.8, 3.8, 3.8, 0.0, 0.0, 192, 129, 192, 1, 0, 10, 0.98, 1.0]
[-16.0, 0.0, -0.3, 32.0, 0.3, 0.6, 0.0, 0.0, 192, 192, 192, 1,0, 2, 1.4, 0.0, 0.0, 0.0, 0.0, 5]
[-0.3, 1.2, -16.0, 0.6, 0.3, 32.0, 0.0, 0.0, 192, 192, 192, 1,0, 2, 1.4, 0.0, 0.0, 0.0, 0.0, 5]
[-3.0, 10.0, -3.0, 6.0, 1.0, 6.0, 0.0, 0.0, 192, 192, 192, 1, 0, 2, 1.0, 0.0, 0.0, 0.0, 0.0, 0]
[-16.0, 0.0, -0.3, 32.0, 0.3, 0.6, 0.0, 0.0, 192, 192, 192, 1,0, 2, 1.0, 0.0, 0.0, 0.0, 0.0, 5]
[-0.3, 1.2, -16.0, 0.6, 0.3, 32.0, 0.0, 0.0, 192, 192, 192, 1,0, 2, 1.0, 0.0, 0.0, 0.0, 0.0, 5]
[ -9.0, 0.0, 7.0, 2.0, 0.2, 2.0, 0.0, 0.0, 192, 129, 192, 1, 0, 14, 0] // keys
[ -5.0, 0.0, 7.0, 2.0, 0.2, 2.0, 0.0, 0.0, 192, 129, 192, 1, 0, 14, 1]

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -25,6 +25,7 @@ int flashlight = 10 ;
int MAX_SIZE = 8192 ;
int* drawOrder ;
int F5;
int loc_scale;
int loc_model;
@ -158,9 +159,16 @@ bool is_visible(cube_0* cb, double offx, double offy, double offz) {
//return true;
for(int d = 0; d < 8; d++) {
project_to_cube(cb->x+cb->w*(d%2==0), cb->y+cb->h*((d/2)%2==0), cb->z+cb->d*((d/4)%2==0), &px, &py, &pz, cb);
project_to_camera(px+offx, py+offy, pz+offz, &px2, &py2, &pz2);
if(pz2 >= near) {
return true;
if(F5 != 2) {
project_to_camera(px+offx, py+offy, pz+offz, &px2, &py2, &pz2);
if(pz2 >= near) {
return true;
}
} else {
project_to_camera(-px-offx, py+offy,-pz-offz, &px2, &py2, &pz2);
if(pz2 >= near) {
return true;
}
}
}
return false;
@ -215,6 +223,8 @@ void gl_renderAll(room* rtd, double offx, double offy, double offz) {
//printf("+++++++++++++++\n");
}
vec3 dir0;
vec3 direction;
void gl_renderNearbyChunks(int render_distance) {
for(int w = -render_distance; w <= render_distance; w++) {
for(int h = -render_distance; h <= render_distance; h++) {
@ -222,15 +232,24 @@ void gl_renderNearbyChunks(int render_distance) {
gl_renderAll(hashtbl_find_opt(visited, player_chx+w, player_chy+h), (2.0*room_width)*w, 0.0, (2.0*room_depth)*h);
}
}
if(F5 != 0) {
glBindTexture(GL_TEXTURE_2D, textures[0]);
fill_cube_0(F5_renderer, camx-min_dist, camy-min_dist, camz-min_dist, 2*min_dist, 2*min_dist, 2*min_dist, 0.0, 0.0, 192, 192, 192);
gl_renderCube(F5_renderer, 0.0, 0.0, 0.0);
}
//printf("\n\n");
}
vec3 dir0;
vec3 direction;
void gl_initRender(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO) {
if(F5==2) {
rot_hz += 3.14159;
}
dir0[0] = sinf((float)(rot_hz)) * cosf((float)(rot_vt));
dir0[1] = -sinf((float)(rot_vt));
dir0[2] = cosf((float)(rot_hz)) * cosf((float)(rot_vt));
if(F5==2) {
rot_hz -= 3.14159;
}
glm_vec3_normalize(dir0); // Normalize to unit length
glm_vec3_add((vec3){(float)camx, (float)camy, (float)camz}, dir0, direction);
@ -238,6 +257,10 @@ void gl_initRender(unsigned int shaderProgram, unsigned int fragmentShader, unsi
glm_mat4_identity(view);
glm_lookat((vec3){(float)camx, (float)camy, (float)camz}, direction, (vec3){0.0f, 1.0f, 0.0f}, view);
if(F5 != 0) {
glm_translate(view, (vec3){dir0[0]*3, dir0[1]*3, dir0[2]*3});
}
glm_perspective((1.0f - 2.0f*(is_FP==1))*glm_rad((float)fov), 1500.0f / 1000.0f, 0.1f, 100.0f*((float)bounding_mult), projection);
loc_scale = glGetUniformLocation(shaderProgram, "scale");

View File

@ -24,6 +24,8 @@
double choffx, choffz;
double choffxE, choffzE;
static int nTxts = 0;
// necessary condition for 2 boxes to collide (w*w + h*h + d*d is (diagonal length of the cube)²)
bool is_at_least_somewhat_close(cube_0* c1, cube_0* c2) {
return (
@ -181,6 +183,7 @@ void update_entities(float dtime, room* rtd) {
}
void update_nearby_entities(float dtime, int render_distance) {
nTxts = 0;
for(int w = -render_distance; w <= render_distance; w++) {
for(int h = -render_distance; h <= render_distance; h++) {
choffxE = 2*room_width*w;
@ -315,7 +318,16 @@ void moving_xyz_line(float dtime, entity* ent, cube_0* ret) {
}
}
// metai1 = id of the interface
// metai2 = price
// metai3 = doPay
// metach1 = text (stored here to free() easily)
void subtitle_text_box_far(float dtime, entity* ent, cube_0* ret) {
if(distance_pt_cube_0_3d_infinite(camx-choffxE, camy, camz-choffzE, ret) <= 3.0) {
gl_drawString(fShader, ent->metach1, 0.0f, -0.7f+0.12f*nTxts, 0.03f, ret->red, ret->green, ret->blue, 0.003f, 0);
nTxts+=1;
}
}
// metai1 = id of the interface
// metai2 = price
@ -323,7 +335,8 @@ void moving_xyz_line(float dtime, entity* ent, cube_0* ret) {
// metach1 = text (stored here to free() easily)
void subtitle_text_box(float dtime, entity* ent, cube_0* ret) {
if(distance_pt_cube_0_3d_infinite(camx+player_chx*room_width*2, camy, camz+player_chy*room_depth*2, ret) <= 1.5) {
gl_drawString(fShader, ent->metach1, 0.0f, -0.7f, 0.03f, ret->red, ret->green, ret->blue, 0.003f, 0);
gl_drawString(fShader, ent->metach1, 0.0f, -0.7f+0.12f*nTxts, 0.03f, ret->red, ret->green, ret->blue, 0.003f, 0);
nTxts+=1;
}
}

View File

@ -20,6 +20,7 @@ void speen3(float dtime, entity* ent, cube_0* ret);
void moving_xyz(float dtime, entity* ent, cube_0* ret);
void moving_xyz_line(float dtime, entity* ent, cube_0* ret);
void go_to_player(float dtime, entity* ent, cube_0* ret);
void subtitle_text_box_far(float dtime, entity* ent, cube_0* ret);
void subtitle_text_box(float dtime, entity* ent, cube_0* ret);
void beating_block(float dtime, entity* ent, cube_0* ret);
void spinning_platform(float dtime, entity* ent, cube_0* ret);

View File

@ -94,8 +94,9 @@ void init_ent_generator(int n) {
hashtbl_entities[6].tex = 1;
hashtbl_entities[6].tex2 = 1;
hashtbl_entities[6].name = "TextBox";
hashtbl_entities[6].updatePos = NULL;
hashtbl_entities[6].onHit = &pop_text;
hashtbl_entities[6].updatePos = &subtitle_text_box_far;
//hashtbl_entities[6].onHit = &pop_text;
hashtbl_entities[6].onHit = NULL;
hashtbl_entities[6].onDeath = NULL;
hashtbl_entities[7].id = 7;

View File

@ -45,6 +45,7 @@ bool rPress = false;
bool pPress = false;
bool kPress = false;
bool yPress = false;
bool P5ress = false;
unsigned int textures[32];
@ -54,9 +55,9 @@ bool hardReset = true;
double oldx, oldy, oldz;
int oldchx, oldchy;
int kodami[10] = {GLFW_KEY_UP, GLFW_KEY_UP, GLFW_KEY_DOWN, GLFW_KEY_DOWN, GLFW_KEY_LEFT, GLFW_KEY_RIGHT, GLFW_KEY_LEFT, GLFW_KEY_RIGHT, GLFW_KEY_B, GLFW_KEY_A};
int kodid = 0;
bool kodhit = false;
int konami[10] = {GLFW_KEY_UP, GLFW_KEY_UP, GLFW_KEY_DOWN, GLFW_KEY_DOWN, GLFW_KEY_LEFT, GLFW_KEY_RIGHT, GLFW_KEY_LEFT, GLFW_KEY_RIGHT, GLFW_KEY_B, GLFW_KEY_A};
int konid = 0;
bool konhit = false;
cube_0* modCube;
@ -151,20 +152,20 @@ void processInput(GLFWwindow *window, float dtime) {
glfwSetWindowShouldClose(window, true);
}
// kodami
if(!kodhit && is_SD == 0) { // no cheating with SD !
if(kodid == 10) {
kodhit = true;
// konami
if(!konhit && is_SD == 0) { // no cheating with SD !
if(konid == 10) {
konhit = true;
player_hp += 1500;
} else if(glfwGetKey(window, kodami[kodid]) == GLFW_PRESS) {
} else if(glfwGetKey(window, konami[konid]) == GLFW_PRESS) {
if(!kPress) {
kPress = true;
kodid += 1;
//printf("%d\n", kodid);
konid += 1;
//printf("%d\n", konid);
}
} else {
kPress = false;
//kodid = 0;
//konid = 0;
}
}
@ -191,6 +192,16 @@ void processInput(GLFWwindow *window, float dtime) {
pressed = true;
//camvy = vtmult*speed*sin(rot_vt);
}
if(glfwGetKey(window, GLFW_KEY_F5) == GLFW_PRESS) {
if(!P5ress) {
F5 = (F5+1)%3;
P5ress = true;
// 0 = 1st person, 1 = backwards F5, 2 = front F5
}
} else {
P5ress = false;
}
if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
if(gamemode == 1) {
for(int k = 0; k < 10; k++) {
@ -415,7 +426,7 @@ void generate_texture_2D(int id, char* filename, file_extension ext) {
int widthImg, heightImg, numColCh;
//unsigned char* bytes = stbi_load("res/container.jpg", &widthImg, &heightImg, &numColCh, 0);
unsigned char* bytes = stbi_load(filename, &widthImg, &heightImg, &numColCh, 0);
if(bytes == 0) {fprintf(stderr, "ERROR : cannot load texture\n"); exit(1);}
if(bytes == 0) {fprintf(stderr, "ERROR : cannot load texture [%s]\n", filename); exit(1);}
glGenTextures(1, &textures[id]);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures[id]);
@ -826,6 +837,7 @@ int main_alt() {
free_ent_generator();
printf("Done\n"); fflush(stdout);
free_maeth();
free(F5_renderer);
// optional: de-allocate all resources once they've outlived their purpose:
// ------------------------------------------------------------------------

View File

@ -89,6 +89,8 @@ float buttonMaxT[16];
bool mathSignal;
int mathSigCD;
cube_0* F5_renderer;
void init_csts() {
camx = 2.0;
camy = 5.0;
@ -104,6 +106,8 @@ void init_csts() {
room_width = 16.0;
room_depth = 16.0;
F5_renderer = create_cube_0(0.0, 0.0, 0.0, min_dist*2, min_dist*2, min_dist*2, 0.0, 0.0, 255, 255, 255);
coins = 0;
player_hp = 1000;
njumps = 1;

View File

@ -155,7 +155,7 @@ extern double sensitivity;
extern double fov;
extern double speed;
extern double creative_speed;
extern double min_dist;
extern double min_dist; // hitbox size
extern int render_distance;
// ---------------------------------------------------------------------------------------------------- //
@ -233,4 +233,7 @@ extern int modCount;
extern char* modString;
extern int F5; // but then I had a very good idea
extern cube_0* F5_renderer;
#endif