movable crates now interact with each other

This commit is contained in:
Alexandre 2025-03-14 08:02:05 +01:00
parent 48c39e5c55
commit dd0aed2334
8 changed files with 78 additions and 5 deletions

BIN
bin/back

Binary file not shown.

View File

@ -34,6 +34,8 @@ Entities:
[-10.0, 4.0, -20.0, 5.0, 1.0, 5.0, 0.0, 0.0, 255, 255, 255, 1, 0, 2, 3.0, 0.0, 0.0, 0.0, 0.0, 0]
[-5.0, 3.0, 5.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 10, 0.9, 1.0]
[-5.0, 6.0, 5.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 10, 0.9, 1.0]
[-5.0, 9.0, 5.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 10, 0.9, 1.0]
[8.0, 1.0 , 8.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 128, 1, 0, 8, 100, 1, 128, 128, 128]
[-8.0, 1.0, 8.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 6, get over it, 192, 192, 192]

Binary file not shown.

Binary file not shown.

View File

@ -44,6 +44,21 @@ bool is_colliding_with_tp(cube_0* cb) {
return false;
}
bool is_colliding_with_ent_sp(cube_0* cb, int allowed) {
for(int k = 0; k < current_room->ent_len; k++) {
for(int d = 0; d < 8; d++) {
if(
current_room->ents[k]->entity_type == allowed &&
(cb->x != current_room->ents[k]->pos->x || cb->y != current_room->ents[k]->pos->y || cb->z != current_room->ents[k]->pos->z) &&
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->ents[k]->pos) <= 0.01
) {
return true;
}
}
}
return false;
}
// ------------------------------------------------------------------------------------------------------------------------------------------------ //
static double choffx, choffz;
@ -253,17 +268,17 @@ void movableCrate_postStep(double x, double y, double z, double w, double h, dou
ent->metad2 += -((double)dtime)*(gravity_factor*ent->metad5);
ret->x += dtime*ent->metad1;
if(absf(ent->metad1) < 0.04 || is_colliding_with_map(ret) || is_colliding_with_tp(ret)) {
if(absf(ent->metad1) < 0.04 || is_colliding_with_map(ret) || is_colliding_with_tp(ret) || is_colliding_with_ent_sp(ret, 10)) {
ret->x -= dtime*ent->metad1;
ent->metad1 = 0.0;
}
ret->y += dtime*ent->metad2;
if(absf(ent->metad2) < 0.04 || is_colliding_with_map(ret) || is_colliding_with_tp(ret)) {
if(absf(ent->metad2) < 0.04 || is_colliding_with_map(ret) || is_colliding_with_tp(ret) || is_colliding_with_ent_sp(ret, 10)) {
ret->y -= dtime*ent->metad2;
ent->metad2 = 0.0;
}
ret->z += dtime*ent->metad3;
if(absf(ent->metad3) < 0.04 || is_colliding_with_map(ret) || is_colliding_with_tp(ret)) {
if(absf(ent->metad3) < 0.04 || is_colliding_with_map(ret) || is_colliding_with_tp(ret) || is_colliding_with_ent_sp(ret, 10)) {
ret->z -= dtime*ent->metad3;
ent->metad3 = 0.0;
}
@ -276,8 +291,7 @@ void movableCrate_postStep(double x, double y, double z, double w, double h, dou
void movableCrate_onHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
//printf("(+%lf, +%lf)\n", camvx, camvz);
ent->metad1 = camvx;
ent->metad3 = camvz;
updateF_movableCrate(ret, (double)dtime, ent);
}
void lava_onHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {

View File

@ -5,6 +5,7 @@ extern int build_text_box(char* msg, int red, int green, int blue);
bool is_colliding_with_map(cube_0* cb);
bool is_colliding_with_tp(cube_0* cb);
bool is_colliding_with_ent_sp(cube_0* cb, int allowed);
void update_entity(entity* ent, float dtime);
void update_entities(float dtime, room* rtd);

View File

@ -237,6 +237,61 @@ void debugMove(cube_0* cb) {
}
}
void updateF_movableCrate(cube_0* cb, double dtime, entity* ent) {
for(int d = 0; d < 6; d++) {
cb->x -= min_dist;
cb->y -= min_dist;
cb->z -= min_dist;
cb->w += 2*min_dist;
cb->h += 2*min_dist;
cb->d += 2*min_dist;
getSF(cb, d);
cb->x += min_dist;
cb->y += min_dist;
cb->z += min_dist;
cb->w -= 2*min_dist;
cb->h -= 2*min_dist;
cb->d -= 2*min_dist;
getDirectors();
getNormal();
if(d==2 || d==5 || d==1) {
normal.x *= -1.0;
normal.y *= -1.0;
normal.z *= -1.0;
}
//printf("%lf %lf\n", dot3D(normal, directors[0]), dot3D(normal, directors[1]));
pt_2d vt = (pt_2d){.x = camx-camvx*dtime - surface[0].x, .y = camy-camvy*dtime - surface[0].y, .z = camz-camvz*dtime - surface[0].z};
pt_2d vtdt = (pt_2d){.x = camx - surface[0].x, .y = camy - surface[0].y, .z = camz - surface[0].z};
normalize(&vtdt);
normalize(&vt);
if(
(dot3D(vt, normal) <= 0.0 && dot3D(vtdt, normal) >= 0.0) ||
(dot3D(vt, normal) >= 0.0 && dot3D(vtdt, normal) <= 0.0)
) {
printf("%d\n", d);
switch (d) {
case 0:
ent->metad1 += camvx; break;
case 1:
ent->metad1 += camvx; break;
case 3:
break;
case 2:
ent->metad2 += camvy; break;
case 4:
ent->metad3 += camvz; break;
case 5:
ent->metad3 += camvz; break;
default:
break;
}
return;
}
}
}
void updateF(cube_0* cb, double dtime, entity* ent) {
for(int d = 0; d < 6; d++) {
cb->x -= min_dist;

View File

@ -7,6 +7,7 @@ bool is_colliding(float dtime);
void update_buttons(float dtime);
void updateF(cube_0* cb, double dtime, entity* ent);
void updateF_movableCrate(cube_0* cb, double dtime, entity* ent);
void debugMove(cube_0* cb);