diff options
author | kartofen <mladenovnasko0@gmail.com> | 2023-04-15 23:41:51 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2023-04-15 23:41:51 +0300 |
commit | ba01065e0e61e3f35f31dda1824c2fd413c140ff (patch) | |
tree | 8860e9d014fec751d7d1b1ab8a42ceee26ae5be0 | |
parent | 27b4742f185a9780a975118093dc6fdce0575aeb (diff) |
-rw-r--r-- | src/player.h | 3 | ||||
-rw-r--r-- | src/sector.c | 17 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/player.h b/src/player.h index 3e957e9..81b5bf4 100644 --- a/src/player.h +++ b/src/player.h @@ -8,8 +8,9 @@ typedef struct player { struct xyz pos, velocity; // vectors for the player float angle, anglesin, anglecos; // angle, and its sine and cosine size_t sector; // the sector that the player is in + bool ducking; + float stand_height, duck_height, head_margin, knee_height; // eyeheights; minimum margin between current height and celling; maximum height objects the player can walk over - bool moving, ducking; } player_t; void player_default(player_t *player); diff --git a/src/sector.c b/src/sector.c index 96efed4..5255a76 100644 --- a/src/sector.c +++ b/src/sector.c @@ -96,7 +96,8 @@ int map_draw(map_t *map, int SW, int SH) int old_ytop = ytop[x], old_ybottom = ybottom[x]; // depth-shaded white color - uint wall_col = scale_color(COLOR_WHITE, (2*z/3)); + uint wall_col = //(x == x1 || x == x2) ? COLOR_BLACK : + scale_color(COLOR_WHITE, (2*z/3)); if(neighbor == (size_t)-1) { // no neighbor vline(x, cya, cyb, wall_col); @@ -165,9 +166,8 @@ void map_detect_collision(map_t *map) || !(pointside(px+dx, py+dy, vert(s0).x, vert(s0).y, vert(s1).x, vert(s1).y) < 0)) continue; - float hole_low = 0.0f, hole_high = 0.0f; - if(sect->neighbors[i] != (size_t)-1) - { + float hole_high = 0.0f, hole_low = 0.0f; + if(sect->neighbors[i] != (size_t)-1) { hole_high = min(sect->ceil, map->sectors[sect->neighbors[i]].ceil); hole_low = map->sectors[sect->neighbors[i]].floor; } @@ -178,14 +178,15 @@ void map_detect_collision(map_t *map) || hole_high - hole_low < eyeheight + player->head_margin) { // formula from wikipedia float xd = vert(s1).x - vert(s0).x, yd = vert(s1).y - vert(s0).y; - player->velocity.x = xd * (dx*xd + yd*dy) / (xd*xd + yd*yd); - player->velocity.y = yd * (dx*xd + yd*dy) / (xd*xd + yd*yd); + dx = xd * (dx*xd + yd*dy) / (xd*xd + yd*yd); + dy = yd * (dx*xd + yd*dy) / (xd*xd + yd*yd); } else { map->player.sector = sect->neighbors[i]; } - - break; } + + player->velocity.x = dx; + player->velocity.y = dy; } |