From: Lukas Krickl Date: Thu, 27 Nov 2025 12:53:57 +0000 (+0100) Subject: map: get_tile now returns a static null tile if oob coordinates are requested X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=c659ecadb18550d49ba6365750b3ad7415cefab7;p=gbrg%2F.git map: get_tile now returns a static null tile if oob coordinates are requested --- diff --git a/src/map.s b/src/map.s index ce2eb49..baaa292 100644 --- a/src/map.s +++ b/src/map.s @@ -189,6 +189,15 @@ map_draw_tile: ; returns: ; hl: tile map_get_tile: + ; check if out of bounds + ld a, b + cp a, MAP_H + jp nc, @oob_tile + + ld a, c + cp a, MAP_W + jp nc, @oob_tile + ld hl, tiles ld de, MAP_W * t_size @@ -215,6 +224,11 @@ map_get_tile: ; hl = tile now ret + +@oob_tile: + ; fallback tile + ld hl, tile_null + ret ; prepares tile draw ; by writing the expected tiles diff --git a/src/tiles.s b/src/tiles.s index e383c9e..230b933 100644 --- a/src/tiles.s +++ b/src/tiles.s @@ -9,7 +9,10 @@ tile_id_table: dw tile_grass dw tile_wall - + + ; fallback tile +tile_null: + tiledef 0, 0, 0 tile_grass: tiledef TT_EMPTY, 0, GFX_GRASS