diff --git a/bin/back b/bin/back index ccac55f..eb9e070 100755 Binary files a/bin/back and b/bin/back differ diff --git a/levels/level_02/room_0 b/levels/level_02/room_0 index 335c98b..e0324a6 100644 --- a/levels/level_02/room_0 +++ b/levels/level_02/room_0 @@ -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] diff --git a/obj/entities.o b/obj/entities.o index e4f8f49..7f9871c 100644 Binary files a/obj/entities.o and b/obj/entities.o differ diff --git a/obj/move.o b/obj/move.o index 939b691..2a317fc 100644 Binary files a/obj/move.o and b/obj/move.o differ diff --git a/src/entities.c b/src/entities.c index dab059b..8595b19 100644 --- a/src/entities.c +++ b/src/entities.c @@ -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) { diff --git a/src/entities.h b/src/entities.h index b50c4f4..4348d37 100644 --- a/src/entities.h +++ b/src/entities.h @@ -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); diff --git a/src/move.c b/src/move.c index 942a995..87acb45 100644 --- a/src/move.c +++ b/src/move.c @@ -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; diff --git a/src/move.h b/src/move.h index 45da585..d50de69 100644 --- a/src/move.h +++ b/src/move.h @@ -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);