Compare commits

...

3 Commits

18 changed files with 172 additions and 27 deletions

BIN
bin/back

Binary file not shown.

18
levels/level_00/room_0 Normal file
View File

@ -0,0 +1,18 @@
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
$

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

@ -212,9 +212,9 @@ void gl_initRender(unsigned int shaderProgram, unsigned int fragmentShader, unsi
}
void gl_drawData(unsigned int shaderProg) {
gl_drawInteger(shaderProg, (int)camx, 0.95f, 0.9f, 0.05f, 255, 255, 255, 0.005, -1);
gl_drawInteger(shaderProg, (int)camx + 2*room_width*player_chx, 0.95f, 0.9f, 0.05f, 255, 255, 255, 0.005, -1);
gl_drawInteger(shaderProg, (int)camy, 0.95f, 0.75f, 0.05f, 255, 255, 255, 0.005, -1);
gl_drawInteger(shaderProg, (int)camz, 0.95f, 0.6f, 0.05f, 255, 255, 255, 0.005, -1);
gl_drawInteger(shaderProg, (int)camz + 2*room_depth*player_chy, 0.95f, 0.6f, 0.05f, 255, 255, 255, 0.005, -1);
gl_drawInteger(shaderProg, (int)10.0*camvx, 0.95f, -0.6f, 0.05f, 255, 255, 255, 0.005, -1);
gl_drawInteger(shaderProg, (int)10.0*camvy, 0.95f, -0.75f, 0.05f, 255, 255, 255, 0.005, -1);
@ -222,6 +222,7 @@ void gl_drawData(unsigned int shaderProg) {
gl_drawInteger(shaderProg, njumps, 0.0f, 0.80f, 0.04f, 255, 255, 128, 0.005f, 1);
gl_printf(shaderProg, -0.95f, 0.9f, 0.05f, 0.005f, 255-player_hp/4, player_hp/4, 0, "HP %d", player_hp);
gl_printf(shaderProg, -0.95f, 0.9f, 0.04f, 0.004f, 255-player_hp/4, player_hp/4, 0, "HP %d", player_hp);
gl_printf(shaderProg, -0.95f, 0.8f, 0.04f, 0.004f, 255, 255, 0, "coins %d", coins);
//gl_drawInteger(shaderProg, player_hp, -0.95f, 0.9f, 0.05f, 255-player_hp/4, player_hp/4, 0, 0.005f, 1);
}

View File

@ -97,17 +97,26 @@ void moving_xyz(double x, double y, double z, double w, double h, double d, doub
// metai{2} = y_side (+/- 1)
// metai{3} = z_side (+/- 1)
void moving_xyz_line(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret) {
//printf("%lf %lf %lf", ent->metad7, ent->metad8, ent->metad9);
//printf("| %lf %lf %lf\n", ent->metad4, ent->metad5, ent->metad6);
ret->x += (ent->metai1)*ent->metad4*dtime;
if(absf(ent->metad1 - ret->x) > ent->metad7) {
//printf("-x-\n");
ent->metai1 *= (-1);
ret->x += (ent->metai1)*ent->metad4*dtime;
}
ret->y += (ent->metai2)*ent->metad5*dtime;
//printf("%lf, %lf | %lf\n", ent->metad2, ret->y, ent->metad8);
if(absf(ent->metad2 - ret->y) > ent->metad8) {
//printf("-y-\n");
ent->metai2 *= (-1);
ret->y += (ent->metai2)*ent->metad5*dtime;
}
ret->z += (ent->metai3)*ent->metad6*dtime;
if(absf(ent->metad3 - ret->z) > ent->metad9) {
//printf("-z-\n");
ent->metai3 *= (-1);
ret->z += (ent->metai3)*ent->metad6*dtime;
}
}
@ -125,6 +134,15 @@ void detectHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
}
}
void money(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
coins += *hp;
player_hp -= (*dmg);
if(*dmg != 0) {
fade_dmg = 255;
}
*hp = 0;
}
void translatePlayer(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
double dx = ent->metad4*(cos((double)(ent->metai1*(sim_time+(double)dtime)/ent->metai2 + ent->metai3*3.14159/180.0))-cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0)));
double dy = ent->metad5*(cos((double)(ent->metai1*(sim_time+(double)dtime)/ent->metai2 + ent->metai3*3.14159/180.0))-cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0)));
@ -135,9 +153,9 @@ 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) {
double dx = ent->metad4*(cos((double)(ent->metai1*(sim_time+(double)dtime)/ent->metai2 + ent->metai3*3.14159/180.0))-cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0)));
double dy = ent->metad5*(cos((double)(ent->metai1*(sim_time+(double)dtime)/ent->metai2 + ent->metai3*3.14159/180.0))-cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0)));
double dz = ent->metad6*(cos((double)(ent->metai1*(sim_time+(double)dtime)/ent->metai2 + ent->metai3*3.14159/180.0))-cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0)));
double dx = (ent->metai1)*ent->metad4*dtime;
double dy = (ent->metai2)*ent->metad5*dtime;
double dz = (ent->metai3)*ent->metad6*dtime;
//fx += dx/(dtime*dtime);
fy += dy/(dtime*dtime);
//fz += dz/(dtime*dtime);

View File

@ -15,6 +15,7 @@ void moving_xyz_line(double x, double y, double z, double w, double h, double d,
void go_to_player(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret);
void detectHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret);
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);

View File

@ -39,8 +39,8 @@ void init_ent_generator(int n) {
hashtbl_entities[0].id = 0;
hashtbl_entities[0].name = "Coin"; // 0 = default
hashtbl_entities[0].updatePos = &speen2;
hashtbl_entities[0].onHit = &detectHit;
hashtbl_entities[0].updatePos = &speen;
hashtbl_entities[0].onHit = &money;
hashtbl_entities[0].onDeath = NULL;
hashtbl_entities[1].id = 1;
@ -194,12 +194,9 @@ void build_starting_chunk(int chx, int chy) {
void init_hashtbl() {
visited = hashtbl_generate(1789);
build_starting_chunk(0, 0);
current_room = hashtbl_find_opt(visited, 0, 0);
player_chx = 0;
player_chy = 0;
build_starting_chunk(player_chx, player_chy);
current_room = hashtbl_find_opt(visited, player_chx, player_chy);
total_weight = 0;
coins = 0;
}
void get_number_blocks(int* ret_cubes, int* ret_tps, int* ret_ent, FILE* ptr) {
@ -420,6 +417,10 @@ void parse_one_room(int id, char* filename) {
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;
pool[id].area->ents[k]->metad4 = speed_x;
pool[id].area->ents[k]->metad5 = speed_y;
pool[id].area->ents[k]->metad6 = speed_z;
@ -465,8 +466,33 @@ void parse_one_room(int id, char* filename) {
fclose(ptr);
}
void parse_rooms(int n_rooms) {
char* name = malloc(sizeof(char)*19); // 1000 rooms max
char* get_name_and_i(char* folder, int nrooms, int* reti) {
int len = 0;
while(folder[len] != '\0') {
len+=1;
}
int lnn = 1+ln_baseN(nrooms, 10);
int str_size = len+lnn+5;
char* res = malloc(sizeof(char)*str_size);
for(int k = 0; k < len; k++) {
res[k] = folder[k];
}
res[len ] = 'r';
res[len+1] = 'o';
res[len+2] = 'o';
res[len+3] = 'm';
res[len+4] = '_';
res[len+5] = '0';
for(int k = len+6; k < str_size; k++) {
res[k] = '\0';
}
*reti = len+5;
return res;
}
void parse_rooms(int n_rooms, char* folder) {
/*char* name = malloc(sizeof(char)*19); // 1000 rooms max (not anymore xD)
name[0] = 't';
name[1] = 'e';
name[2] = 'm';
@ -485,7 +511,9 @@ void parse_rooms(int n_rooms) {
name[15] = '0';
name[16] = '\0';
name[17] = '\0';
name[18] = '\0';
name[18] = '\0';*/
int id = 0;
char* name = get_name_and_i(folder, n_rooms, &id);
pool = malloc(sizeof(entry)*n_rooms);
pool_size = n_rooms;
@ -495,10 +523,14 @@ void parse_rooms(int n_rooms) {
for(int k = 0; k < n_rooms; k++) {
printf("parsing %d...", k);
if(k < 10) {
name[15] = (char)(k%10 + 48);
name[id] = (char)(k%10 + 48);
} else if(k < 100) {
name[15] = (char)((k/10)%10 + 48);
name[16] = (char)(k%10 + 48);
name[id] = (char)((k/10)%10 + 48);
name[id+1] = (char)(k%10 + 48);
} else if(k < 1000) {
name[id] = (char)((k/100)%10 + 48);
name[id+1] = (char)((k/10)%10 + 48);
name[id+2] = (char)(k%10 + 48);
}
parse_one_room(k, name);
printf("done.\n");
@ -512,6 +544,8 @@ void parse_rooms(int n_rooms) {
// has to be a multiple of both room_width and room_depth
int divider = 4;
// unused
void generate_terrain(room* r) {
int rsize = 4*(room_width/divider)*(room_width/divider)*(room_depth/divider)*(room_depth/divider); // floor size (with 1x1 cubes)

View File

@ -45,7 +45,7 @@ void align_to(FILE* ptr, char ch) ;
int read_int(FILE* ptr, bool print) ;
double read_float(FILE* ptr) ;
void parse_one_room(int id, char* filename) ;
void parse_rooms(int n_rooms) ;
void parse_rooms(int n_rooms, char* folder) ;
void generate_nearby_chunks(int render_dist) ;

View File

@ -27,6 +27,22 @@ int gamemode;
double jPress = false;
double gPress = false;
double rPress = false;
void reset_everything(char* folder) {
hashtbl_free(visited);
free_proj();
free_interf();
free_pool();
//init_csts();
init_hashtbl();
init_ent_generator(10);
init_proj();
init_interf();
parse_rooms(1, folder);
}
void processInput(GLFWwindow *window, float dtime) {
// quit w
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
@ -153,6 +169,16 @@ void processInput(GLFWwindow *window, float dtime) {
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(!rPress) {
rPress = true;
reset_everything("levels/level_00/");
}
} else {
rPress = false;
}
}
const char *vertexShaderSource = "#version 330 core\n"
@ -225,7 +251,7 @@ int main_alt() {
init_ent_generator(10);
init_proj();
init_interf();
parse_rooms(6);
parse_rooms(7, "templates/");
// ---------------------------------------------------------------------------------------------------------------------------------------------- //
// ---------------------------------------------------------------------------------------------------------------------------------------------- //

View File

@ -114,7 +114,7 @@ void gl_drawInteger(unsigned int fragShader, int n, float x, float y, float size
left *= (-1);
}
if(side == 1) {
curx += ((ln_baseN(abs(n), 10)-1)*(size+4*width));
curx += (((n==0)+ln_baseN(abs(n), 10)-1)*(size+4*width));
}
while(left > 0) {
gl_drawDigit(fragShader, left%10, curx, y, size, r, g, b, width);

View File

@ -66,20 +66,27 @@ void init_csts() {
camx = 2.0;
camy = 5.0;
camz = 2.0;
player_chx = 0;
player_chy = 0;
camvx = 0.0;
camvy = 0.0;
camvz = 0.0;
rot_hz = 0.0;
rot_vt = 0.0;
draw_type = 0;
player_hp = 1000;
fade_dmg = 0;
room_width = 16.0;
room_depth = 16.0;
sq2 = sqrt(2);
coins = 0;
player_hp = 1000;
njumps = 3;
draw_type = 0;
fade_dmg = 0;
stop_evetything = false;
tan_fov = tan((fov * 3.14159 / 180.0) / 2.0);
sq2 = sqrt(2);
}
void set_player_coords(int old_chx, int old_chy) {
@ -289,6 +296,10 @@ void movePlayerG(float dtime) {
camvx *= (1.0 - friction*((double)(dtime)));
camvz *= (1.0 - friction*((double)(dtime)));
if(camy <= -64) {
player_hp -= (int)(400*dtime);
}
}
void teleport_on_edge() {

View File

@ -11,9 +11,10 @@ Entities:
[-15.0, 4.0, -15.0, 4.0, 1.0, 4.0, 0.0, 0.0, 192, 128, 192, 10, 0, 4, 0.0, 5.0, 0.0, 2, 1, 0]
[-5.0, 9.0, -15.0, 4.0, 1.0, 4.0, 0.0, 0.0, 192, 128, 192, 10, 0, 5, 5.0, 0.0, 0.0, 6.0, 0.0, 0.0]
[0.0, 10.0, -5.0, 4.0, 1.0, 4.0, 0.0, 0.0, 192, 128, 192, 10, 0, 4, 0.0, 0.0, 5.0, 2, 1, 35]
[0.0, 15.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 255, 255, 0, 5, 0, 0]
Weight :
100
50
$
entities:

35
templates/room_6 Normal file
View File

@ -0,0 +1,35 @@
Blocks :
[-8.0, 0.0, -8.0, 16.0, 1.0, 16.0, 0.0, 0.0, 192, 192, 192]
Teleporters :
[-10.0, 1.0, -1.0, 1.0, 2.0, 2.0, 0.0, 0.0, 255, 0, 0; -1, 0]
[-1.0, 1.0, -10.0, 2.0, 2.0, 1.0, 0.0, 0.0, 255, 255, 0; 0, -1]
[9.0, 1.0, -1.0, 1.0, 2.0, 2.0, 0.0, 0.0, 0, 255, 0; 1, 0]
[-1.0, 1.0, 9.0, 2.0, 2.0, 1.0, 0.0, 0.0, 0, 0, 255; 0, 1]
Entities:
[-2.0, 4.1, -2.0, 4.0, 1.0, 4.0, 0.0, 0.0, 32, 128, 192, 10, 0, 5, 0.0, 4.0, 0.0, 0.0, 5.5, 0.0]
[-6.0, 8.1, -2.0, 4.0, 1.0, 4.0, 0.0, 0.0, 32, 128, 192, 10, 0, 5, 0.0, 4.0, 0.0, 0.0, 6.0, 0.0]
[6.0, 12.1, -2.0, 4.0, 1.0, 4.0, 0.0, 0.0, 32, 128, 192, 10, 0, 5, 0.0, 4.0, 0.0, 0.0, 6.5, 0.0]
[0.0, 20.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 255, 255, 0, 10, 0, 0]
Weight :
50
$
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
[..]