tiles: added test for food spread master origin/HEAD origin/master
authorLukas Krickl <lukas@krickl.dev>
Fri, 14 Nov 2025 08:41:56 +0000 (09:41 +0100)
committerLukas Krickl <lukas@krickl.dev>
Fri, 14 Nov 2025 08:41:56 +0000 (09:41 +0100)
src/tiles.s

index 86c1d9158da9a10856f03d7175280130bd027f46..d61509f03a0f1aac61965d46b2bc859cb5946a06 100644 (file)
@@ -243,17 +243,90 @@ tile_get_adjacent:
 
        ret
 
 
        ret
 
+       ; checks one tile for a type match
+       ; inputs:
+       ;               hl: ptr to next tile
+       ;                a: expected tile type
+       ;                b: current tile match count
+       ;       returns:
+       ;               incremnets b if type matches
+       ;               hl+=2 (next ptr)
+       ;       preserves:
+       ;               a
+#macro tile_count_adjacent_check
+.beginscope
+               push af
+               ld a, [hl+]
+               ld d, a
+               ld a, [hl+]
+               ld e, a
+               ; hl = next ptr
+
+               ; de = ptr to tile
+               push hl
+               ld hl, t_type
+               add hl, de
+               ; hl = tile type
+               ld a, [hl]
+               ld c, a ; c = tile type
+               pop hl
+
+               pop af
+               cp a, c
+               ; check if match
+               jr nz, @no_match REL
+                       inc b ; result++
+@no_match:
+.endscope
+#endmacro
+
+       ; counts adjacent tiles of specific type
+       ; inputs:
+       ;               a: expected type
+       ;       returns:
+       ;               a: count of type
+tile_count_adjacent:
+       ; b = result
+       ld b, 0
+
+       ; hl = ptrs to tiles
+       ld hl, tiles_adjacent
+       
+       ; check 8 tiles
+       tile_count_adjacent_check
+       tile_count_adjacent_check
+       tile_count_adjacent_check
+       tile_count_adjacent_check
+
+       tile_count_adjacent_check
+       tile_count_adjacent_check
+       tile_count_adjacent_check
+       tile_count_adjacent_check
+       
+       ; result is in a now
+       ld a, b
+       ret
+
+
        ; updates empty tile
        ; inputs:
        ;               de: tile
 tile_update_empty:
        ; updates empty tile
        ; inputs:
        ;               de: tile
 tile_update_empty:
+       ld a, TT_FOOD
+       push de
+       call tile_count_adjacent
+       pop de
+       
+       ; if 2 adjacnet food tiles
+       ; turn into food
+       cp a, 2 
+       ret c
 
 
-       ; TODO: for now just inc t_tile
-       ld hl, t_tile
-       add hl, de
-       ld a, [hl]
-       inc a
-       ; ld [hl], a
+       push de
+       pop hl ; hl = dst
+       ld de, tile_food
+       ld bc, t_size
+       call memcpy
        ret
        
        ; updates controlled tile
        ret
        
        ; updates controlled tile