diff --git a/README.md b/README.md index 807a67c..ddddb8a 100644 --- a/README.md +++ b/README.md @@ -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] + ``` \ No newline at end of file diff --git a/bin/back b/bin/back index eb9e070..f2cf8aa 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 e0324a6..70515b8 100644 --- a/levels/level_02/room_0 +++ b/levels/level_02/room_0 @@ -33,9 +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, 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] +[-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] diff --git a/obj/display.o b/obj/display.o index 18243bc..ea7a77c 100644 Binary files a/obj/display.o and b/obj/display.o differ diff --git a/obj/entities.o b/obj/entities.o index 7f9871c..4b2a097 100644 Binary files a/obj/entities.o and b/obj/entities.o differ diff --git a/obj/generation.o b/obj/generation.o index a9372a2..004f61f 100644 Binary files a/obj/generation.o and b/obj/generation.o differ diff --git a/obj/move.o b/obj/move.o index 2a317fc..3b7b2b0 100644 Binary files a/obj/move.o and b/obj/move.o differ diff --git a/src/display.c b/src/display.c index 74b540e..6aa6508 100644 --- a/src/display.c +++ b/src/display.c @@ -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)) ); } diff --git a/src/entities.c b/src/entities.c index 8595b19..ae39cf8 100644 --- a/src/entities.c +++ b/src/entities.c @@ -289,6 +289,32 @@ 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); updateF_movableCrate(ret, (double)dtime, ent); diff --git a/src/entities.h b/src/entities.h index 4348d37..b397bcd 100644 --- a/src/entities.h +++ b/src/entities.h @@ -23,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); diff --git a/src/generation.c b/src/generation.c index 383b6f3..3116fca 100644 --- a/src/generation.c +++ b/src/generation.c @@ -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; } diff --git a/src/move.c b/src/move.c index 87acb45..e5ac3cb 100644 --- a/src/move.c +++ b/src/move.c @@ -268,7 +268,7 @@ void updateF_movableCrate(cube_0* cb, double dtime, entity* ent) { (dot3D(vt, normal) <= 0.0 && dot3D(vtdt, normal) >= 0.0) || (dot3D(vt, normal) >= 0.0 && dot3D(vtdt, normal) <= 0.0) ) { - printf("%d\n", d); + //printf("%d\n", d); switch (d) { case 0: ent->metad1 += camvx; break;