Compare commits

...

2 Commits

13 changed files with 135 additions and 8 deletions

View File

@ -87,7 +87,10 @@ entities:
{ontime,offtime} = double[>0.0]
start = {0,1}
-> 10 UNUSED
-> 10 (movable block)
[.. friction, mass] with
friction = double[>0.0]
mass = double[>0.0] (in kg)
-> 11 (button trigger)
[.. freq, dtime] with
@ -104,4 +107,8 @@ entities:
defaultState = {0, 1}
dtime = double([>0.0] for time-limited press, or use -1.0 if no deactivation)
-> 14 (movable object-related button)
[.. freq] with
freq = int[0 - 15]
```

BIN
bin/back

Binary file not shown.

View File

@ -33,7 +33,13 @@ Entities:
[-15.0, 4.0, -10.0, 4.0, 1.0, 5.0, 0.0, 0.0, 255, 255, 255, 1, 0, 2, 0.0, 42.0, 0.0, 0.0, 2.0, 1]
[-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, 3.0, 5.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 10, 0.98, 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.98, 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.98, 1.0]
[0.0, 0.0, 0.0, 2.0, 0.2, 2.0, 0.0, 0.0, 255, 255, 0, 1, 0, 14, 10]
[4.0, 0.0, 0.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 128, 128, 1, 0, 12, 10, 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.

Binary file not shown.

Binary file not shown.

View File

@ -176,8 +176,9 @@ void gl_resetTexture() {
bool is_button_block_on(entity* ent) {
return (
(ent->entity_type != 11 && ent->entity_type != 12) ||
(ent->entity_type != 11 && ent->entity_type != 12 && ent->entity_type != 14) ||
(ent->entity_type == 11 && buttonSwitch[ent->metai1]) ||
(ent->entity_type == 14 && ent->metai2) ||
(ent->entity_type == 12 && xor(buttonSwitch[ent->metai1], ent->metai2))
);
}

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;
}
@ -274,10 +289,35 @@ void movableCrate_postStep(double x, double y, double z, double w, double h, dou
}
}
// metai1 = button freq
// metai2 = is triggered (0/1)
void movCrateButton_postStep(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) {
bool isIn = false;
for(int k = 0; k < current_room->ent_len*(1-isIn); k++) {
for(int d = 0; d < 8*(1-isIn); d++) {
if(
current_room->ents[k]->entity_type == 10 &&
distance_pt_cube_0_3d(ret->x+ret->w*(d%2==0), ret->y+ret->h*((d/2)%2==0), ret->z+ret->d*((d/4)%2==0), current_room->ents[k]->pos) <= 0.001
) {
isIn = true;
ent->metai2 = 1;
if(!buttonSwitch[ent->metai1]) {
//printf("In\n");
buttonSwitch[ent->metai1] = true;
buttonTimes[ent->metai1] = -1.0;
}
}
}
}
if(!isIn && ent->metai2 != 0) {
ent->metai2 = 0;
buttonSwitch[ent->metai1] = false;
}
}
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);
@ -22,6 +23,7 @@ void spinning_platform(double x, double y, double z, double w, double h, double
void math_block(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 lava_postStep(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 movableCrate_postStep(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 movCrateButton_postStep(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 movableCrate_onHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret);
void lava_onHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret);

View File

@ -153,6 +153,14 @@ void init_ent_generator(int n) {
hashtbl_entities[13].updatePos = &math_block;
hashtbl_entities[13].onHit = &active_math;
hashtbl_entities[13].onDeath = NULL;
hashtbl_entities[14].id = 14;
hashtbl_entities[14].tex = 10;
hashtbl_entities[14].tex2 = 11;
hashtbl_entities[14].name = "movableBlockButton";
hashtbl_entities[14].updatePos = &movCrateButton_postStep;
hashtbl_entities[14].onHit = NULL;
hashtbl_entities[14].onDeath = NULL;
}
fct_entry* get_entry(int k0) {
@ -678,6 +686,7 @@ void parse_one_room(int id, char* filename) {
pool[id].area->ents[k]->metai1 = freq;
pool[id].area->ents[k]->metad1 = acttime;
} else if(entry->id == 12) {
// button interface
int freq = read_int(ptr);
int offstate = read_int(ptr);
@ -690,6 +699,7 @@ void parse_one_room(int id, char* filename) {
pool[id].area->ents[k]->metai1 = freq;
pool[id].area->ents[k]->metai2 = offstate;
} else if(entry->id == 13) {
// button block
int defaultState = read_int(ptr);
double activeTime = read_float(ptr);
@ -702,6 +712,11 @@ void parse_one_room(int id, char* filename) {
} else {
pool[id].area->ents[k]->tex2 = 9;
}
} else if(entry->id == 14) {
// movable block button
int freq = read_int(ptr);
pool[id].area->ents[k]->metai1 = freq;
} else {
pool[id].area->ents[k]->metai3 = 0;
}

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);