Fix array out-of-bound error in tile collision
parent
5bbbaa19e2
commit
8c924956a8
|
@ -873,7 +873,6 @@ void player_crushing_system(Scene_t* scene)
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
// Left
|
||||
uint8_t collide_type = check_collision_line(&ent, &data->tilemap, false);
|
||||
if (collide_type == 1)
|
||||
|
@ -913,6 +912,12 @@ void spike_collision_system(Scene_t* scene)
|
|||
unsigned int tile_y1 = (p_ctransform->position.y) / TILE_SIZE;
|
||||
unsigned int tile_x2 = (p_ctransform->position.x + p_bbox->size.x - 1) / TILE_SIZE;
|
||||
unsigned int tile_y2 = (p_ctransform->position.y + p_bbox->size.y - 1) / TILE_SIZE;
|
||||
|
||||
tile_x1 = (tile_x1 < 0) ? 0 : tile_x1;
|
||||
tile_x2 = (tile_x2 >= tilemap.width) ? tilemap.width - 1 : tile_x2;
|
||||
tile_y1 = (tile_y1 < 0) ? 0 : tile_y1;
|
||||
tile_y2 = (tile_y2 >= tilemap.height) ? tilemap.height - 1 : tile_y2;
|
||||
|
||||
Vector2 overlap;
|
||||
for (unsigned int tile_y = tile_y1; tile_y <= tile_y2; tile_y++)
|
||||
{
|
||||
|
@ -974,6 +979,11 @@ void tile_collision_system(Scene_t* scene)
|
|||
unsigned int tile_x2 = (p_ctransform->position.x + p_bbox->size.x) / TILE_SIZE;
|
||||
unsigned int tile_y2 = (p_ctransform->position.y + p_bbox->size.y) / TILE_SIZE;
|
||||
|
||||
tile_x1 = (tile_x1 < 0) ? 0 : tile_x1;
|
||||
tile_x2 = (tile_x2 >= tilemap.width) ? tilemap.width - 1 : tile_x2;
|
||||
tile_y1 = (tile_y1 < 0) ? 0 : tile_y1;
|
||||
tile_y2 = (tile_y2 >= tilemap.height) ? tilemap.height - 1 : tile_y2;
|
||||
|
||||
for (unsigned int tile_y = tile_y1; tile_y <= tile_y2; tile_y++)
|
||||
{
|
||||
for (unsigned int tile_x = tile_x1; tile_x <= tile_x2; tile_x++)
|
||||
|
|
Loading…
Reference in New Issue