mines
This commit is contained in:
parent
0c3e582cd2
commit
e265292843
3
Makefile
3
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/entities.o obj/triangles.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/menus.o obj/triangles.o obj/move.o obj/base.o obj/hash.o
|
||||
mkdir -p bin
|
||||
$(CC) $(FLAGS) $^ $(LFLAGS) -o $@
|
||||
|
||||
|
@ -22,6 +22,7 @@ obj/entities.o: src/entities.c
|
|||
obj/triangles.o: src/triangles.c
|
||||
obj/move.o: src/move.c
|
||||
obj/base.o: src/base.c
|
||||
obj/hash.o: src/menus.c
|
||||
obj/hash.o: src/hash.c
|
||||
|
||||
.PHONY: clean mrproper
|
||||
|
|
BIN
obj/display.o
BIN
obj/display.o
Binary file not shown.
BIN
obj/entities.o
BIN
obj/entities.o
Binary file not shown.
BIN
obj/generation.o
BIN
obj/generation.o
Binary file not shown.
BIN
obj/main.o
BIN
obj/main.o
Binary file not shown.
Binary file not shown.
BIN
obj/triangles.o
BIN
obj/triangles.o
Binary file not shown.
|
@ -779,7 +779,7 @@ void renderTriangleFull(SDL_Renderer* renderer, int k) {
|
|||
}
|
||||
|
||||
void remove_hidden(SDL_Renderer* renderer) {
|
||||
printf("%d --> ", triangles_i);
|
||||
//printf("%d --> ", triangles_i);
|
||||
for(int k = 0; k < triangles_i; k++) {
|
||||
int halt = 1 ;
|
||||
bool fst = false ;
|
||||
|
@ -804,8 +804,9 @@ void remove_hidden(SDL_Renderer* renderer) {
|
|||
}
|
||||
}
|
||||
}
|
||||
halt = 1 ;
|
||||
}
|
||||
printf("%d\n", triangles_i);
|
||||
//printf("%d\n", triangles_i);
|
||||
}
|
||||
|
||||
void visit(int k, bool vflag) {
|
||||
|
|
|
@ -71,8 +71,40 @@ void detectHit(float dtime, int* hp, int* dmg, cube_0* ret) {
|
|||
ret->green = 192;
|
||||
ret->blue = 0;
|
||||
coins += *hp;
|
||||
player_hp -= 10*(*hp);
|
||||
player_hp -= (*dmg);
|
||||
if(*dmg != 0) {
|
||||
fade_dmg = 255 ;
|
||||
}
|
||||
*hp = 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
void go_to_player(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, cube_0* ret) {
|
||||
double dx = (x+w/2 - camx) ;
|
||||
double dy = (y+h/2 - camy) ;
|
||||
double dz = (z+d/2 - camz);
|
||||
dx = 10.0*dx/absf(dx);
|
||||
dy = 10.0*dy/absf(dy);
|
||||
dz = 10.0*dz/absf(dz);
|
||||
ret->x -=12.0*dtime*dx ;
|
||||
if(is_colliding_with_map(*ret) || is_colliding_with_tp(*ret)) {
|
||||
ret->x +=12.0*dtime*dx ;
|
||||
}
|
||||
ret->y -=12.0*dtime*dy ;
|
||||
if(is_colliding_with_map(*ret) || is_colliding_with_tp(*ret)) {
|
||||
ret->y +=12.0*dtime*dy ;
|
||||
}
|
||||
ret->z -=12.0*dtime*dz ;
|
||||
if(is_colliding_with_map(*ret) || is_colliding_with_tp(*ret)) {
|
||||
ret->z +=12.0*dtime*dz ;
|
||||
}
|
||||
}
|
||||
|
||||
void explodeOnHit(float dtime, int* hp, int* dmg, cube_0* ret) {
|
||||
|
||||
player_hp -= (*dmg);
|
||||
if(*dmg != 0) {
|
||||
fade_dmg = 255 ;
|
||||
}
|
||||
*hp = 0 ;
|
||||
}
|
|
@ -8,9 +8,11 @@ void update_entity(entity* ent, float dtime);
|
|||
void update_entities(float dtime);
|
||||
|
||||
void speen(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, cube_0* ret);
|
||||
|
||||
void speen2(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, cube_0* ret);
|
||||
|
||||
void go_to_player(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, cube_0* ret);
|
||||
|
||||
void detectHit(float dtime, int* hp, int* dmg, cube_0* ret);
|
||||
void explodeOnHit(float dtime, int* hp, int* dmg, cube_0* ret);
|
||||
|
||||
#endif
|
|
@ -28,6 +28,44 @@ int pool_size ;
|
|||
int total_weight ;
|
||||
|
||||
int coins ;
|
||||
int fct_entry_size ;
|
||||
|
||||
fct_entry* hashtbl_entities ;
|
||||
|
||||
void init_ent_generator(int n) {
|
||||
hashtbl_entities = malloc(sizeof(fct_entry)*n);
|
||||
fct_entry_size = n;
|
||||
for(int k = 0; k < 10; k++) {
|
||||
hashtbl_entities[k].id = (-1) ;
|
||||
}
|
||||
|
||||
hashtbl_entities[0].id = 0;
|
||||
hashtbl_entities[0].name = "Coin"; // 0 = default
|
||||
hashtbl_entities[0].updatePos = &speen2 ;
|
||||
hashtbl_entities[0].onHit = &detectHit ;
|
||||
hashtbl_entities[0].onDeath = NULL ;
|
||||
|
||||
hashtbl_entities[1].id = 1;
|
||||
hashtbl_entities[1].name = "ExplosiveStill";
|
||||
hashtbl_entities[1].updatePos = &speen2 ;
|
||||
hashtbl_entities[1].onHit = &explodeOnHit ;
|
||||
hashtbl_entities[1].onDeath = NULL ;
|
||||
|
||||
hashtbl_entities[2].id = 2;
|
||||
hashtbl_entities[2].name = "ExplosiveSeek";
|
||||
hashtbl_entities[2].updatePos = &go_to_player ;
|
||||
hashtbl_entities[2].onHit = &explodeOnHit ;
|
||||
hashtbl_entities[2].onDeath = NULL ;
|
||||
}
|
||||
|
||||
fct_entry* get_entry(int k0) {
|
||||
for(int k = 0; k < fct_entry_size; k++) {
|
||||
if(hashtbl_entities[k].id == k0) {
|
||||
return &(hashtbl_entities[k]);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void copy_room(room* src, room* dest, int chx, int chy) {
|
||||
// considering dest has already been malloc'd
|
||||
|
@ -279,14 +317,20 @@ void parse_one_room(int id, char* filename) {
|
|||
int blue = read_int(ptr, true);
|
||||
int hp = read_int(ptr, true);
|
||||
int dmg = read_int(ptr, true);
|
||||
int fid = read_int(ptr, true);
|
||||
fct_entry* entry = get_entry(fid);
|
||||
if(entry == NULL) {
|
||||
entry = get_entry(0);
|
||||
}
|
||||
pool[id].area->ents[k].pos = malloc(sizeof(cube_0));
|
||||
*(pool[id].area->ents[k].pos) = create_cube_0(cx, cy, cz, cw, ch, cd, chz, cvt, red, green, blue);
|
||||
pool[id].area->ents[k].damage = dmg ;
|
||||
pool[id].area->ents[k].hitpoints = malloc(sizeof(int));
|
||||
*(pool[id].area->ents[k].hitpoints) = hp ;
|
||||
pool[id].area->ents[k].updatePos = *speen ;
|
||||
pool[id].area->ents[k].onHit = *detectHit ;
|
||||
pool[id].area->ents[k].onDeath = NULL ;
|
||||
|
||||
pool[id].area->ents[k].updatePos = entry->updatePos ;
|
||||
pool[id].area->ents[k].onHit = entry->onHit ;
|
||||
pool[id].area->ents[k].onDeath = entry->onDeath ;
|
||||
//printf("\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,18 @@ typedef struct entry {
|
|||
int weight ;
|
||||
} entry ;
|
||||
|
||||
typedef struct fct_entry {
|
||||
int id ;
|
||||
char* name ;
|
||||
void (*updatePos)(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, cube_0* ret) ;
|
||||
// act as velocity function
|
||||
void (*onHit)(float dtime, int* hp, int* dmg, cube_0* ret) ;
|
||||
// triggers when object is hit
|
||||
void (*onDeath)(float dtime) ;
|
||||
} fct_entry ;
|
||||
|
||||
void init_ent_generator(int n);
|
||||
|
||||
void copy_room(room* src, room* dest, int chx, int chy) ;
|
||||
void build_starting_chunk(int chx, int chy) ;
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ int main(int argc, char** argv) {
|
|||
init_csts();
|
||||
init_hashtbl();
|
||||
init_draworder();
|
||||
init_ent_generator(10);
|
||||
trInit();
|
||||
parse_rooms(5);
|
||||
import_digits(rend) ;
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#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"
|
||||
#include "menus.h"
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef MENUS_H
|
||||
#define MENUS_H
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -304,16 +304,21 @@ bool pt_equal(pt_2d p1, pt_2d p2, double epsilon) {
|
|||
return (absf(p2.x - p1.x) <= epsilon && absf(p2.y - p1.y) <= epsilon && absf(p2.z - p1.z) <= epsilon) ;
|
||||
}
|
||||
|
||||
bool nonzero(double tha, double thb, double thc, double epsilon) {
|
||||
return (absf(tha) > epsilon && absf(thb) > epsilon && absf(thc) > epsilon);
|
||||
}
|
||||
|
||||
double u = 0.0 ;
|
||||
double v = 0.0 ;
|
||||
double w = 0.0 ;
|
||||
double th1, th2;
|
||||
double dist ;
|
||||
bool is_hidden(SDL_Renderer* renderer, pt_2d p, pt_2d ogp, pt_2d* tri, pt_2d* og) {
|
||||
if(pt_equal(p, tri[0], 0.0001) || pt_equal(p, tri[1], 0.0001) || pt_equal(p, tri[2], 0.0001)) {
|
||||
return false;
|
||||
}
|
||||
double u = 0.0 ;
|
||||
double v = 0.0 ;
|
||||
double w = 0.0 ;
|
||||
get_barycentric(p, tri, &u, &v, &w);
|
||||
pt_2d mid = convex_pt2d_tri(og[0], u, og[1], v, og[2], w);
|
||||
if(renderer != NULL && (u >= 0.0) && (v >= 0.0) && (w >= 0.0) && (u+v+w <= 1.0)) {
|
||||
/*if(renderer != NULL && (u >= 0.0) && (v >= 0.0) && (w >= 0.0) && (u+v+w <= 1.0)) {
|
||||
if(mid.z >= 0.4) {
|
||||
SDL_Rect r;
|
||||
r.x = (int)(1500.0 * (1.0 + (mid.x / (1.5 * mid.z * tan_fov))) / 2.0) -2;
|
||||
|
@ -323,30 +328,32 @@ bool is_hidden(SDL_Renderer* renderer, pt_2d p, pt_2d ogp, pt_2d* tri, pt_2d* og
|
|||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
SDL_RenderFillRect(renderer, &r);
|
||||
}
|
||||
}*/
|
||||
if(((u >= 0.0) && (v >= 0.0) && (w >= 0.0) && (u+v+w <= 1.0)) && nonzero(u, v, w, 0.0001)) {
|
||||
pt_2d mid = convex_pt2d_tri(og[0], u, og[1], v, og[2], w);
|
||||
dist = proj_pt_distance_to_camera(mid) - proj_pt_distance_to_camera(ogp);
|
||||
if(absf(dist) >= 0.0001) {
|
||||
//return (proj_pt_distance_to_camera(mid) <= proj_pt_distance_to_camera(ogp));
|
||||
return (dist <= 0.0);
|
||||
}
|
||||
if((u >= 0.0) && (v >= 0.0) && (w >= 0.0) && (u+v+w <= 1.0)) {
|
||||
return (proj_pt_distance_to_camera(mid) <= proj_pt_distance_to_camera(ogp));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool nonzero(double tha, double thb, double thc, double epsilon) {
|
||||
return (absf(tha) > epsilon && absf(thb) > epsilon && absf(thc) > epsilon);
|
||||
}
|
||||
|
||||
bool is_in_front(pt_2d* tri1, pt_2d* og1, pt_2d* tri2, pt_2d* og2) {
|
||||
for(int k = 0; k < 3; k++) {
|
||||
pt_2d p = tri1[k];
|
||||
if(pt_equal(p, tri2[0], 0.0001) || pt_equal(p, tri2[1], 0.0001) || pt_equal(p, tri2[2], 0.0001)) {
|
||||
return false;
|
||||
}
|
||||
double u = 0.0 ;
|
||||
double v = 0.0 ;
|
||||
double w = 0.0 ;
|
||||
get_barycentric(p, tri2, &u, &v, &w);
|
||||
pt_2d mid = convex_pt2d_tri(og2[0], u, og2[1], v, og2[2], w);
|
||||
if(((u >= 0.0) && (v >= 0.0) && (w >= 0.0) && (u+v+w <= 1.0)) && nonzero(u, v, w, 0.0001)) {
|
||||
return !(proj_pt_distance_to_camera(mid) <= proj_pt_distance_to_camera(og1[k]));
|
||||
dist = proj_pt_distance_to_camera(mid) - proj_pt_distance_to_camera(og1[k]);
|
||||
if(absf(dist) >= 0.0001) {
|
||||
//return !(proj_pt_distance_to_camera(mid) <= proj_pt_distance_to_camera(og1[k]));
|
||||
return !(dist <= 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int k = 0; k < 3; k++) {
|
||||
|
@ -354,22 +361,26 @@ bool is_in_front(pt_2d* tri1, pt_2d* og1, pt_2d* tri2, pt_2d* og2) {
|
|||
if(pt_equal(p, tri1[0], 0.0001) || pt_equal(p, tri1[1], 0.0001) || pt_equal(p, tri1[2], 0.0001)) {
|
||||
return false;
|
||||
}
|
||||
double u = 0.0 ;
|
||||
double v = 0.0 ;
|
||||
double w = 0.0 ;
|
||||
get_barycentric(p, tri1, &u, &v, &w);
|
||||
pt_2d mid = convex_pt2d_tri(og1[0], u, og1[1], v, og1[2], w);
|
||||
if(((u >= 0.0) && (v >= 0.0) && (w >= 0.0) && (u+v+w <= 1.0)) && nonzero(u, v, w, 0.0001)) {
|
||||
return !(proj_pt_distance_to_camera(mid) >= proj_pt_distance_to_camera(og2[k]));
|
||||
dist = proj_pt_distance_to_camera(mid) - proj_pt_distance_to_camera(og2[k]);
|
||||
if(absf(dist) >= 0.0001) {
|
||||
//return !(proj_pt_distance_to_camera(mid) >= proj_pt_distance_to_camera(og2[k]));
|
||||
return !(dist >= 0.0) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int k1 = 0; k1 < 3; k1++) {
|
||||
for(int k2 = 0; k2 < 3; k2++) {
|
||||
double th1, th2;
|
||||
if(seg_seg_inter(tri1[k1], tri1[(k1+1)%3], tri2[k2], tri2[(k2+1)%3], &th1, &th2)) {
|
||||
pt_2d mid1 = convex_pt2d(tri1[k1], tri1[(k1+1)%3], th1);
|
||||
pt_2d mid2 = convex_pt2d(tri2[k2], tri2[(k2+1)%3], th2);
|
||||
return (proj_pt_distance_to_camera(mid1) <= proj_pt_distance_to_camera(mid2));
|
||||
dist = proj_pt_distance_to_camera(mid1) - proj_pt_distance_to_camera(mid2);
|
||||
if(absf(dist) >= 0.0001) {
|
||||
//return (proj_pt_distance_to_camera(mid1) <= proj_pt_distance_to_camera(mid2));
|
||||
return (dist <= 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,14 +12,14 @@ Teleporters :
|
|||
[7.0, 0.0, -1.0, 2.0, 1.0, 2.0, 0.0, 0.0, 0, 0, 255; 1, 0]
|
||||
|
||||
Entities :
|
||||
[0.0, 3.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0]
|
||||
[0.0, 4.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0]
|
||||
[0.0, 5.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0]
|
||||
[0.0, 6.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0]
|
||||
[0.0, 7.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0]
|
||||
[0.0, 8.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0]
|
||||
[0.0, 9.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0]
|
||||
[0.0, 10.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0]
|
||||
[0.0, 3.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0]
|
||||
[0.0, 4.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0]
|
||||
[0.0, 5.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0]
|
||||
[0.0, 6.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0]
|
||||
[0.0, 7.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0]
|
||||
[0.0, 8.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0]
|
||||
[0.0, 9.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0]
|
||||
[0.0, 10.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0]
|
||||
|
||||
Weight :
|
||||
10
|
||||
|
|
|
@ -14,10 +14,10 @@ Teleporters :
|
|||
[-5.0, 1.0, 9.0, 10.0, 2.0, 1.0, 0.0, 0.0, 0, 0, 255; 1, 0]
|
||||
|
||||
Entities :
|
||||
[3.0, 3.0, 3.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0]
|
||||
[-3.0, 3.0, 3.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0]
|
||||
[3.0, 3.0, -3.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0]
|
||||
[-3.0, 3.0, -3.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0]
|
||||
[3.0, 3.0, 3.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0]
|
||||
[-3.0, 3.0, 3.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0]
|
||||
[3.0, 3.0, -3.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0]
|
||||
[-3.0, 3.0, -3.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0]
|
||||
|
||||
Weight :
|
||||
20
|
||||
|
|
|
@ -8,7 +8,11 @@ Teleporters :
|
|||
[9.0, 1.0, -5.0, 1.0, 2.0, 10.0, 0.0, 0.0, 0, 255, 0; 0, 1]
|
||||
[-5.0, 1.0, 9.0, 10.0, 2.0, 1.0, 0.0, 0.0, 0, 0, 255; 1, 0]
|
||||
|
||||
Entities :
|
||||
[0.0, 3.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 255, 64, 0, 5, 100, 1]
|
||||
[0.0, 40.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 255, 64, 0, 5, 100, 2]
|
||||
|
||||
Weight :
|
||||
10
|
||||
100
|
||||
|
||||
$
|
Loading…
Reference in New Issue