Added bounds check for collision detection.
This commit is contained in:
@@ -149,6 +149,10 @@ check_map_collision :: proc(rect: rl.Rectangle, game_map: Game_Map) -> bool {
|
|||||||
// check all points along the x axis per y axis 'row'
|
// check all points along the x axis per y axis 'row'
|
||||||
for gy := min_grid[1]; gy <= max_grid[1]; gy += 1 {
|
for gy := min_grid[1]; gy <= max_grid[1]; gy += 1 {
|
||||||
for gx := min_grid[0]; gx <= max_grid[0]; gx += 1 {
|
for gx := min_grid[0]; gx <= max_grid[0]; gx += 1 {
|
||||||
|
|
||||||
|
// bounds check
|
||||||
|
if gx < 0 || gx >= game_map.width || gy < 0 || gy >= game_map.height do continue
|
||||||
|
|
||||||
idx := (gy * game_map.width) + gx
|
idx := (gy * game_map.width) + gx
|
||||||
tile := Tile_Type(game_map.data[idx])
|
tile := Tile_Type(game_map.data[idx])
|
||||||
def := tile_defs[tile]
|
def := tile_defs[tile]
|
||||||
|
|||||||
Reference in New Issue
Block a user