#define GFX_FOOD 0x03
+ ; resets update tile to 0/0
+tile_update_reset:
+ xor a, a
+ ld [update_tile_y], a
+ ld [update_tile_x], a
+
+ call tile_update_get
+
+ ret
+
; inits the next tile
- ; inputs:
- ; de: next tile
-tile_next_set:
- ld a, d
- ld [next_update_tile], a
- ld a, e
- ld [next_update_tile+1], a
+ ; increments update_tile_y/x
+ ; resets when out of bounds
+tile_update_get_next:
+ ld a, [update_tile_x]
+ inc a
+ cp a, MAP_W
+ jr nz, @not_y REL
+ ld a, [update_tile_y]
+ inc a
+ and a, MAP_H-1
+ ld [update_tile_y], a
+ xor a, a ; reset x
+@not_y:
+ ld [update_tile_x], a
+
+ call tile_update_get
+ ret
+
+ ; sets update_tile to the current selected tile
+ ; bsed on y/x position
+tile_update_get:
+ ld a, [update_tile_y]
+ ld b, a
+ ld a, [update_tile_x]
+ ld c, a
+ call map_get_tile
+
+ ld a, h
+ ld [update_tile], a
+ ld a, l
+ ld [update_tile+1], a
ret
; updates the next tile
; next_update_tile
; sets next_update_tile to next tile
; wraps to first tile if end is reached
-tile_next_update:
- ld a, [next_update_tile]
+tile_update_selected:
+ call tile_update_get_next
+
+ ld a, [update_tile]
ld d, a
- ld a, [next_update_tile+1]
+ ld a, [update_tile+1]
ld e, a
- push de
call tile_update
- pop de
-
- ; next tile
- ld hl, t_size
- add hl, de
- push hl
- pop de
- ; TODO: wrap back to start
- call tile_next_set
ret
+
+ ; draws the recently updated tile
+ ; bsed on update_tile y and x
+tile_update_draw:
+ ld a, [update_tile_y]
+ ld b, a
+ ld a, [update_tile_x]
+ ld c, a
+ jp map_draw_tile
+
; updates a tile with its
; routine
; inputs:
; de: tile
tile_update:
+ ; TODO: for now just inc t_tile
+ ld hl, t_tile
+ add hl, de
+ ld a, [hl]
+ inc a
+ ld [hl], a
ret
; table of update routines
; ptr to current tile
; selected by the player cursor
current_tile: .adv 2
-
- ; the next tile to be updated
-next_update_tile: .adv 2
+
+ ; the following values are set by tile_next_update
+update_tile_y: .adv 1
+update_tile_x: .adv 1
+update_tile: .adv 2
+ ; previpus frame's update tile
+ ; used for drawing the recently updated tile
+update_tile_prev_y: .adv 1
+update_tile_prev_x: .adv 1