added shooting mines

This commit is contained in:
Alexandre 2025-01-25 22:08:42 +01:00
parent 286d4ecbce
commit 5e3ff72046
17 changed files with 91 additions and 73 deletions

BIN
bin/back

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -811,14 +811,6 @@ void drawCurrentRoom(SDL_Renderer* renderer) {
for(int k = 0; k < triangles_i; k++) {
renderTriangleFull(renderer, triangles_order[k]);
}
/*for(int k = 0; k < triangles_i; k++) {
drawNumberToRenderer(renderer, digits,
(int)(3.3*(proj_pt_distance_to_camera(triangles_og_coords[k][0])+proj_pt_distance_to_camera(triangles_og_coords[k][1])+proj_pt_distance_to_camera(triangles_og_coords[k][2]))),
(int)(0.33*(triangles_to_render[k][0].x+triangles_to_render[k][1].x+triangles_to_render[k][2].x)),
(int)(0.33*(triangles_to_render[k][0].y+triangles_to_render[k][1].y+triangles_to_render[k][2].y)),
75/4, 105/4, 0
);
}*/
for(int k = 0; k < 0*triangles_i; k++) {
for(int l = 0; l < 3; l++) {
drawNumberToRenderer(renderer, digits,

View File

@ -60,18 +60,27 @@ 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) {
ret->vt_angle += ((double)dtime)*15.0;
ret->hz_angle += ((double)dtime)*15.0;
}
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) {
ret->hz_angle += ((double)dtime)*15.0;
ret->hz_angle += ((double)dtime)*22.5;
if((int)(10.0*ret->hz_angle) != (int)(10.0*(ret->hz_angle - ((double)dtime)*22.5))) {
double dx = (x+w/2 - camx);
double dy = (y+h/2 - camy);
double dz = (z+d/2 - camz);
double total = sqrt(dx*dx + dy*dy + dz*dz) ;
dx = 170.0*dx/total;
dy = 170.0*dy/total;
dz = 170.0*dz/total;
appendProj(x+w/2, y+h/2, z+d/2, -dx, -dy, -dz, 0.0, 0.0, 0.0, 192, 32, 192, 10, 2.0);
}
}
void speen3(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, cube_0* ret) {
ret->vt_angle += ((double)dtime)*22.5;
if((int)(ret->vt_angle) != (int)(ret->vt_angle - ((double)dtime)*22.5)) {
appendProj(x, y, z, 10.0 + rand()%15, 10.0 + rand()%15, 0.0, 0.0, 0.0, 0.0, 32, 32, 255);
//printf("app\n");
appendProj(x+w/2, y+h/2, z+d/2, 10.0 + rand()%15, 10.0 + rand()%15, 0.0, 0.0, 0.0, 0.0, 32, 32, 255, 1, 5.0);
}
}

View File

@ -41,7 +41,7 @@ void init_ent_generator(int n) {
hashtbl_entities[0].id = 0;
hashtbl_entities[0].name = "Coin"; // 0 = default
hashtbl_entities[0].updatePos = &speen2 ;
hashtbl_entities[0].updatePos = &speen ;
hashtbl_entities[0].onHit = &detectHit ;
hashtbl_entities[0].onDeath = NULL ;

View File

@ -83,19 +83,19 @@ int main(int argc, char** argv) {
entend = clock();
//printf("00\n");
//printf("%s\n", SDL_GetError());
fflush(stdout);
//fflush(stdout);
playerActions(((float)entend - (float)entstart)/CLOCKS_PER_SEC) ;
//printf("01\n");
fflush(stdout);
//fflush(stdout);
generate_nearby_chunks(1);
//printf("02\n");
fflush(stdout);
//fflush(stdout);
entend = clock();
update_entities(((float)entend - (float)entstart)/CLOCKS_PER_SEC);
updateAllProj(((float)entend - (float)entstart)/CLOCKS_PER_SEC);
//printf("03\n");
fflush(stdout);
//fflush(stdout);
entstart = clock();
//printf("-->%d\n", triangles_i);
@ -104,32 +104,35 @@ int main(int argc, char** argv) {
//printf("-->%d\n", triangles_i);
//printf("04\n");
//printf("%s\n", SDL_GetError());
fflush(stdout);
//fflush(stdout);
drawData(rend) ;
//printf("05\n");
fflush(stdout);
//fflush(stdout);
drawHPbar(rend);
//printf("06\n");
fflush(stdout);
//fflush(stdout);
finish = clock();
fade_dmg = max(fade_dmg-5, 0);
delta = ((float)finish - (float)origin)/CLOCKS_PER_SEC;
//printf("07\n");
fflush(stdout);
//fflush(stdout);
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);
drawNumberToRenderer(rend, digits, coins, 1500/2-55, 1000 - 70, 75/3, 105/3, 0);
//printf("08\n");
fflush(stdout);
//fflush(stdout);
//printf("%s\n", SDL_GetError());
updateRenderer(rend) ;
sim_time += delta + intervalf ;
//printf("09\n");
fflush(stdout);
//fflush(stdout);
if(player_hp <= 0) {
stop_evetything = true ;
}
usleep(interval) ;
}
//printf("GPNE\n");
fflush(stdout);
//fflush(stdout);
free_digits(digits) ;
for(int k = 0; k < MAX_SIZE; k++) {
@ -146,7 +149,7 @@ int main(int argc, char** argv) {
free(visited_tri);
free_proj();
//printf("10\n");
fflush(stdout);
//fflush(stdout);
hashtbl_free(visited);
free_pool();
@ -154,17 +157,17 @@ int main(int argc, char** argv) {
SDL_DestroyRenderer(rend);
//printf("10\n");
fflush(stdout);
//fflush(stdout);
SDL_DestroyWindow(win);
//printf("11\n");
fflush(stdout);
//fflush(stdout);
SDL_Quit();
//printf("12\n");
fflush(stdout);
//fflush(stdout);
/* -------------------------------------------------------- */
//printf("Done\n") ;
fflush(stdout);
//fflush(stdout);
return 0;
}

View File

@ -15,6 +15,7 @@
#include "structure.h"
#include "base.h"
#include "entities.h"
#include "proj.h"
#include "move.h"
// ---------------------------------------------------------------------------------------------------- //
@ -84,6 +85,7 @@ bool is_colliding(float dtime) {
player_chy = current_room->tps[k].dest_chy ;
current_room = hashtbl_find_opt(visited, player_chx, player_chy);
set_player_coords(old_chx, old_chy);
resetProj();
return true ;
}
}
@ -182,13 +184,10 @@ void playerActions(float dtime) {
if(state[SDL_SCANCODE_SPACE] == 1) {
stop_evetything = true ;
} else {
pass = true ;
}
if(state[SDL_SCANCODE_T] == 1) {
fprintf(stderr, "Killed.\n") ;
exit(1) ;
stop_evetything = true ;
}
if(state[SDL_SCANCODE_A] == 1) {

View File

@ -39,9 +39,11 @@ void init_proj() {
bullets[k]->vel = build_pt(0.0, 0.0, 0.0);
bullets[k]->acc = build_pt(0.0, 0.0, 0.0);
bullets[k]->size = 1.0;
bullets[k]->ttl = 1.0;
bullets[k]->red = 0;
bullets[k]->green = 0;
bullets[k]->blue = 0;
bullets[k]->damage = 0;
}
bullets_id = 0;
}
@ -66,6 +68,10 @@ bool is_proj_colliding_with_tp(double x, double y, double z, double size) {
return false ;
}
bool is_proj_colliding_w_player(double x, double y, double z, double size) {
return (distance_pt_pt_3d(x, y, z, camx, camy, camz) <= size);
}
double ppx, ppy, ppz;
double projx, projy;
void addProjectileToDraw(projectile* proj) {
@ -74,7 +80,7 @@ void addProjectileToDraw(projectile* proj) {
if(ppz >= draw_constant) {
projx = 1500.0 * (1.0 + (ppx / (1.5 * ppz * tan_fov))) / 2.0;
projy = 1000.0 * (1.0 + (ppy / (ppz * tan_fov))) / 2.0;
double rpsize = (40.0*psize/maxd(0.5, ppz));
double rpsize = (40.0*psize/maxd(0.07, ppz));
//printf("%lf\n", rpsize);
triangles_to_render[triangles_i][0] = build_pt(projx-rpsize/2, projy-rpsize/2, 0.0);
triangles_to_render[triangles_i][1] = build_pt(projx-rpsize/2, projy+rpsize/2, 0.0);
@ -107,12 +113,14 @@ void drawProj() {
}
}
void appendProj(double x, double y, double z, double vx, double vy, double vz, double ax, double ay, double az, int r, int g, int b) {
void appendProj(double x, double y, double z, double vx, double vy, double vz, double ax, double ay, double az, int r, int g, int b, int dmg, double ttl) {
if(bullets_id < MAX_SIZE) {
bullets[bullets_id]->red = r ;
bullets[bullets_id]->green = g ;
bullets[bullets_id]->blue = b ;
bullets[bullets_id]->size = 0.5 ;
bullets[bullets_id]->size = 1.0 ;
bullets[bullets_id]->damage = dmg ;
bullets[bullets_id]->ttl = ttl ;
bullets[bullets_id]->pos = build_pt(x, y, z) ;
bullets[bullets_id]->vel = build_pt(vx, vy, vz) ;
bullets[bullets_id]->acc = build_pt(ax, ay, az) ;
@ -128,28 +136,42 @@ void removeProj(int k) {
bullets[k]->pos = bullets[bullets_id]->pos;
bullets[k]->vel = bullets[bullets_id]->vel;
bullets[k]->acc = bullets[bullets_id]->acc;
bullets[k]->ttl = bullets[bullets_id]->ttl;
bullets[k]->damage = bullets[bullets_id]->damage;
bullets_id -= 1;
}
void updateAllProj(float dtime) {
for(int k = 0; k < bullets_id; k++) {
bullets[k]->vel.x += ((double)dtime)*(bullets[k]->acc.x) ;
bullets[k]->vel.y += ((double)dtime)*(bullets[k]->acc.y) ;
bullets[k]->vel.z += ((double)dtime)*(bullets[k]->acc.z) ;
bullets[k]->pos.x += ((double)dtime)*(bullets[k]->vel.x) ;
bullets[k]->pos.y += ((double)dtime)*(bullets[k]->vel.y) ;
bullets[k]->pos.z += ((double)dtime)*(bullets[k]->vel.z) ;
//if(k==0) printf("[%d] %lf, %lf, %lf\n", k, bullets[k]->pos.x, bullets[k]->pos.y, bullets[k]->pos.z);
if(
is_proj_colliding_with_map(bullets[k]->pos.x - bullets[k]->size/2, bullets[k]->pos.y - bullets[k]->size/2, bullets[k]->pos.z - bullets[k]->size/2, bullets[k]->size) ||
is_proj_colliding_with_tp(bullets[k]->pos.x - bullets[k]->size/2, bullets[k]->pos.y - bullets[k]->size/2, bullets[k]->pos.z - bullets[k]->size/2, bullets[k]->size)
) {
bullets[k]->vel.x += ((double)dtime)*(bullets[k]->acc.x);
bullets[k]->vel.y += ((double)dtime)*(bullets[k]->acc.y);
bullets[k]->vel.z += ((double)dtime)*(bullets[k]->acc.z);
bullets[k]->pos.x += ((double)dtime)*(bullets[k]->vel.x);
bullets[k]->pos.y += ((double)dtime)*(bullets[k]->vel.y);
bullets[k]->pos.z += ((double)dtime)*(bullets[k]->vel.z);
bullets[k]->ttl -= 20.0*(double)dtime;
//if(k==0) printf("[%d] %lf\n", k, bullets[k]->ttl);
if(is_proj_colliding_w_player(bullets[k]->pos.x - bullets[k]->size/2.0, bullets[k]->pos.y - bullets[k]->size/2.0, bullets[k]->pos.z - bullets[k]->size/2.0, bullets[k]->size)) {
if(bullets[k]->damage != 0) {
player_hp -= bullets[k]->damage ;
fade_dmg = 255 ;
}
removeProj(k);
k -= 1;
} else if(bullets[k]->ttl <= 0.0 || (
is_proj_colliding_with_map(bullets[k]->pos.x - bullets[k]->size/2.0, bullets[k]->pos.y - bullets[k]->size/2.0, bullets[k]->pos.z - bullets[k]->size/2.0, bullets[k]->size) ||
is_proj_colliding_with_tp(bullets[k]->pos.x - bullets[k]->size/2.0, bullets[k]->pos.y - bullets[k]->size/2.0, bullets[k]->pos.z - bullets[k]->size/2.0, bullets[k]->size)
)) {
removeProj(k);
k -= 1;
}
}
}
void resetProj() {
bullets_id = 0;
}
void free_proj() {
for(int k = 0; k < MAX_SIZE; k++) {
free(bullets[k]);

View File

@ -6,17 +6,21 @@ typedef struct projectile {
pt_2d vel ;
pt_2d acc ;
double size;
double ttl;
int red;
int green;
int blue;
int damage;
} projectile ;
void init_proj();
void free_proj();
void drawProj();
void appendProj(double x, double y, double z, double vx, double vy, double vz, double ax, double ay, double az, int r, int g, int b);
void appendProj(double x, double y, double z, double vx, double vy, double vz, double ax, double ay, double az, int r, int g, int b, int dmg, double ttl);
void removeProj(int k);
void updateAllProj(float dtime);
void resetProj();
#endif

View File

@ -318,17 +318,6 @@ bool is_hidden(SDL_Renderer* renderer, pt_2d p, pt_2d ogp, pt_2d* tri, pt_2d* og
return false;
}
get_barycentric(p, tri, &u, &v, &w);
/*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;
r.y = (int)(1000.0 * (1.0 + (mid.y / (mid.z * tan_fov))) / 2.0) -2;
r.w = 4 ;
r.h = 4 ;
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);
@ -341,6 +330,19 @@ bool is_hidden(SDL_Renderer* renderer, pt_2d p, pt_2d ogp, pt_2d* tri, pt_2d* og
}
bool is_in_front(pt_2d* tri1, pt_2d* og1, pt_2d* tri2, pt_2d* og2) {
for(int k1 = 0; k1 < 3; k1++) {
for(int k2 = 0; k2 < 3; k2++) {
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);
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);
}
}
}
}
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)) {
@ -371,18 +373,5 @@ bool is_in_front(pt_2d* tri1, pt_2d* og1, pt_2d* tri2, pt_2d* og2) {
}
}
}
for(int k1 = 0; k1 < 3; k1++) {
for(int k2 = 0; k2 < 3; k2++) {
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);
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);
}
}
}
}
return false;
}

View File

@ -13,6 +13,6 @@ Entities :
[0.0, 40.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 255, 64, 0, 5, 100, 2]
Weight :
10
500
$