diff --git a/engine/collisions.c b/engine/collisions.c index 1de0994..75d12e6 100644 --- a/engine/collisions.c +++ b/engine/collisions.c @@ -173,9 +173,9 @@ uint8_t check_collision_offset(Entity_t* p_ent, Vector2 pos, Vector2 bbox_sz, Ti return check_collision(&ent, grid, false); } -bool check_on_ground(Entity_t* p_ent, Vector2 pos, Vector2 prev_pos, Vector2 bbox_sz, TileGrid_t* grid) +bool check_on_ground(Entity_t* p_ent, Vector2 prev_pos, Vector2 bbox_sz, TileGrid_t* grid) { - Vector2 new_pos = Vector2Add(pos, (Vector2){0, 1}); + Vector2 new_pos = Vector2Add(p_ent->position, (Vector2){0, 1}); CollideEntity_t ent = { .p_ent = p_ent, .bbox = (Rectangle){new_pos.x, new_pos.y + bbox_sz.y, bbox_sz.x, 1}, @@ -193,12 +193,13 @@ bool check_on_ground(Entity_t* p_ent, Vector2 pos, Vector2 prev_pos, Vector2 bbo uint8_t check_bbox_edges( TileGrid_t* tilemap, - Entity_t* p_ent, Vector2 pos, Vector2 bbox, + Entity_t* p_ent, Vector2 bbox, bool ignore_fragile ) { uint8_t detected = 0; + Vector2 pos = p_ent->position; // Too lazy to adjust the tile area to check, so just make a big one CollideEntity_t ent = { diff --git a/engine/collisions.h b/engine/collisions.h index ca4368e..f8629f8 100644 --- a/engine/collisions.h +++ b/engine/collisions.h @@ -60,6 +60,6 @@ void remove_entity_from_tilemap(EntityManager_t *p_manager, TileGrid_t* tilemap, uint8_t check_collision(const CollideEntity_t* ent, TileGrid_t* grid, bool check_oneway); uint8_t check_collision_line(const CollideEntity_t* ent, TileGrid_t* grid, bool check_oneway); uint8_t check_collision_offset(Entity_t* p_ent, Vector2 pos, Vector2 bbox_sz, TileGrid_t* grid, Vector2 offset); -bool check_on_ground(Entity_t* p_ent, Vector2 pos, Vector2 prev_pos, Vector2 bbox_sz, TileGrid_t* grid); -uint8_t check_bbox_edges(TileGrid_t* tilemap, Entity_t* p_ent, Vector2 pos, Vector2 bbox, bool ignore_fragile); +bool check_on_ground(Entity_t* p_ent, Vector2 prev_pos, Vector2 bbox_sz, TileGrid_t* grid); +uint8_t check_bbox_edges(TileGrid_t* tilemap, Entity_t* p_ent, Vector2 bbox, bool ignore_fragile); #endif // __COLLISION_FUNCS_H diff --git a/scenes/game_systems.c b/scenes/game_systems.c index b89c994..7dca325 100644 --- a/scenes/game_systems.c +++ b/scenes/game_systems.c @@ -591,7 +591,7 @@ void player_crushing_system(Scene_t* scene) uint8_t edges = check_bbox_edges( &data->tilemap, p_player, - p_player->position, p_bbox->size, true + p_bbox->size, true ); // There is a second check for to ensure that there is an solid entity/tile overlapping the player bbox @@ -829,7 +829,7 @@ void edge_velocity_check_system(Scene_t* scene) // Post movement edge check to zero out velocity uint8_t edges = check_bbox_edges( &data->tilemap, p_ent, - p_ent->position, p_bbox->size, false + p_bbox->size, false ); if (edges & (1<<3)) { @@ -963,7 +963,7 @@ void global_external_forces_system(Scene_t* scene) // Zero out acceleration for contacts with sturdy entites and tiles uint8_t edges = check_bbox_edges( &data->tilemap, p_ent, - p_ent->position, p_bbox->size, false + p_bbox->size, false ); if (edges & (1<<3)) { @@ -1406,7 +1406,7 @@ void state_transition_update_system(Scene_t* scene) else if (p_ctransform->velocity.x < 0) p_mstate->x_dir = 0; bool on_ground = check_on_ground( - p_ent, p_ent->position, p_ctransform->prev_position, p_bbox->size, + p_ent, p_ctransform->prev_position, p_bbox->size, &data->tilemap );