added structs for entities
This commit is contained in:
parent
2997f77c40
commit
5814dc5b05
|
@ -4,6 +4,9 @@
|
||||||
"stdio.h": "c",
|
"stdio.h": "c",
|
||||||
"math.h": "c",
|
"math.h": "c",
|
||||||
"sdl_image.h": "c",
|
"sdl_image.h": "c",
|
||||||
"display.h": "c"
|
"display.h": "c",
|
||||||
|
"generation.h": "c",
|
||||||
|
"time.h": "c",
|
||||||
|
"limits": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
3
Makefile
3
Makefile
|
@ -7,7 +7,7 @@ all: bin/back
|
||||||
test: bin/back
|
test: bin/back
|
||||||
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
|
mkdir -p bin
|
||||||
$(CC) $(FLAGS) $^ $(LFLAGS) -o $@
|
$(CC) $(FLAGS) $^ $(LFLAGS) -o $@
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ obj/%.o: src/%.c
|
||||||
obj/main.o: src/main.c
|
obj/main.o: src/main.c
|
||||||
obj/generation.o: src/generation.c
|
obj/generation.o: src/generation.c
|
||||||
obj/display.o: src/display.c
|
obj/display.o: src/display.c
|
||||||
|
obj/entities.o: src/entities.c
|
||||||
obj/move.o: src/move.c
|
obj/move.o: src/move.c
|
||||||
obj/base.o: src/base.c
|
obj/base.o: src/base.c
|
||||||
obj/hash.o: src/hash.c
|
obj/hash.o: src/hash.c
|
||||||
|
|
BIN
obj/display.o
BIN
obj/display.o
Binary file not shown.
Binary file not shown.
BIN
obj/main.o
BIN
obj/main.o
Binary file not shown.
|
@ -15,6 +15,7 @@
|
||||||
#include "structure.h"
|
#include "structure.h"
|
||||||
#include "base.h"
|
#include "base.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
|
#include "entities.h"
|
||||||
#include "generation.h"
|
#include "generation.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
#ifndef ENTITIES_H
|
||||||
|
#define ENTITIES_H
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
12
src/main.c
12
src/main.c
|
@ -15,9 +15,12 @@
|
||||||
#include "structure.h"
|
#include "structure.h"
|
||||||
#include "base.h"
|
#include "base.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
|
#include "entities.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "generation.h"
|
#include "generation.h"
|
||||||
|
|
||||||
|
double sim_time ;
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
|
@ -44,12 +47,17 @@ int main(int argc, char** argv) {
|
||||||
SDL_SetRelativeMouseMode(true) ;
|
SDL_SetRelativeMouseMode(true) ;
|
||||||
|
|
||||||
/* -------------------------------------------------------- */
|
/* -------------------------------------------------------- */
|
||||||
|
int fps = 60 ;
|
||||||
|
int interval = 1000000/fps ;
|
||||||
|
double intervalf = 1.0/((double)(fps)) ;
|
||||||
|
|
||||||
init_csts() ;
|
init_csts() ;
|
||||||
init_hashtbl() ;
|
init_hashtbl() ;
|
||||||
init_draworder() ;
|
init_draworder() ;
|
||||||
parse_rooms(3);
|
parse_rooms(3);
|
||||||
import_digits(rend) ;
|
import_digits(rend) ;
|
||||||
import_letters(rend) ;
|
import_letters(rend) ;
|
||||||
|
sim_time = 0.0 ;
|
||||||
clock_t origin = clock();
|
clock_t origin = clock();
|
||||||
clock_t finish = clock();
|
clock_t finish = clock();
|
||||||
float delta;
|
float delta;
|
||||||
|
@ -66,8 +74,10 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
delta = ((float)finish - (float)origin)/CLOCKS_PER_SEC;
|
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)(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) ;
|
updateRenderer(rend) ;
|
||||||
usleep(1000000/60) ;
|
sim_time += delta + intervalf ;
|
||||||
|
usleep(interval) ;
|
||||||
}
|
}
|
||||||
free_digits(digits) ;
|
free_digits(digits) ;
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define MOVE_H
|
#define MOVE_H
|
||||||
|
|
||||||
void init_csts();
|
void init_csts();
|
||||||
|
bool is_colliding();
|
||||||
void playerActions();
|
void playerActions();
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -29,6 +29,13 @@ typedef struct teleporter {
|
||||||
double dest_z ;
|
double dest_z ;
|
||||||
} teleporter ;
|
} 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 {
|
struct room {
|
||||||
// (0, 0, 0) = bottom, left and down
|
// (0, 0, 0) = bottom, left and down
|
||||||
int chunk_x ;
|
int chunk_x ;
|
||||||
|
@ -61,6 +68,8 @@ typedef hashtbl_0* hashtbl ;
|
||||||
|
|
||||||
// ------------------------------------------------ //
|
// ------------------------------------------------ //
|
||||||
|
|
||||||
|
extern double sim_time ;
|
||||||
|
|
||||||
extern imgs digits ;
|
extern imgs digits ;
|
||||||
extern imgs letters ;
|
extern imgs letters ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue