a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit ca65e8820cee92715af2d7ceef5560321f0ccbb4
parent 9384ef0ecc5332bd44c2d8c64f63e6905d463114
Author: amin <dev@aminmesbah.com>
Date:   Thu, 25 Apr 2019 02:53:36 +0000

Add epsilon to player dist from collision boundary

Before it was being added to the distance of the collision boundary from
the associated tile it represented. That meant that if the player ended
up exactly on that boundary, they wouldn't be colliding with the _tile_,
but they _would_ be colliding with the boundary itself, causing them to
get stuck on it.

FossilOrigin-Name: 2f7b5a8c422490b3779ef4b6a0dd58dd3be74f84660301ea9974a34f4cd480b1
Diffstat:
Msrc/game.c | 19+++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -270,6 +270,7 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga if (player_is_in_tile && tile_id > 0) { color = (v3) {0.8f, 0.4f, 0.4f}; + assert(false); } } @@ -430,10 +431,6 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga }; rect tile_player_sum = glmth_minkowski_sum_rect_rect(tile_aabb, player->dimensions); - f32 collision_border_epsilon = 0.0001f; - tile_player_sum = glmth_minkowski_sum_rect_rect( - tile_player_sum, - (v2) {collision_border_epsilon, collision_border_epsilon}); RENDER_COLLISION_DEBUG_QUAD(tile_player_sum, ((v3) {0.8f, 0.4f, 0.4f})); v2 tile_nw = {tile_player_sum.min.x, tile_player_sum.max.y}; @@ -512,7 +509,21 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga v2 delta_to_nearest_collision = glmth_v2f_m(player_delta, smallest_distance_scale_factor); v2 nearest_collision_p = glmth_v2_a(player->pos, delta_to_nearest_collision); + f32 epsilon = 0.0001f; + rect local_inhabitable_region = { + .min = { + glmth_min(player->pos.x, nearest_collision_p.x + epsilon), + glmth_min(player->pos.y, nearest_collision_p.y + epsilon), + }, + .max = { + glmth_max(player->pos.x, nearest_collision_p.x - epsilon), + glmth_max(player->pos.y, nearest_collision_p.y - epsilon), + }, + }; + player->pos = nearest_collision_p; + glmth_clamp(&player->pos.x, local_inhabitable_region.min.x, local_inhabitable_region.max.x); + glmth_clamp(&player->pos.y, local_inhabitable_region.min.y, local_inhabitable_region.max.y); // NOTE(amin): // n * dot(v, n)