diff --git a/.vscode/settings.json b/.vscode/settings.json index 0471f99..ae64e74 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,9 @@ "stdio.h": "c", "math.h": "c", "sdl_image.h": "c", - "display.h": "c" + "display.h": "c", + "generation.h": "c", + "time.h": "c", + "limits": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 48343b4..921b2a7 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ all: bin/back test: bin/back bin/back -bin/back: obj/main.o obj/generation.o obj/display.o obj/move.o obj/base.o obj/hash.o +bin/back: obj/main.o obj/generation.o obj/display.o obj/entities.o obj/move.o obj/base.o obj/hash.o mkdir -p bin $(CC) $(FLAGS) $^ $(LFLAGS) -o $@ @@ -18,6 +18,7 @@ obj/%.o: src/%.c obj/main.o: src/main.c obj/generation.o: src/generation.c obj/display.o: src/display.c +obj/entities.o: src/entities.c obj/move.o: src/move.c obj/base.o: src/base.c obj/hash.o: src/hash.c diff --git a/bin/back b/bin/back index c7b79b5..909171d 100755 Binary files a/bin/back and b/bin/back differ diff --git a/obj/display.o b/obj/display.o index 8e57dc0..5dde95e 100644 Binary files a/obj/display.o and b/obj/display.o differ diff --git a/obj/entities.o b/obj/entities.o new file mode 100644 index 0000000..3d133c8 Binary files /dev/null and b/obj/entities.o differ diff --git a/obj/main.o b/obj/main.o index 7701bf7..cd9ad26 100644 Binary files a/obj/main.o and b/obj/main.o differ diff --git a/src/display.c b/src/display.c index 4bd6d98..db4449e 100644 --- a/src/display.c +++ b/src/display.c @@ -15,6 +15,7 @@ #include "structure.h" #include "base.h" #include "move.h" +#include "entities.h" #include "generation.h" #include "display.h" diff --git a/src/entities.c b/src/entities.c new file mode 100644 index 0000000..0c1ff1d --- /dev/null +++ b/src/entities.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hash.h" +#include "structure.h" +#include "base.h" +#include "entities.h" + +// ------------------------------------------------------------------------------------------------------------------------------------------------ // + +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 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 false ; +} + +// ------------------------------------------------------------------------------------------------------------------------------------------------ // + +void update_entity(entity* ent) { + (*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, ent->pos); +} \ No newline at end of file diff --git a/src/entities.h b/src/entities.h new file mode 100644 index 0000000..7c308d1 --- /dev/null +++ b/src/entities.h @@ -0,0 +1,5 @@ +#ifndef ENTITIES_H +#define ENTITIES_H + + +#endif \ No newline at end of file diff --git a/src/main.c b/src/main.c index f4b9257..302a558 100644 --- a/src/main.c +++ b/src/main.c @@ -15,9 +15,12 @@ #include "structure.h" #include "base.h" #include "move.h" +#include "entities.h" #include "display.h" #include "generation.h" +double sim_time ; + int main(int argc, char** argv) { srand(time(NULL)); @@ -44,12 +47,17 @@ int main(int argc, char** argv) { SDL_SetRelativeMouseMode(true) ; /* -------------------------------------------------------- */ + int fps = 60 ; + int interval = 1000000/fps ; + double intervalf = 1.0/((double)(fps)) ; + init_csts() ; init_hashtbl() ; init_draworder() ; parse_rooms(3); import_digits(rend) ; import_letters(rend) ; + sim_time = 0.0 ; clock_t origin = clock(); clock_t finish = clock(); float delta; @@ -66,8 +74,10 @@ int main(int argc, char** argv) { delta = ((float)finish - (float)origin)/CLOCKS_PER_SEC; drawNumberToRenderer(rend, digits, (int)(1.0f/delta), 720, 60, 75/2, 105/2, 0); + drawNumberToRenderer(rend, digits, (int)(10*sim_time), 720, 110, 75/2, 105/2, 0); updateRenderer(rend) ; - usleep(1000000/60) ; + sim_time += delta + intervalf ; + usleep(interval) ; } free_digits(digits) ; diff --git a/src/move.h b/src/move.h index 84688c5..375ee1d 100644 --- a/src/move.h +++ b/src/move.h @@ -2,6 +2,7 @@ #define MOVE_H void init_csts(); +bool is_colliding(); void playerActions(); #endif \ No newline at end of file diff --git a/src/structure.h b/src/structure.h index d2f847e..674e4e2 100644 --- a/src/structure.h +++ b/src/structure.h @@ -29,6 +29,13 @@ typedef struct teleporter { double dest_z ; } teleporter ; +typedef struct entity { + cube_0* pos ; + void (*updatePos)(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, cube_0* ret) ; // act as velocity function + int damage ; + int hitpoints ; +} entity ; + struct room { // (0, 0, 0) = bottom, left and down int chunk_x ; @@ -61,6 +68,8 @@ typedef hashtbl_0* hashtbl ; // ------------------------------------------------ // +extern double sim_time ; + extern imgs digits ; extern imgs letters ;