Compare commits

...

3 Commits

Author SHA1 Message Date
Alexandre 7b79815188 physics 2025-02-06 19:28:20 +01:00
Alexandre 541596e8c0 added jumping and moving platforms 2025-02-06 15:57:27 +01:00
Alexandre 381348a420 changed type in room + fixed some segFaults 2025-02-06 14:36:33 +01:00
28 changed files with 536 additions and 239 deletions

BIN
bin/back

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.

Binary file not shown.

Binary file not shown.

View File

@ -357,21 +357,26 @@ void project_to_cube(double x0, double y0, double z0, double* rx, double* ry, do
void remove_entity(entity** arr, int* memlen, int* len, int index) { void remove_entity(entity** arr, int* memlen, int* len, int index) {
if(*len > 0) { if(*len > 0) {
(*arr)[index] = (*arr)[*len -1]; entity* temp = arr[index];
arr[index] = arr[*len -1];
arr[*len -1] = temp;
*len -= 1; *len -= 1;
} }
} }
void add_entity(entity** arr, int* memlen, int* len, entity ent) { void add_entity(entity** arr, int* memlen, int* len, entity* ent) {
if(*memlen == *len) { if(*memlen == *len) {
entity* newarr = malloc(sizeof(entity)*2*(*memlen)); entity** newarr = malloc(sizeof(entity*)*2*(*memlen));
for(int k = 0; k < *len; k++) { for(int k = 0; k < *len; k++) {
newarr[k] = (*arr)[k] ; newarr[k] = malloc(sizeof(entity));
newarr[k] = arr[k] ;
free(arr[k]);
} }
free(*arr); free(*arr);
*arr = newarr ; arr = newarr ;
*memlen *= 2; *memlen *= 2;
} }
(*arr)[*len] = ent ; free(arr[*len]);
arr[*len] = ent ;
*len += 1; *len += 1;
} }

View File

@ -56,7 +56,7 @@ double distance_pt_cube_axis_max(double coord, double begin, double end);
double distance_pt_cube_aligned_3d_max(double x0, double y0, double z0, double cx, double cy, double cz, double cw, double ch, double cd); double distance_pt_cube_aligned_3d_max(double x0, double y0, double z0, double cx, double cy, double cz, double cw, double ch, double cd);
void remove_entity(entity** arr, int* memlen, int* len, int index); void remove_entity(entity** arr, int* memlen, int* len, int index);
void add_entity(entity** arr, int* memlen, int* len, entity ent); void add_entity(entity** arr, int* memlen, int* len, entity* ent);
void project_to_camera(double x0, double y0, double z0, double* rx, double* ry, double* rz); void project_to_camera(double x0, double y0, double z0, double* rx, double* ry, double* rz);
void project_to_cube(double x0, double y0, double z0, double* rx, double* ry, double* rz, cube_0* c); void project_to_cube(double x0, double y0, double z0, double* rx, double* ry, double* rz, cube_0* c);

View File

@ -27,6 +27,13 @@ int MAX_SIZE = 8192 ;
int* drawOrder ; int* drawOrder ;
GLint loc_scale;
GLint loc_model;
GLint loc_view;
GLint loc_proj;
GLint loc_frag;
void init_draworder() { void init_draworder() {
drawOrder = malloc(sizeof(int)*6) ; drawOrder = malloc(sizeof(int)*6) ;
} }
@ -128,23 +135,24 @@ void gl_renderCube(unsigned int shaderProgram, unsigned int fragmentShader, unsi
glm_rotate(model, (float)(-c->hz_angle), (vec3){0.0f, 1.0f, 0.0f}); glm_rotate(model, (float)(-c->hz_angle), (vec3){0.0f, 1.0f, 0.0f});
glm_rotate(model, (float)(c->vt_angle), (vec3){1.0f, 0.0f, 0.0f}); glm_rotate(model, (float)(c->vt_angle), (vec3){1.0f, 0.0f, 0.0f});
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "scale"), 1, GL_FALSE, (float*)scale); glUniformMatrix4fv(loc_scale, 1, GL_FALSE, (float*)scale);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "model"), 1, GL_FALSE, (float*)model); glUniformMatrix4fv(loc_model, 1, GL_FALSE, (float*)model);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "view"), 1, GL_FALSE, (float*)view); glUniformMatrix4fv(loc_view, 1, GL_FALSE, (float*)view);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "projection"), 1, GL_FALSE, (float*)projection); glUniformMatrix4fv(loc_proj, 1, GL_FALSE, (float*)projection);
glUniform4f(glGetUniformLocation(fragmentShader, "u_color"), c->red/255.0f, c->green/255.0f, c->blue/255.0f, 1.0f); glUniform4f(loc_frag, c->red/255.0f, c->green/255.0f, c->blue/255.0f, 1.0f);
glDrawArrays(GL_TRIANGLES, 0, 36); glDrawArrays(GL_TRIANGLES, 0, 36);
triCount += 12; triCount += 12;
} }
double px, py, pz, pz2; double px, py, pz;
double px2, py2, pz2;
bool is_visible(cube_0* cb, double offx, double offy, double offz) { bool is_visible(cube_0* cb, double offx, double offy, double offz) {
for(int d = 0; d < 8; d++) { for(int d = 0; d < 8; d++) {
project_to_cube(cb->x+cb->w*(d%2==0)+offx, cb->y+cb->h*((d/2)%2==0)+offy, cb->z+cb->d*((d/4)%2==0)+offz, &px, &py, &pz, cb); project_to_cube(cb->x+cb->w*(d%2==0)+offx, cb->y+cb->h*((d/2)%2==0)+offy, cb->z+cb->d*((d/4)%2==0)+offz, &px, &py, &pz, cb);
project_to_camera(px, py, pz, NULL, NULL, &pz2); project_to_camera(px, py, pz, &px2, &py2, &pz2);
if(pz2 > near) { if(pz2 >= near) {
return true; return true;
} }
} }
@ -164,8 +172,8 @@ void gl_renderAll(unsigned int shaderProgram, unsigned int fragmentShader, unsig
} }
} }
for(int k = 0; k < rtd->ent_len; k++) { for(int k = 0; k < rtd->ent_len; k++) {
if(is_visible(rtd->ents[k].pos, offx, offy, offz)) { if(is_visible(rtd->ents[k]->pos, offx, offy, offz)) {
gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->ents[k].pos, offx, offy, offz); gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->ents[k]->pos, offx, offy, offz);
} }
} }
} }
@ -193,6 +201,13 @@ void gl_initRender(unsigned int shaderProgram, unsigned int fragmentShader, unsi
glm_lookat((vec3){(float)camx, (float)camy, (float)camz}, direction, (vec3){0.0f, 1.0f, 0.0f}, view); glm_lookat((vec3){(float)camx, (float)camy, (float)camz}, direction, (vec3){0.0f, 1.0f, 0.0f}, view);
glm_perspective(glm_rad((float)fov), 1500.0f / 1000.0f, 0.1f, 100.0f, projection); glm_perspective(glm_rad((float)fov), 1500.0f / 1000.0f, 0.1f, 100.0f, projection);
loc_scale = glGetUniformLocation(shaderProgram, "scale");
loc_model = glGetUniformLocation(shaderProgram, "model");
loc_view = glGetUniformLocation(shaderProgram, "view");
loc_proj = glGetUniformLocation(shaderProgram, "projection");
loc_frag = glGetUniformLocation(fragmentShader, "u_color");
} }
void gl_drawData(unsigned int shaderProg) { void gl_drawData(unsigned int shaderProg) {
@ -200,5 +215,9 @@ void gl_drawData(unsigned int shaderProg) {
gl_drawInteger(shaderProg, (int)camy, 0.95f, 0.75f, 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, 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);
gl_drawInteger(shaderProg, (int)10.0*camvz, 0.95f, -0.9f, 0.05f, 255, 255, 255, 0.005, -1);
gl_drawInteger(shaderProg, player_hp, -0.95f, 0.9f, 0.05f, 255-player_hp/4, player_hp/4, 0, 0.005f, 1); gl_drawInteger(shaderProg, player_hp, -0.95f, 0.9f, 0.05f, 255-player_hp/4, player_hp/4, 0, 0.005f, 1);
} }

View File

@ -42,25 +42,25 @@ bool is_colliding_with_tp(cube_0* cb) {
// ------------------------------------------------------------------------------------------------------------------------------------------------ // // ------------------------------------------------------------------------------------------------------------------------------------------------ //
void update_entity(entity* ent, float dtime) { void update_entity(entity* ent, float dtime) {
(*ent->updatePos)(ent->pos->x, ent->pos->y, ent->pos->z, ent->pos->w, ent->pos->h, ent->pos->d, ent->pos->hz_angle, ent->pos->vt_angle, dtime, ent->pos); (*ent->updatePos)(ent->pos->x, ent->pos->y, ent->pos->z, ent->pos->w, ent->pos->h, ent->pos->d, ent->pos->hz_angle, ent->pos->vt_angle, dtime, ent, ent->pos);
} }
void update_entities(float dtime) { void update_entities(float dtime) {
for(int k = 0; k < current_room->ent_len; k++) { for(int k = 0; k < current_room->ent_len; k++) {
if(current_room->ents[k].updatePos != NULL) { if(current_room->ents[k]->updatePos != NULL) {
//printf("e\n"); //printf("e\n");
update_entity(&(current_room->ents[k]), dtime); update_entity(current_room->ents[k], dtime);
} }
} }
} }
// ------------------------------------------------------------------------------------------------------------------------------------------------ // // ------------------------------------------------------------------------------------------------------------------------------------------------ //
void speen(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, cube_0* ret) { void speen(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) {
ret->hz_angle += ((double)dtime)*15.0; ret->hz_angle += ((double)dtime)*15.0;
} }
void speen2(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, cube_0* ret) { void speen2(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) {
ret->hz_angle += ((double)dtime)*22.5; ret->hz_angle += ((double)dtime)*22.5;
if((int)(5.0*ret->hz_angle) != (int)(5.0*(ret->hz_angle - ((double)dtime)*22.5))) { if((int)(5.0*ret->hz_angle) != (int)(5.0*(ret->hz_angle - ((double)dtime)*22.5))) {
double dx = (x+w/2 - camx); double dx = (x+w/2 - camx);
@ -74,11 +74,23 @@ void speen2(double x, double y, double z, double w, double h, double d, double h
} }
} }
void speen3(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, cube_0* ret) { void speen3(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) {
ret->vt_angle += ((double)dtime)*22.5; ret->vt_angle += ((double)dtime)*22.5;
} }
void detectHit(float dtime, int* hp, int* dmg, cube_0* ret) { // metad{1,2,3} = og pos
// metad{4,5,6} = amplitudes
// metai{1} = frequency multiplier
// metai{2} = frequency divider
// metai{3} = phase
void moving_xyz(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) {
ret->x = ent->metad1 + ent->metad4*cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0));
ret->y = ent->metad2 + ent->metad5*cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0));
ret->z = ent->metad3 + ent->metad6*cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0));
//printf("%lf %lf %lf\n", ret->x, ret->y, ret->z);
}
void detectHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
if(ret->red == 193) { if(ret->red == 193) {
ret->red = 0; ret->red = 0;
ret->green = 192; ret->green = 192;
@ -92,7 +104,35 @@ void detectHit(float dtime, int* hp, int* dmg, cube_0* ret) {
} }
} }
void go_to_player(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, cube_0* ret) { void translatePlayer(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
double vx = 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 vy = 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 vz = 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)));
//printf("(%lf %lf) (%lf %lf) (%lf %lf)\n", vx, camvx, vy, camvy, vz, camvz);
if(true) {
double oldvx = camvx;
camvx += vx/dtime;
camx -= oldvx*dtime;
camx += camvx*dtime;
noResetSpeed = true;
}
if(true) {
double oldvy = camvy;
camvy += vy/dtime;
camy -= oldvy*dtime;
camy += camvy*dtime;
noResetSpeed = true;
}
if(true) {
double oldvz = camvz;
camvz += vz/dtime;
camz -= oldvz*dtime;
camz += camvz*dtime;
noResetSpeed = true;
}
}
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) {
double dx = (x+w/2 - camx); double dx = (x+w/2 - camx);
double dy = (y+h/2 - camy); double dy = (y+h/2 - camy);
double dz = (z+d/2 - camz); double dz = (z+d/2 - camz);
@ -117,7 +157,7 @@ void go_to_player(double x, double y, double z, double w, double h, double d, do
} }
} }
void explodeOnHit(float dtime, int* hp, int* dmg, cube_0* ret) { void explodeOnHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
player_hp -= (*dmg); player_hp -= (*dmg);
if(*dmg != 0) { if(*dmg != 0) {
fade_dmg = 255; fade_dmg = 255;

View File

@ -7,13 +7,14 @@ bool is_colliding_with_tp(cube_0* cb);
void update_entity(entity* ent, float dtime); void update_entity(entity* ent, float dtime);
void update_entities(float dtime); void update_entities(float dtime);
void speen(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, cube_0* ret); void speen(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 speen2(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, cube_0* ret); void speen2(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 speen3(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, cube_0* ret); void speen3(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 moving_xyz(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 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 go_to_player(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, cube_0* ret); void detectHit(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 detectHit(float dtime, int* hp, int* dmg, cube_0* ret); void translatePlayer(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret);
void explodeOnHit(float dtime, int* hp, int* dmg, cube_0* ret);
#endif #endif

View File

@ -59,6 +59,12 @@ void init_ent_generator(int n) {
hashtbl_entities[3].updatePos = &speen3; hashtbl_entities[3].updatePos = &speen3;
hashtbl_entities[3].onHit = &explodeOnHit; hashtbl_entities[3].onHit = &explodeOnHit;
hashtbl_entities[3].onDeath = NULL; hashtbl_entities[3].onDeath = NULL;
hashtbl_entities[4].id = 4;
hashtbl_entities[4].name = "Platform";
hashtbl_entities[4].updatePos = &moving_xyz;
hashtbl_entities[4].onHit = &translatePlayer;
hashtbl_entities[4].onDeath = NULL;
} }
fct_entry* get_entry(int k0) { fct_entry* get_entry(int k0) {
@ -97,21 +103,39 @@ void copy_room(room* src, room* dest, int chx, int chy) {
dest->tps[k]->dest_y = src->tps[k]->dest_y; dest->tps[k]->dest_y = src->tps[k]->dest_y;
dest->tps[k]->dest_z = src->tps[k]->dest_z; dest->tps[k]->dest_z = src->tps[k]->dest_z;
} }
dest->ents = malloc(sizeof(entity)*src->ent_memlen); dest->ents = malloc(sizeof(entity*)*src->ent_memlen);
dest->ent_memlen = src->ent_memlen; dest->ent_memlen = src->ent_memlen;
dest->ent_len = src->ent_len; dest->ent_len = src->ent_len;
for(int k = 0; k < src->ent_len; k++) { for(int k = 0; k < src->ent_len; k++) {
dest->ents[k].damage = src->ents[k].damage ; dest->ents[k] = malloc(sizeof(entity));
dest->ents[k].hitpoints = malloc(sizeof(int)); dest->ents[k]->damage = src->ents[k]->damage;
*(dest->ents[k].hitpoints) = *(src->ents[k].hitpoints) ; dest->ents[k]->hitpoints = malloc(sizeof(int));
dest->ents[k].pos = create_cube_0( dest->ents[k]->metai1 = src->ents[k]->metai1;
(*(src->ents[k].pos)).x, (*(src->ents[k].pos)).y, (*(src->ents[k].pos)).z, dest->ents[k]->metai2 = src->ents[k]->metai2;
(*(src->ents[k].pos)).w, (*(src->ents[k].pos)).h, (*(src->ents[k].pos)).d, dest->ents[k]->metai3 = src->ents[k]->metai3;
(*(src->ents[k].pos)).hz_angle, (*(src->ents[k].pos)).vt_angle, (*(src->ents[k].pos)).red, (*(src->ents[k].pos)).green, (*(src->ents[k].pos)).blue dest->ents[k]->metai4 = src->ents[k]->metai4;
dest->ents[k]->metai5 = src->ents[k]->metai5;
dest->ents[k]->metai6 = src->ents[k]->metai6;
dest->ents[k]->metad1 = src->ents[k]->metad1;
dest->ents[k]->metad2 = src->ents[k]->metad2;
dest->ents[k]->metad3 = src->ents[k]->metad3;
dest->ents[k]->metad4 = src->ents[k]->metad4;
dest->ents[k]->metad5 = src->ents[k]->metad5;
dest->ents[k]->metad6 = src->ents[k]->metad6;
*(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,
(*(src->ents[k]->pos)).w, (*(src->ents[k]->pos)).h, (*(src->ents[k]->pos)).d,
(*(src->ents[k]->pos)).hz_angle, (*(src->ents[k]->pos)).vt_angle, (*(src->ents[k]->pos)).red, (*(src->ents[k]->pos)).green, (*(src->ents[k]->pos)).blue
); );
dest->ents[k].updatePos = src->ents[k].updatePos; dest->ents[k]->updatePos = src->ents[k]->updatePos;
dest->ents[k].onHit = src->ents[k].onHit; dest->ents[k]->onHit = src->ents[k]->onHit;
dest->ents[k].onDeath = src->ents[k].onDeath; dest->ents[k]->onDeath = src->ents[k]->onDeath;
}
for(int k = src->ent_len; k < src->ent_memlen; k++) {
dest->ents[k] = malloc(sizeof(entity));
dest->ents[k]->hitpoints = malloc(sizeof(int));
dest->ents[k]->pos = malloc(sizeof(cube_0));
} }
dest->tps_size = src->tps_size; dest->tps_size = src->tps_size;
} }
@ -140,16 +164,20 @@ void build_starting_chunk(int chx, int chy) {
new->tps[2] = create_teleporter(5.0, 1.0, 2.0, 1.0, 2.0 + (double)(rand()%2), 1.0, 0.0, 0.0, 0, 255, 0 , chx+1, chy , 2.5, 2.5, 2.5); new->tps[2] = create_teleporter(5.0, 1.0, 2.0, 1.0, 2.0 + (double)(rand()%2), 1.0, 0.0, 0.0, 0, 255, 0 , chx+1, chy , 2.5, 2.5, 2.5);
new->tps[3] = create_teleporter(2.0, 1.0, 5.0, 1.0, 2.0 + (double)(rand()%2), 1.0, 0.0, 0.0, 0, 0, 255 , chx , chy+1, 2.5, 2.5, 2.5); new->tps[3] = create_teleporter(2.0, 1.0, 5.0, 1.0, 2.0 + (double)(rand()%2), 1.0, 0.0, 0.0, 0, 0, 255 , chx , chy+1, 2.5, 2.5, 2.5);
new->ents = malloc(sizeof(entity)*128); new->ents = malloc(sizeof(entity*)*32);
for(int k = 0; k < 32; k++) {
new->ents[k] = malloc(sizeof(entity));
new->ents[k]->hitpoints = malloc(sizeof(int));
new->ents[k]->pos = malloc(sizeof(cube_0));
};
new->ent_len = 1; new->ent_len = 1;
new->ent_memlen = 128 ; new->ent_memlen = 32;
new->ents[0].pos = create_cube_0(-0.25, 8.25, -0.25, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 128, 0); fill_cube_0(new->ents[0]->pos, -0.25, 8.25, -0.25, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 128, 0);
new->ents[0].damage = 0 ; new->ents[0]->damage = 0;
new->ents[0].hitpoints = malloc(sizeof(int)); *(new->ents[0]->hitpoints) = 5;
*(new->ents[0].hitpoints) = 5 ; new->ents[0]->onDeath = NULL;
new->ents[0].onDeath = NULL ; new->ents[0]->onHit = *detectHit;
new->ents[0].onHit = *detectHit ; new->ents[0]->updatePos = *speen2;
new->ents[0].updatePos = *speen2 ;
hashtbl_add(visited, chx, chy, new); hashtbl_add(visited, chx, chy, new);
} }
@ -255,10 +283,7 @@ void parse_one_room(int id, char* filename) {
get_number_blocks(&ncubes, &ntps, &nent, ptr2); get_number_blocks(&ncubes, &ntps, &nent, ptr2);
printf("(%d, %d, %d)\n", ncubes, ntps, nent); printf("(%d, %d, %d)\n", ncubes, ntps, nent);
int nmemlen = 128 ; int nmemlen = maxd(nent, 64);
while(nmemlen < nent) {
nmemlen *= 2.;
}
pool[id].area->map = malloc(sizeof(cube_0*)*ncubes); pool[id].area->map = malloc(sizeof(cube_0*)*ncubes);
pool[id].area->map_size = ncubes; pool[id].area->map_size = ncubes;
@ -267,7 +292,12 @@ void parse_one_room(int id, char* filename) {
pool[id].area->tps[k] = malloc(sizeof(teleporter)); pool[id].area->tps[k] = malloc(sizeof(teleporter));
} }
pool[id].area->tps_size = ntps; pool[id].area->tps_size = ntps;
pool[id].area->ents = malloc(sizeof(entity)*nmemlen); pool[id].area->ents = malloc(sizeof(entity*)*nmemlen);
for(int k = 0; k < nmemlen; k++) {
pool[id].area->ents[k] = malloc(sizeof(entity));
pool[id].area->ents[k]->hitpoints = malloc(sizeof(int));
pool[id].area->ents[k]->pos = malloc(sizeof(cube_0));
}
pool[id].area->ent_len = nent; pool[id].area->ent_len = nent;
pool[id].area->ent_memlen = nmemlen; pool[id].area->ent_memlen = nmemlen;
@ -336,17 +366,44 @@ void parse_one_room(int id, char* filename) {
if(entry == NULL) { if(entry == NULL) {
entry = get_entry(0); entry = get_entry(0);
} }
pool[id].area->ents[k].pos = create_cube_0(cx, cy, cz, cw, ch, cd, chz, cvt, red, green, blue); fill_cube_0(pool[id].area->ents[k]->pos, cx, cy, cz, cw, ch, cd, chz, cvt, red, green, blue);
pool[id].area->ents[k].damage = dmg ; pool[id].area->ents[k]->damage = dmg;
pool[id].area->ents[k].hitpoints = malloc(sizeof(int)); *(pool[id].area->ents[k]->hitpoints) = hp;
*(pool[id].area->ents[k].hitpoints) = hp ; pool[id].area->ents[k]->updatePos = entry->updatePos;
pool[id].area->ents[k]->onHit = entry->onHit ;
pool[id].area->ents[k].updatePos = entry->updatePos ; pool[id].area->ents[k]->onDeath = entry->onDeath ;
pool[id].area->ents[k].onHit = entry->onHit ; pool[id].area->ents[k]->metai1 = entry->metai1;
pool[id].area->ents[k].onDeath = entry->onDeath ; pool[id].area->ents[k]->metai2 = entry->metai2;
//pool[id].area->ents[k].updatePos = &speen2 ; pool[id].area->ents[k]->metai3 = entry->metai3;
//pool[id].area->ents[k].onHit = &detectHit ; pool[id].area->ents[k]->metai4 = entry->metai4;
//pool[id].area->ents[k].onDeath = NULL ; pool[id].area->ents[k]->metai5 = entry->metai5;
pool[id].area->ents[k]->metai6 = entry->metai6;
pool[id].area->ents[k]->metad1 = entry->metad1;
pool[id].area->ents[k]->metad2 = entry->metad2;
pool[id].area->ents[k]->metad3 = entry->metad3;
pool[id].area->ents[k]->metad4 = entry->metad4;
pool[id].area->ents[k]->metad5 = entry->metad5;
pool[id].area->ents[k]->metad6 = entry->metad6;
if(entry->id == 4) {
double ccw = read_float(ptr);
double cch = read_float(ptr);
double ccd = read_float(ptr);
int mult = read_int(ptr, true);
int divd = read_int(ptr, true);
int phase = read_int(ptr, true);
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 = ccw;
pool[id].area->ents[k]->metad5 = cch;
pool[id].area->ents[k]->metad6 = ccd;
pool[id].area->ents[k]->metai1 = mult;
pool[id].area->ents[k]->metai2 = divd;
pool[id].area->ents[k]->metai3 = phase;
}
//pool[id].area->ents[k]->updatePos = &speen2;
//pool[id].area->ents[k]->onHit = &detectHit ;
//pool[id].area->ents[k]->onDeath = NULL ;
//printf("\n"); //printf("\n");
} }
@ -354,7 +411,7 @@ void parse_one_room(int id, char* filename) {
fflush(stdout); fflush(stdout);
// debug // debug
for(int k = 0; k < ncubes; k++) { /*for(int k = 0; k < ncubes; k++) {
printf("(%lf, %lf, %lf), (%lf, %lf, %lf), (%lf, %lf), (%d, %d, %d)\n", printf("(%lf, %lf, %lf), (%lf, %lf, %lf), (%lf, %lf), (%d, %d, %d)\n",
pool[id].area->map[k]->x, pool[id].area->map[k]->x,
pool[id].area->map[k]->y, pool[id].area->map[k]->y,
@ -368,15 +425,14 @@ void parse_one_room(int id, char* filename) {
pool[id].area->map[k]->green, pool[id].area->map[k]->green,
pool[id].area->map[k]->blue pool[id].area->map[k]->blue
); );
} }*/
printf("OK\n");
fflush(stdout);
printf("\n\n");
pool[id].weight = read_int(ptr, true); pool[id].weight = read_int(ptr, true);
total_weight += pool[id].weight; total_weight += pool[id].weight;
printf("(w = %d) OK\n", pool[id].weight);
fflush(stdout);
printf("\n\n");
fclose(ptr); fclose(ptr);
} }
@ -408,6 +464,7 @@ void parse_rooms(int n_rooms) {
printf("Parsing...\n"); printf("Parsing...\n");
for(int k = 0; k < n_rooms; k++) { for(int k = 0; k < n_rooms; k++) {
printf("parsing %d...", k);
if(k < 10) { if(k < 10) {
name[15] = (char)(k%10 + 48); name[15] = (char)(k%10 + 48);
} else if(k < 100) { } else if(k < 100) {
@ -415,6 +472,7 @@ void parse_rooms(int n_rooms) {
name[16] = (char)(k%10 + 48); name[16] = (char)(k%10 + 48);
} }
parse_one_room(k, name); parse_one_room(k, name);
printf("done.\n");
} }
printf("\nDone.\n"); printf("\nDone.\n");
@ -423,14 +481,14 @@ void parse_rooms(int n_rooms) {
free(name); free(name);
} }
int divider = 8; // has to be a multiple of both room_width and room_depth
int divider = 4;
void generate_terrain(room* r) { 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) int rsize = 4*(room_width/divider)*(room_width/divider)*(room_depth/divider)*(room_depth/divider); // floor size (with 1x1 cubes)
cube** newMap = malloc(sizeof(cube_0*)*(rsize+r->map_size)); cube_0** newMap = malloc(sizeof(cube_0*)*(rsize+r->map_size));
for(int k = 0; k < rsize+r->map_size; k++) { for(int k = 0; k < rsize+r->map_size; k++) {
newMap[k] = malloc(sizeof(cube_0)); newMap[k] = malloc(sizeof(cube_0));
} }
for(int k = 0; k < r->map_size; k++) { for(int k = 0; k < r->map_size; k++) {
@ -443,7 +501,7 @@ void generate_terrain(room* r) {
int i = r->map_size; int i = r->map_size;
for(int l = -room_width; l < room_width; l+=divider) { for(int l = -room_width; l < room_width; l+=divider) {
for(int d = -room_depth; d < room_depth; d+=divider) { for(int d = -room_depth; d < room_depth; d+=divider) {
newMap[i] = create_cube_0((double)l, -20.0, (double)d, (double)divider, 1.0, (double)divider, 0.0, 0.0,32, 128, 32); fill_cube_0(newMap[i], (double)l, -20.0, (double)d, (double)divider, 1.0, (double)divider, 0.0, 0.0,32, 128, 32);
i+=1; i+=1;
} }
} }
@ -459,6 +517,7 @@ void generate_nearby_chunks(int render_dist) {
printf("generating (%d, %d)... ", player_chx + w, player_chy + h); printf("generating (%d, %d)... ", player_chx + w, player_chy + h);
//build_starting_chunk(player_chx + w, player_chy + h); //build_starting_chunk(player_chx + w, player_chy + h);
int pick = rand()%total_weight; int pick = rand()%total_weight;
printf("R = %d ", pick);
int sum = 0; int sum = 0;
for(int k = 0; k < pool_size; k++) { for(int k = 0; k < pool_size; k++) {
sum += pool[k].weight; sum += pool[k].weight;
@ -466,11 +525,12 @@ void generate_nearby_chunks(int render_dist) {
printf("chose %d\n", k); printf("chose %d\n", k);
room* new = malloc(sizeof(room)); room* new = malloc(sizeof(room));
copy_room(pool[k].area, new, player_chx + w, player_chy + h); copy_room(pool[k].area, new, player_chx + w, player_chy + h);
generate_terrain(new); //generate_terrain(new);
hashtbl_add(visited, player_chx + w, player_chy + h, new); hashtbl_add(visited, player_chx + w, player_chy + h, new);
k = pool_size+1; k = pool_size+1;
} }
} }
printf("Done\n");
} }
} }
} }
@ -485,9 +545,10 @@ void free_pool() {
free(pool[k0].area->tps[k]->hitbox); free(pool[k0].area->tps[k]->hitbox);
free(pool[k0].area->tps[k]); free(pool[k0].area->tps[k]);
} }
for(int k = 0; k < pool[k0].area->ent_len; k++) { for(int k = 0; k < pool[k0].area->ent_memlen; k++) {
free(pool[k0].area->ents[k].hitpoints); free(pool[k0].area->ents[k]->hitpoints);
free(pool[k0].area->ents[k].pos); free(pool[k0].area->ents[k]->pos);
free(pool[k0].area->ents[k]);
} }
free(pool[k0].area->ents); free(pool[k0].area->ents);
free(pool[k0].area->tps); free(pool[k0].area->tps);

View File

@ -9,11 +9,25 @@ typedef struct entry {
typedef struct fct_entry { typedef struct fct_entry {
int id ; int id ;
char* name ; char* name ;
void (*updatePos)(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, cube_0* ret) ; void (*updatePos)(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) ;
// act as velocity function // act as velocity function
void (*onHit)(float dtime, int* hp, int* dmg, cube_0* ret) ; void (*onHit)(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) ;
// triggers when object is hit // triggers when object is hit
void (*onDeath)(float dtime) ; void (*onDeath)(float dtime) ;
// metadata //
int metai1;
int metai2;
int metai3;
int metai4;
int metai5;
int metai6;
double metad1;
double metad2;
double metad3;
double metad4;
double metad5;
double metad6;
} fct_entry ; } fct_entry ;
void init_ent_generator(int n); void init_ent_generator(int n);

View File

@ -65,9 +65,10 @@ void free_all_cubes(room* r) {
free(r->tps[k]->hitbox); free(r->tps[k]->hitbox);
free(r->tps[k]); free(r->tps[k]);
} }
for(int k = 0; k < r->ent_len; k++) { for(int k = 0; k < r->ent_memlen; k++) {
free(r->ents[k].hitpoints); free(r->ents[k]->hitpoints);
free(r->ents[k].pos); free(r->ents[k]->pos);
free(r->ents[k]);
} }
free(r->ents); free(r->ents);
free(r->tps); free(r->tps);

View File

@ -28,6 +28,7 @@ void processInput(GLFWwindow *window, float dtime) {
glfwSetWindowShouldClose(window, true); glfwSetWindowShouldClose(window, true);
} }
if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) { if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
/*
for(int k = 0; k < 10; k++) { for(int k = 0; k < 10; k++) {
camz -= speed*cos(rot_hz)*cos(rot_vt)/10; camz -= speed*cos(rot_hz)*cos(rot_vt)/10;
camx -= speed*sin(rot_hz)*cos(rot_vt)/10; camx -= speed*sin(rot_hz)*cos(rot_vt)/10;
@ -39,8 +40,13 @@ void processInput(GLFWwindow *window, float dtime) {
k=11; k=11;
} }
} }
*/
camvz = -speed*cos(rot_hz)*cos(rot_vt);
camvx = -speed*sin(rot_hz)*cos(rot_vt);
camvy = vtmult*speed*sin(rot_vt);
} }
if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) { if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
/*
for(int k = 0; k < 10; k++) { for(int k = 0; k < 10; k++) {
camx -= speed*cos(rot_hz)/10; camx -= speed*cos(rot_hz)/10;
camz += speed*sin(rot_hz)/10; camz += speed*sin(rot_hz)/10;
@ -49,10 +55,12 @@ void processInput(GLFWwindow *window, float dtime) {
camz -= speed*sin(rot_hz)/10; camz -= speed*sin(rot_hz)/10;
k=11; k=11;
} }
} }*/
camvx = -speed*cos(rot_hz);
camvz = speed*sin(rot_hz);
} }
if(glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) { if(glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) {
for(int k = 0; k < 10; k++) { /*for(int k = 0; k < 10; k++) {
camz += speed*cos(rot_hz)*cos(rot_vt)/10; camz += speed*cos(rot_hz)*cos(rot_vt)/10;
camx += speed*sin(rot_hz)*cos(rot_vt)/10; camx += speed*sin(rot_hz)*cos(rot_vt)/10;
camy -= speed*sin(rot_vt)/10; camy -= speed*sin(rot_vt)/10;
@ -62,10 +70,13 @@ void processInput(GLFWwindow *window, float dtime) {
camy += speed*sin(rot_vt)/10; camy += speed*sin(rot_vt)/10;
k=11; k=11;
} }
} }*/
camvz = speed*cos(rot_hz)*cos(rot_vt);
camvx = speed*sin(rot_hz)*cos(rot_vt);
camvy = -vtmult*speed*sin(rot_vt);
} }
if(glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) { if(glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) {
for(int k = 0; k < 10; k++) { /*for(int k = 0; k < 10; k++) {
camx += speed*cos(rot_hz)/10; camx += speed*cos(rot_hz)/10;
camz -= speed*sin(rot_hz)/10; camz -= speed*sin(rot_hz)/10;
if(is_colliding(dtime)) { if(is_colliding(dtime)) {
@ -73,11 +84,14 @@ void processInput(GLFWwindow *window, float dtime) {
camz += speed*sin(rot_hz)/10; camz += speed*sin(rot_hz)/10;
k=11; k=11;
} }
} }*/
camvx = speed*cos(rot_hz);
camvz = -speed*sin(rot_hz);
} }
if(glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) { if(glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) {
stop_evetything = true ; camvx = 0.0;
camvz = 0.0;
} }
if(glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) { if(glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) {
@ -88,10 +102,10 @@ void processInput(GLFWwindow *window, float dtime) {
} }
if(glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS) { if(glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS) {
rot_vt -= sensitivity; rot_vt = maxd(-3.14159/2.0, rot_vt-sensitivity);
} }
if(glfwGetKey(window, GLFW_KEY_M) == GLFW_PRESS) { if(glfwGetKey(window, GLFW_KEY_M) == GLFW_PRESS) {
rot_vt += sensitivity; rot_vt = mind(3.14159/2.0, rot_vt+sensitivity);
} }
} }
@ -164,7 +178,7 @@ int main_alt() {
init_hashtbl(); init_hashtbl();
init_ent_generator(10); init_ent_generator(10);
init_proj(); init_proj();
parse_rooms(5); parse_rooms(6);
// ---------------------------------------------------------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------------------------------------------------------- //
// ---------------------------------------------------------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------------------------------------------------------- //
@ -289,19 +303,24 @@ int main_alt() {
int fps = 60; int fps = 60;
int interval = 1000000/fps; int interval = 1000000/fps;
double slp_time = 1.0/fps;
float delta = 0.0f;
double deltad = 0.0;
clock_t finish = clock(); clock_t finish = clock();
clock_t origin = clock(); clock_t origin = clock();
while(!glfwWindowShouldClose(window) && player_hp >= 0) { while(!glfwWindowShouldClose(window) && player_hp > 0) {
// input // input
// ----- // -----
glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
triCount = 0; triCount = 0;
origin = clock();
fflush(stdout);
generate_nearby_chunks(1); generate_nearby_chunks(1);
fflush(stdout);
// draw the map // draw the map
glUseProgram(shaderProgram); glUseProgram(shaderProgram);
@ -315,28 +334,30 @@ int main_alt() {
glUseProgram(shaderProgramR); glUseProgram(shaderProgramR);
glBindVertexArray(RVAO); glBindVertexArray(RVAO);
finish = clock(); gl_drawInteger(shaderProgramR, (int)(1.0f/(delta)), 0.0f, -0.92f, 0.05, 32, 255, 32, 0.005, -1);
gl_drawInteger(shaderProgramR, (int)(1.0f/(((float)finish - (float)origin)/CLOCKS_PER_SEC)), 0.9f, -0.85f, 0.05, 32, 255, 32, 0.005, -1);
gl_drawInteger(shaderProgramR, triCount, 0.0f, 0.92f, 0.04f, 128, 128, 128, 0.005f, 1); gl_drawInteger(shaderProgramR, triCount, 0.0f, 0.92f, 0.04f, 128, 128, 128, 0.005f, 1);
gl_drawData(shaderProgramR); gl_drawData(shaderProgramR);
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
processInput(window, ((float)finish - (float)origin)/CLOCKS_PER_SEC); processInput(window, delta);
movePlayerG(deltad);
teleport_on_edge(); teleport_on_edge();
update_entities(((float)finish - (float)origin)/CLOCKS_PER_SEC); update_entities(delta);
updateProj(((float)finish - (float)origin)/CLOCKS_PER_SEC); updateProj(delta);
//printf("%f\n", 1.0f/(((float)finish - (float)origin)/CLOCKS_PER_SEC));
//printf("%lf, %lf, %lf\n", camx, camy, camz);
usleep(interval); usleep(max(0, interval-(int)(1000000*delta)));
sim_time += deltad;
glfwSwapBuffers(window); glfwSwapBuffers(window);
glfwPollEvents(); glfwPollEvents();
finish = clock();
delta = slp_time+((float)finish - (float)origin)/CLOCKS_PER_SEC;
deltad = slp_time+((double)finish - (double)origin)/CLOCKS_PER_SEC;
origin = clock();
} }
//printf("10\n");
//fflush(stdout);
hashtbl_free(visited); hashtbl_free(visited);
free_proj(); free_proj();
free_pool(); free_pool();
@ -356,5 +377,6 @@ int main_alt() {
int main(int argc, char** argv) { int main(int argc, char** argv) {
srand(time(NULL)); srand(time(NULL));
triCount = 0; triCount = 0;
sim_time = 0.0;
return main_alt(); return main_alt();
} }

View File

@ -18,8 +18,13 @@
// ---------------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------------- //
double sensitivity = 0.06; double sensitivity = 0.06;
double fov = 90.0; double fov = 90.0;
double speed = 0.22; double creative_speed = 0.3;
double speed = 8.0;
double vtmult = 1.5;
double min_dist = 0.7; double min_dist = 0.7;
double friction = 0.8;
double gravity_factor = 9.8;
bool noResetSpeed = false;
// ---------------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------------- //
int player_hp; int player_hp;
@ -30,6 +35,9 @@ double camx;
double camy; double camy;
double camz; double camz;
double camvx;
double camvy;
double camvz;
double rot_hz; double rot_hz;
double rot_vt; double rot_vt;
@ -47,6 +55,9 @@ void init_csts() {
camx = 2.0; camx = 2.0;
camy = 5.0; camy = 5.0;
camz = 2.0; camz = 2.0;
camvx = 0.0;
camvy = 0.0;
camvz = 0.0;
rot_hz = 0.0; rot_hz = 0.0;
rot_vt = 0.0; rot_vt = 0.0;
draw_type = 0; draw_type = 0;
@ -92,15 +103,15 @@ bool is_colliding(float dtime) {
} }
} }
for(int k = 0; k < current_room->ent_len; k++) { for(int k = 0; k < current_room->ent_len; k++) {
double dist = distance_pt_cube_0_3d(camx, camy, camz, current_room->ents[k].pos); double dist = distance_pt_cube_0_3d(camx, camy, camz, current_room->ents[k]->pos);
if(dist <= min_dist) { if(dist <= min_dist) {
if(current_room->ents[k].onHit != NULL) { if(current_room->ents[k]->onHit != NULL) {
(*current_room->ents[k].onHit)(dtime, current_room->ents[k].hitpoints, &current_room->ents[k].damage, &(*(current_room->ents[k].pos))); (*current_room->ents[k]->onHit)(dtime, current_room->ents[k]->hitpoints, &current_room->ents[k]->damage, current_room->ents[k], &(*(current_room->ents[k]->pos)));
if(*(current_room->ents[k].hitpoints) <= 0) { if(*(current_room->ents[k]->hitpoints) <= 0) {
if(current_room->ents[k].onDeath != NULL) { if(current_room->ents[k]->onDeath != NULL) {
(*current_room->ents[k].onDeath)(dtime); (*current_room->ents[k]->onDeath)(dtime);
} }
remove_entity(&current_room->ents, &current_room->ent_memlen, &current_room->ent_len, k); remove_entity(current_room->ents, &current_room->ent_memlen, &current_room->ent_len, k);
} }
} }
return true; return true;
@ -109,6 +120,39 @@ bool is_colliding(float dtime) {
return false; return false;
} }
void movePlayerG(double dtime) {
camx += camvx*dtime;
noResetSpeed = false;
if(is_colliding(dtime)) {
camx -= camvx*dtime;
if(!noResetSpeed) {
camvx = 0.0;
}
}
camvx = camvx*(1-dtime*friction);
camvy -= gravity_factor*dtime;
camy += camvy*dtime;
noResetSpeed = false;
if(is_colliding(dtime)) {
camy -= camvy*dtime;
if(!noResetSpeed) {
camvy = 0.0;
}
}
camvy = camvy*(1-dtime*friction);
camz += camvz*dtime;
noResetSpeed = false;
if(is_colliding(dtime)) {
camz -= camvz*dtime;
if(!noResetSpeed) {
camvz = 0.0;
}
}
camvz = camvz*(1-dtime*friction);
}
void teleport_on_edge() { void teleport_on_edge() {
if(camx >= room_width) { if(camx >= room_width) {
camx -= 2.0*room_width; camx -= 2.0*room_width;

View File

@ -5,5 +5,6 @@ void init_csts();
bool is_colliding(float dtime); bool is_colliding(float dtime);
void teleport_on_edge(); void teleport_on_edge();
void movePlayerG(double dtime);
#endif #endif

View File

@ -33,14 +33,27 @@ typedef struct teleporter {
typedef struct entity { typedef struct entity {
cube_0* pos; cube_0* pos;
// act as velocity function // act as velocity function
void (*updatePos)(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, cube_0* ret); void (*updatePos)(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, struct entity* ent, cube_0* ret);
// triggers when object is hit // triggers when object is hit
void (*onHit)(float dtime, int* hp, int* dmg, cube_0* ret); void (*onHit)(float dtime, int* hp, int* dmg, struct entity* ent, cube_0* ret);
// triggers when <hitpoints> goes negative (death) // triggers when <hitpoints> goes negative (death)
void (*onDeath)(float dtime); void (*onDeath)(float dtime);
int metai1;
int metai2;
int metai3;
int metai4;
int metai5;
int metai6;
double metad1;
double metad2;
double metad3;
double metad4;
double metad5;
double metad6;
int damage; int damage;
int* hitpoints; int* hitpoints;
} entity; } entity;
@ -53,7 +66,7 @@ struct room {
int map_size; int map_size;
teleporter** tps; teleporter** tps;
int tps_size; int tps_size;
entity* ents; entity** ents;
int ent_len; int ent_len;
int ent_memlen; int ent_memlen;
}; };
@ -86,6 +99,14 @@ extern double camx;
extern double camy; extern double camy;
extern double camz; extern double camz;
extern double camvx;
extern double camvy;
extern double camvz;
extern double friction;
extern double vtmult;
extern double gravity_factor;
extern double rot_hz; extern double rot_hz;
extern double rot_vt; extern double rot_vt;
@ -126,4 +147,6 @@ extern float rectDefault[18];
extern int triCount; extern int triCount;
extern bool noResetSpeed;
#endif #endif

View File

@ -12,7 +12,17 @@ Teleporters :
[4.0, 1.0, 9.0, 2.0, 4.0, 1.0, 0.0, 0.0, 0, 255, 0; 0, 1] [4.0, 1.0, 9.0, 2.0, 4.0, 1.0, 0.0, 0.0, 0, 255, 0; 0, 1]
[9.0, 1.0, 4.0, 1.0, 4.0, 2.0, 0.0, 0.0, 0, 0, 255; 1, 0] [9.0, 1.0, 4.0, 1.0, 4.0, 2.0, 0.0, 0.0, 0, 0, 255; 1, 0]
Entities:
[0.0, 14.0, 0.0, 2.0, 1.0, 2.0, 0.0, 0.0, 193, 192, 0, 1, 0, 4, 0.0, 5.0, 0.0, 4, 1, 45]
Weight : Weight :
10 50
$ $
entities:
[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..]
if entityType = 4
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd]
else
[..]

View File

@ -22,6 +22,13 @@ Entities :
[0.0, 10.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0] [0.0, 10.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0]
Weight : Weight :
60 50
$ $
entities:
[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..]
if entityType = 4
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd]
else
[..]

View File

@ -23,3 +23,10 @@ Weight :
50 50
$ $
entities:
[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..]
if entityType = 4
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd]
else
[..]

View File

@ -11,6 +11,13 @@ Teleporters :
[-5.0, 1.0, 9.0, 10.0, 2.0, 1.0, 0.0, 0.0, 0, 0, 255; 1, 0] [-5.0, 1.0, 9.0, 10.0, 2.0, 1.0, 0.0, 0.0, 0, 0, 255; 1, 0]
Weight : Weight :
20 50
$ $
entities:
[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..]
if entityType = 4
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd]
else
[..]

View File

@ -16,3 +16,10 @@ Weight :
50 50
$ $
entities:
[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..]
if entityType = 4
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd]
else
[..]

28
templates/room_5 Normal file
View File

@ -0,0 +1,28 @@
Blocks :
[-10.0, 0.0, -10.0, 20.0, 1.0, 20.0, 0.0, 0.0, 192, 192, 192]
Teleporters :
[-10.0, 1.0, -5.0, 1.0, 2.0, 10.0, 0.0, 0.0, 255, 0, 0; 0, -1]
[-5.0, 1.0, -10.0, 10.0, 2.0, 1.0, 0.0, 0.0, 255, 255, 0; -1, 0]
[9.0, 1.0, -5.0, 1.0, 2.0, 10.0, 0.0, 0.0, 0, 255, 0; 0, 1]
[-5.0, 1.0, 9.0, 10.0, 2.0, 1.0, 0.0, 0.0, 0, 0, 255; 1, 0]
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, 90]
[-5.0, 9.0, -15.0, 4.0, 1.0, 4.0, 0.0, 0.0, 192, 128, 192, 10, 0, 4, 5.0, 0.0, 0.0, 2, 1, 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, 270]
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} = doubles[>= 0.0]
{mult,divd} = int
{phase} = int[0, 360]
else
[..]