added structs for entities

This commit is contained in:
Alexandre 2025-01-05 17:03:18 +01:00
parent 2997f77c40
commit 5814dc5b05
12 changed files with 80 additions and 3 deletions

View File

@ -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"
}
}

View File

@ -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

BIN
bin/back

Binary file not shown.

Binary file not shown.

BIN
obj/entities.o Normal file

Binary file not shown.

Binary file not shown.

View File

@ -15,6 +15,7 @@
#include "structure.h"
#include "base.h"
#include "move.h"
#include "entities.h"
#include "generation.h"
#include "display.h"

47
src/entities.c Normal file
View File

@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <stdbool.h>
#include <ncurses.h>
#include <unistd.h>
#include <termios.h>
#include <limits.h>
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#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);
}

5
src/entities.h Normal file
View File

@ -0,0 +1,5 @@
#ifndef ENTITIES_H
#define ENTITIES_H
#endif

View File

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

View File

@ -2,6 +2,7 @@
#define MOVE_H
void init_csts();
bool is_colliding();
void playerActions();
#endif

View File

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