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) {
if(*len > 0) {
(*arr)[index] = (*arr)[*len -1];
entity* temp = arr[index];
arr[index] = arr[*len -1];
arr[*len -1] = temp;
*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) {
entity* newarr = malloc(sizeof(entity)*2*(*memlen));
entity** newarr = malloc(sizeof(entity*)*2*(*memlen));
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);
*arr = newarr ;
arr = newarr ;
*memlen *= 2;
}
(*arr)[*len] = ent ;
free(arr[*len]);
arr[*len] = ent ;
*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);
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_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 ;
GLint loc_scale;
GLint loc_model;
GLint loc_view;
GLint loc_proj;
GLint loc_frag;
void init_draworder() {
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->vt_angle), (vec3){1.0f, 0.0f, 0.0f});
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "scale"), 1, GL_FALSE, (float*)scale);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "model"), 1, GL_FALSE, (float*)model);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "view"), 1, GL_FALSE, (float*)view);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "projection"), 1, GL_FALSE, (float*)projection);
glUniformMatrix4fv(loc_scale, 1, GL_FALSE, (float*)scale);
glUniformMatrix4fv(loc_model, 1, GL_FALSE, (float*)model);
glUniformMatrix4fv(loc_view, 1, GL_FALSE, (float*)view);
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);
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) {
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_camera(px, py, pz, NULL, NULL, &pz2);
if(pz2 > near) {
project_to_camera(px, py, pz, &px2, &py2, &pz2);
if(pz2 >= near) {
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++) {
if(is_visible(rtd->ents[k].pos, offx, offy, offz)) {
gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, 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);
}
}
}
@ -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_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) {
@ -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)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);
}

View File

@ -21,52 +21,52 @@ bool is_colliding_with_map(cube_0* cb) {
for(int k = 0; k < current_room->map_size; k++) {
for(int d = 0; d < 8; d++) {
if(distance_pt_cube_0_3d(cb->x+cb->w*(d%2==0), cb->y+cb->h*((d/2)%2==0), cb->z+cb->d*((d/4)%2==0), current_room->map[k]) <= 0.01) {
return true ;
return true;
}
}
}
return false ;
return false;
}
bool is_colliding_with_tp(cube_0* cb) {
for(int k = 0; k < current_room->tps_size; k++) {
for(int d = 0; d < 8; d++) {
if(distance_pt_cube_0_3d(cb->x+cb->w*(d%2==0), cb->y+cb->h*((d/2)%2==0), cb->z+cb->d*((d/4)%2==0), current_room->tps[k]->hitbox) <= 0.01) {
return true ;
return true;
}
}
}
return false ;
return false;
}
// ------------------------------------------------------------------------------------------------------------------------------------------------ //
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) {
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");
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;
}
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;
if((int)(5.0*ret->hz_angle) != (int)(5.0*(ret->hz_angle - ((double)dtime)*22.5))) {
double dx = (x+w/2 - camx);
double dy = (y+h/2 - camy);
double dz = (z+d/2 - camz);
double total = sqrt(dx*dx + dy*dy + dz*dz) ;
double total = sqrt(dx*dx + dy*dy + dz*dz);
dx = 170.0*dx/total;
dy = 170.0*dy/total;
dz = 170.0*dz/total;
@ -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;
}
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) {
ret->red = 0;
ret->green = 192;
@ -86,41 +98,69 @@ void detectHit(float dtime, int* hp, int* dmg, cube_0* ret) {
coins += *hp;
player_hp -= (*dmg);
if(*dmg != 0) {
fade_dmg = 255 ;
fade_dmg = 255;
}
*hp = 0 ;
*hp = 0;
}
}
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 dy = (y+h/2 - camy);
double dz = (z+d/2 - camz);
double total = sqrt(dx*dx + dy*dy + dz*dz) ;
double total = sqrt(dx*dx + dy*dy + dz*dz);
dx = 110.0*dx/total;
dy = 110.0*dy/total;
dz = 110.0*dz/total;
ret->x -= dtime*dx ;
ret->x -= dtime*dx;
if(is_colliding_with_map(ret) || is_colliding_with_tp(ret)) {
ret->x += dtime*dx ;
ret->x += dtime*dx;
}
ret->y -= dtime*dy ;
ret->y -= dtime*dy;
if(is_colliding_with_map(ret) || is_colliding_with_tp(ret)) {
ret->y += dtime*dy ;
ret->y += dtime*dy;
}
ret->z -= dtime*dz ;
ret->z -= dtime*dz;
if(is_colliding_with_map(ret) || is_colliding_with_tp(ret)) {
ret->z += dtime*dz ;
ret->z += dtime*dz;
}
if((int)(ret->x+ret->y+ret->z) != (int)(ret->x+ret->y+ret->z-dx-dy-dz)) {
}
}
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);
if(*dmg != 0) {
fade_dmg = 255 ;
fade_dmg = 255;
}
*hp = 0 ;
*hp = 0;
}

View File

@ -7,13 +7,14 @@ bool is_colliding_with_tp(cube_0* cb);
void update_entity(entity* ent, 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 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 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 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, 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, 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, cube_0* ret);
void explodeOnHit(float dtime, int* hp, int* dmg, 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 translatePlayer(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret);
#endif

View File

@ -14,51 +14,57 @@
#include "entities.h"
#include "generation.h"
hashtbl visited ;
room* current_room ;
hashtbl visited;
room* current_room;
int player_chx ;
int player_chy ;
int player_chx;
int player_chy;
entry* pool ;
int pool_size ;
int total_weight ;
entry* pool;
int pool_size;
int total_weight;
int coins ;
int fct_entry_size ;
int coins;
int fct_entry_size;
fct_entry* hashtbl_entities ;
fct_entry* hashtbl_entities;
void init_ent_generator(int n) {
hashtbl_entities = malloc(sizeof(fct_entry)*n);
fct_entry_size = n;
for(int k = 0; k < 10; k++) {
hashtbl_entities[k].id = (-1) ;
hashtbl_entities[k].id = (-1);
}
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].onDeath = NULL ;
hashtbl_entities[0].updatePos = &speen2;
hashtbl_entities[0].onHit = &detectHit;
hashtbl_entities[0].onDeath = NULL;
hashtbl_entities[1].id = 1;
hashtbl_entities[1].name = "ExplosiveStill";
hashtbl_entities[1].updatePos = &speen2 ;
hashtbl_entities[1].onHit = &explodeOnHit ;
hashtbl_entities[1].onDeath = NULL ;
hashtbl_entities[1].updatePos = &speen2;
hashtbl_entities[1].onHit = &explodeOnHit;
hashtbl_entities[1].onDeath = NULL;
hashtbl_entities[2].id = 2;
hashtbl_entities[2].name = "ExplosiveSeek";
hashtbl_entities[2].updatePos = &go_to_player ;
hashtbl_entities[2].onHit = &explodeOnHit ;
hashtbl_entities[2].onDeath = NULL ;
hashtbl_entities[2].updatePos = &go_to_player;
hashtbl_entities[2].onHit = &explodeOnHit;
hashtbl_entities[2].onDeath = NULL;
hashtbl_entities[3].id = 3;
hashtbl_entities[3].name = "ExplosiveShoot";
hashtbl_entities[3].updatePos = &speen3 ;
hashtbl_entities[3].onHit = &explodeOnHit ;
hashtbl_entities[3].onDeath = NULL ;
hashtbl_entities[3].updatePos = &speen3;
hashtbl_entities[3].onHit = &explodeOnHit;
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) {
@ -72,8 +78,8 @@ fct_entry* get_entry(int k0) {
void copy_room(room* src, room* dest, int chx, int chy) {
// considering dest has already been malloc'd
dest->chunk_x = chx ;
dest->chunk_y = chy ;
dest->chunk_x = chx;
dest->chunk_y = chy;
dest->map = malloc(sizeof(cube_0*)*src->map_size);
for(int k = 0; k < src->map_size; k++) {
dest->map[k] = create_cube_0(
@ -82,7 +88,7 @@ void copy_room(room* src, room* dest, int chx, int chy) {
src->map[k]->hz_angle, src->map[k]->vt_angle, src->map[k]->red, src->map[k]->green, src->map[k]->blue
);
}
dest->map_size = src->map_size ;
dest->map_size = src->map_size;
dest->tps = malloc(sizeof(teleporter*)*src->tps_size);
for(int k = 0; k < src->tps_size; k++) {
dest->tps[k] = malloc(sizeof(teleporter));
@ -93,37 +99,55 @@ void copy_room(room* src, room* dest, int chx, int chy) {
);
dest->tps[k]->dest_chx = src->tps[k]->dest_chx + chx;
dest->tps[k]->dest_chy = src->tps[k]->dest_chy + chy;
dest->tps[k]->dest_x = src->tps[k]->dest_x ;
dest->tps[k]->dest_y = src->tps[k]->dest_y ;
dest->tps[k]->dest_z = src->tps[k]->dest_z ;
dest->tps[k]->dest_x = src->tps[k]->dest_x;
dest->tps[k]->dest_y = src->tps[k]->dest_y;
dest->tps[k]->dest_z = src->tps[k]->dest_z;
}
dest->ents = malloc(sizeof(entity)*src->ent_memlen);
dest->ent_memlen = src->ent_memlen ;
dest->ent_len = src->ent_len ;
dest->ents = malloc(sizeof(entity*)*src->ent_memlen);
dest->ent_memlen = src->ent_memlen;
dest->ent_len = src->ent_len;
for(int k = 0; k < src->ent_len; k++) {
dest->ents[k].damage = src->ents[k].damage ;
dest->ents[k].hitpoints = malloc(sizeof(int));
*(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] = malloc(sizeof(entity));
dest->ents[k]->damage = src->ents[k]->damage;
dest->ents[k]->hitpoints = malloc(sizeof(int));
dest->ents[k]->metai1 = src->ents[k]->metai1;
dest->ents[k]->metai2 = src->ents[k]->metai2;
dest->ents[k]->metai3 = src->ents[k]->metai3;
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].onHit = src->ents[k].onHit;
dest->ents[k].onDeath = src->ents[k].onDeath;
dest->ents[k]->updatePos = src->ents[k]->updatePos;
dest->ents[k]->onHit = src->ents[k]->onHit;
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;
}
void build_starting_chunk(int chx, int chy) {
room* new = malloc(sizeof(room));
new->chunk_x = chx ;
new->chunk_y = chy ;
new->chunk_x = chx;
new->chunk_y = chy;
new->map = malloc(sizeof(cube_0*)*9);
new->map_size = 9 ;
new->map_size = 9;
new->tps = malloc(sizeof(teleporter*)*4);
new->tps_size = 4 ;
new->tps_size = 4;
new->map[0] = create_cube_0(0.0, 0.0, 0.0, 5.0, 1.0, 5.0, 0.0, 0.0, 255, 255, 255);
new->map[1] = create_cube_0(0.0, 0.0, 0.0, 5.0, 1.0, 5.0, 0.0, 0.0, 255, 255, 255);
@ -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[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->ent_len = 1 ;
new->ent_memlen = 128 ;
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);
new->ents[0].damage = 0 ;
new->ents[0].hitpoints = malloc(sizeof(int));
*(new->ents[0].hitpoints) = 5 ;
new->ents[0].onDeath = NULL ;
new->ents[0].onHit = *detectHit ;
new->ents[0].updatePos = *speen2 ;
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_memlen = 32;
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]->hitpoints) = 5;
new->ents[0]->onDeath = NULL;
new->ents[0]->onHit = *detectHit;
new->ents[0]->updatePos = *speen2;
hashtbl_add(visited, chx, chy, new);
}
@ -158,32 +186,32 @@ 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 ;
total_weight = 0 ;
coins = 0 ;
player_chx = 0;
player_chy = 0;
total_weight = 0;
coins = 0;
}
void get_number_blocks(int* ret_cubes, int* ret_tps, int* ret_ent, FILE* ptr) {
*ret_cubes = 0 ;
*ret_tps = 0 ;
*ret_ent = 0 ;
*ret_cubes = 0;
*ret_tps = 0;
*ret_ent = 0;
int in_blocks = 0 ;
char c = fgetc(ptr) ;
int in_blocks = 0;
char c = fgetc(ptr);
while(c != EOF && c != '$') {
//printf("%c", c);
if(c == 'B') {
in_blocks = 0 ;
in_blocks = 0;
} else if(c == 'T') {
in_blocks = 1 ;
in_blocks = 1;
} else if(c == 'E') {
in_blocks = 2 ;
in_blocks = 2;
} else if(c == '[') {
if(in_blocks == 0) {
*ret_cubes += 1 ;
*ret_cubes += 1;
} else if(in_blocks == 1) {
*ret_tps += 1 ;
*ret_tps += 1;
} else {
*ret_ent += 1;
}
@ -203,24 +231,24 @@ void align_to(FILE* ptr, char ch) {
int read_int(FILE* ptr, bool print) {
bool is_reading = false;
int buffer = 0 ;
int sign = 1 ;
int buffer = 0;
int sign = 1;
char c = fgetc(ptr);
while(c != EOF) {
if(c == '-') {
sign = -1 ;
sign = -1;
} else if((int)c >= 48 && (int)c <= 57) {
is_reading = true ;
buffer = 10*buffer + (int)c - 48 ;
is_reading = true;
buffer = 10*buffer + (int)c - 48;
} else if(is_reading) {
/*if(print) {
printf("%d ; ", buffer*sign);
printf("%d; ", buffer*sign);
}*/
return buffer*sign;
}
c = fgetc(ptr);
}
return buffer*sign ;
return buffer*sign;
}
double sign(double __x) {
@ -233,7 +261,7 @@ double sign(double __x) {
double read_float(FILE* ptr) {
int ent = read_int(ptr, false);
int frac = read_int(ptr, false);
//printf("%d.%d ; ", ent, frac);
//printf("%d.%d; ", ent, frac);
if(ent != 0.0) {
return (ent/abs(ent))*(absf((double)ent) + ((double)frac)/(pow(10.0, (double)ln_baseN(frac, 10))));
} else {
@ -247,18 +275,15 @@ void parse_one_room(int id, char* filename) {
FILE* ptr = fopen(filename, "r");
pool[id].area = malloc(sizeof(room));
int ncubes ;
int ntps ;
int nent ;
int ncubes;
int ntps;
int nent;
FILE* ptr2 = fopen(filename, "r") ;
FILE* ptr2 = fopen(filename, "r");
get_number_blocks(&ncubes, &ntps, &nent, ptr2);
printf("(%d, %d, %d)\n", ncubes, ntps, nent);
int nmemlen = 128 ;
while(nmemlen < nent) {
nmemlen *= 2.;
}
int nmemlen = maxd(nent, 64);
pool[id].area->map = malloc(sizeof(cube_0*)*ncubes);
pool[id].area->map_size = ncubes;
@ -267,9 +292,14 @@ void parse_one_room(int id, char* filename) {
pool[id].area->tps[k] = malloc(sizeof(teleporter));
}
pool[id].area->tps_size = ntps;
pool[id].area->ents = malloc(sizeof(entity)*nmemlen);
pool[id].area->ent_len = nent ;
pool[id].area->ent_memlen = 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_memlen = nmemlen;
printf("0/3...\n");
fflush(stdout);
@ -336,17 +366,44 @@ void parse_one_room(int id, char* filename) {
if(entry == NULL) {
entry = get_entry(0);
}
pool[id].area->ents[k].pos = create_cube_0(cx, cy, cz, cw, ch, cd, chz, cvt, red, green, blue);
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].updatePos = entry->updatePos ;
pool[id].area->ents[k].onHit = entry->onHit ;
pool[id].area->ents[k].onDeath = entry->onDeath ;
//pool[id].area->ents[k].updatePos = &speen2 ;
//pool[id].area->ents[k].onHit = &detectHit ;
//pool[id].area->ents[k].onDeath = NULL ;
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]->hitpoints) = hp;
pool[id].area->ents[k]->updatePos = entry->updatePos;
pool[id].area->ents[k]->onHit = entry->onHit ;
pool[id].area->ents[k]->onDeath = entry->onDeath ;
pool[id].area->ents[k]->metai1 = entry->metai1;
pool[id].area->ents[k]->metai2 = entry->metai2;
pool[id].area->ents[k]->metai3 = entry->metai3;
pool[id].area->ents[k]->metai4 = entry->metai4;
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");
}
@ -354,7 +411,7 @@ void parse_one_room(int id, char* filename) {
fflush(stdout);
// 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",
pool[id].area->map[k]->x,
pool[id].area->map[k]->y,
@ -368,53 +425,54 @@ void parse_one_room(int id, char* filename) {
pool[id].area->map[k]->green,
pool[id].area->map[k]->blue
);
}
}*/
pool[id].weight = read_int(ptr, true);
total_weight += pool[id].weight;
printf("OK\n");
printf("(w = %d) OK\n", pool[id].weight);
fflush(stdout);
printf("\n\n");
pool[id].weight = read_int(ptr, true);
total_weight += pool[id].weight ;
fclose(ptr);
}
void parse_rooms(int n_rooms) {
char* name = malloc(sizeof(char)*19); // 1000 rooms max
name[0] = 't' ;
name[1] = 'e' ;
name[2] = 'm' ;
name[3] = 'p' ;
name[4] = 'l' ;
name[5] = 'a' ;
name[6] = 't' ;
name[7] = 'e' ;
name[8] = 's' ;
name[9] = '/' ;
name[10] = 'r' ;
name[11] = 'o' ;
name[12] = 'o' ;
name[13] = 'm' ;
name[14] = '_' ;
name[15] = '0' ;
name[16] = '\0' ;
name[17] = '\0' ;
name[18] = '\0' ;
name[0] = 't';
name[1] = 'e';
name[2] = 'm';
name[3] = 'p';
name[4] = 'l';
name[5] = 'a';
name[6] = 't';
name[7] = 'e';
name[8] = 's';
name[9] = '/';
name[10] = 'r';
name[11] = 'o';
name[12] = 'o';
name[13] = 'm';
name[14] = '_';
name[15] = '0';
name[16] = '\0';
name[17] = '\0';
name[18] = '\0';
pool = malloc(sizeof(entry)*n_rooms);
pool_size = n_rooms ;
pool_size = n_rooms;
printf("Parsing...\n");
for(int k = 0; k < n_rooms; k++) {
printf("parsing %d...", k);
if(k < 10) {
name[15] = (char)(k%10 + 48) ;
name[15] = (char)(k%10 + 48);
} else if(k < 100) {
name[15] = (char)((k/10)%10 + 48) ;
name[16] = (char)(k%10 + 48) ;
name[15] = (char)((k/10)%10 + 48);
name[16] = (char)(k%10 + 48);
}
parse_one_room(k, name);
printf("done.\n");
}
printf("\nDone.\n");
@ -423,14 +481,14 @@ void parse_rooms(int n_rooms) {
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) {
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++) {
newMap[k] = malloc(sizeof(cube_0));
}
for(int k = 0; k < r->map_size; k++) {
@ -443,7 +501,7 @@ void generate_terrain(room* r) {
int i = r->map_size;
for(int l = -room_width; l < room_width; l+=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;
}
}
@ -458,19 +516,21 @@ void generate_nearby_chunks(int render_dist) {
if(!hashtbl_mem(visited, 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);
int pick = rand()%total_weight ;
int sum = 0 ;
int pick = rand()%total_weight;
printf("R = %d ", pick);
int sum = 0;
for(int k = 0; k < pool_size; k++) {
sum += pool[k].weight ;
sum += pool[k].weight;
if(pick < sum) {
printf("chose %d\n", k);
room* new = malloc(sizeof(room));
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);
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]);
}
for(int k = 0; k < pool[k0].area->ent_len; k++) {
free(pool[k0].area->ents[k].hitpoints);
free(pool[k0].area->ents[k].pos);
for(int k = 0; k < pool[k0].area->ent_memlen; k++) {
free(pool[k0].area->ents[k]->hitpoints);
free(pool[k0].area->ents[k]->pos);
free(pool[k0].area->ents[k]);
}
free(pool[k0].area->ents);
free(pool[k0].area->tps);

View File

@ -9,11 +9,25 @@ typedef struct entry {
typedef struct fct_entry {
int id ;
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
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
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 ;
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]);
}
for(int k = 0; k < r->ent_len; k++) {
free(r->ents[k].hitpoints);
free(r->ents[k].pos);
for(int k = 0; k < r->ent_memlen; k++) {
free(r->ents[k]->hitpoints);
free(r->ents[k]->pos);
free(r->ents[k]);
}
free(r->ents);
free(r->tps);

View File

@ -20,7 +20,7 @@
#include "display.h"
#include "generation.h"
double sim_time ;
double sim_time;
int triCount;
void processInput(GLFWwindow *window, float dtime) {
@ -28,6 +28,7 @@ void processInput(GLFWwindow *window, float dtime) {
glfwSetWindowShouldClose(window, true);
}
if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
/*
for(int k = 0; k < 10; k++) {
camz -= speed*cos(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;
}
}
*/
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) {
/*
for(int k = 0; k < 10; k++) {
camx -= speed*cos(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;
k=11;
}
}
}*/
camvx = -speed*cos(rot_hz);
camvz = speed*sin(rot_hz);
}
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;
camx += speed*sin(rot_hz)*cos(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;
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) {
for(int k = 0; k < 10; k++) {
/*for(int k = 0; k < 10; k++) {
camx += speed*cos(rot_hz)/10;
camz -= speed*sin(rot_hz)/10;
if(is_colliding(dtime)) {
@ -73,11 +84,14 @@ void processInput(GLFWwindow *window, float dtime) {
camz += speed*sin(rot_hz)/10;
k=11;
}
}
}*/
camvx = speed*cos(rot_hz);
camvz = -speed*sin(rot_hz);
}
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) {
@ -88,10 +102,10 @@ void processInput(GLFWwindow *window, float dtime) {
}
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) {
rot_vt += sensitivity;
rot_vt = mind(3.14159/2.0, rot_vt+sensitivity);
}
}
@ -164,7 +178,7 @@ int main_alt() {
init_hashtbl();
init_ent_generator(10);
init_proj();
parse_rooms(5);
parse_rooms(6);
// ---------------------------------------------------------------------------------------------------------------------------------------------- //
// ---------------------------------------------------------------------------------------------------------------------------------------------- //
@ -287,21 +301,26 @@ int main_alt() {
// ---------------------------------------------------------------------------------------------------------------------------------------------- //
// ---------------------------------------------------------------------------------------------------------------------------------------------- //
int fps = 60 ;
int interval = 1000000/fps ;
int fps = 60;
int interval = 1000000/fps;
double slp_time = 1.0/fps;
float delta = 0.0f;
double deltad = 0.0;
clock_t finish = clock();
clock_t origin = clock();
while(!glfwWindowShouldClose(window) && player_hp >= 0) {
while(!glfwWindowShouldClose(window) && player_hp > 0) {
// input
// -----
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
triCount = 0;
origin = clock();
fflush(stdout);
generate_nearby_chunks(1);
fflush(stdout);
// draw the map
glUseProgram(shaderProgram);
@ -315,28 +334,30 @@ int main_alt() {
glUseProgram(shaderProgramR);
glBindVertexArray(RVAO);
finish = clock();
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, (int)(1.0f/(delta)), 0.0f, -0.92f, 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_drawData(shaderProgramR);
// 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();
update_entities(((float)finish - (float)origin)/CLOCKS_PER_SEC);
updateProj(((float)finish - (float)origin)/CLOCKS_PER_SEC);
//printf("%f\n", 1.0f/(((float)finish - (float)origin)/CLOCKS_PER_SEC));
//printf("%lf, %lf, %lf\n", camx, camy, camz);
update_entities(delta);
updateProj(delta);
usleep(interval);
usleep(max(0, interval-(int)(1000000*delta)));
sim_time += deltad;
glfwSwapBuffers(window);
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);
free_proj();
free_pool();
@ -356,5 +377,6 @@ int main_alt() {
int main(int argc, char** argv) {
srand(time(NULL));
triCount = 0;
sim_time = 0.0;
return main_alt();
}

View File

@ -18,8 +18,13 @@
// ---------------------------------------------------------------------------------------------------- //
double sensitivity = 0.06;
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 friction = 0.8;
double gravity_factor = 9.8;
bool noResetSpeed = false;
// ---------------------------------------------------------------------------------------------------- //
int player_hp;
@ -30,6 +35,9 @@ double camx;
double camy;
double camz;
double camvx;
double camvy;
double camvz;
double rot_hz;
double rot_vt;
@ -47,6 +55,9 @@ void init_csts() {
camx = 2.0;
camy = 5.0;
camz = 2.0;
camvx = 0.0;
camvy = 0.0;
camvz = 0.0;
rot_hz = 0.0;
rot_vt = 0.0;
draw_type = 0;
@ -92,15 +103,15 @@ bool is_colliding(float dtime) {
}
}
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(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)));
if(*(current_room->ents[k].hitpoints) <= 0) {
if(current_room->ents[k].onDeath != NULL) {
(*current_room->ents[k].onDeath)(dtime);
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], &(*(current_room->ents[k]->pos)));
if(*(current_room->ents[k]->hitpoints) <= 0) {
if(current_room->ents[k]->onDeath != NULL) {
(*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;
@ -109,6 +120,39 @@ bool is_colliding(float dtime) {
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() {
if(camx >= room_width) {
camx -= 2.0*room_width;

View File

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

View File

@ -33,14 +33,27 @@ typedef struct teleporter {
typedef struct entity {
cube_0* pos;
// 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
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)
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* hitpoints;
} entity;
@ -53,7 +66,7 @@ struct room {
int map_size;
teleporter** tps;
int tps_size;
entity* ents;
entity** ents;
int ent_len;
int ent_memlen;
};
@ -86,6 +99,14 @@ extern double camx;
extern double camy;
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_vt;
@ -124,6 +145,8 @@ extern double min_dist;
extern float vertices[108];
extern float rectDefault[18];
extern int triCount ;
extern int triCount;
extern bool noResetSpeed;
#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]
[9.0, 1.0, 4.0, 1.0, 4.0, 2.0, 0.0, 0.0, 0, 0, 255; 1, 0]
Weight :
10
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 :
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]
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

@ -22,4 +22,11 @@ Entities :
Weight :
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]
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

@ -15,4 +15,11 @@ Entities :
Weight :
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
[..]