dw tile_update_enemy_hive
dw tile_update_food
+strz str_empty, "EMPTY"
+strz str_player_hive, "YOUR HIVE"
+strz str_enemy_hive, "HIVE"
+strz str_player, "PLAYER"
+strz str_enemy, "ENEMY"
+strz str_food, "FOOD"
+
+ ; mapping of tile ids to
+ ; the tile names
+tile_str_table:
+ dw str_empty
+ dw str_player
+ dw str_player_hive
+ dw str_enemy
+ dw str_enemy_hive
+ dw str_food
+
+
; updates empty tile
; inputs:
; de: tile
-; draw one TILE_MOVE tile
-; in top row for each move remaining
-#define UI_TILE_MOVE 0xC0
-#define UI_TILE_MOVE_USED 0xC1
-
-#define UI_PLAYER_HP SCRN1+33
-#define UI_ENEMY_HP SCRN1+65
+#define UI_TILE_NAME SCRN1+33
; one tile after 'Z'
#define UI_WINDOW_BACKGROUND 0xF4
#define UI_TILE_HP_2 0xCA
#define UI_TILE_HP_1 0xCB
-
-strz str_player, "PLAYER"
-strz str_enemy, "ENEMY"
-
; inits UI
ui_init:
- call ui_draw_all
+ ld hl, ui_draw_nop
+ call ui_request_draw
ret
; updates UI
; checks if a UI draw is required
; usually this occurs when
; the player cursor enters a new tile
+ ; sets current tile y/x and ptr
ui_update:
; check y
- ld a, [ui_prev_tile_y]
+ ld a, [current_tile_y]
ld b, a
ld a, [player+act_pos_y]
add a, PLAYER_TILE_OFFSET
div16 a
- ld [ui_prev_tile_y], a
+ ld [current_tile_y], a
cp a, b ; are they differnet?
jr nz, @draw_new REL
; check x
- ld a, [ui_prev_tile_x]
+ ld a, [current_tile_x]
ld b, a
ld a, [player+act_pos_x]
add a, PLAYER_TILE_OFFSET
div16 a
- ld [ui_prev_tile_x], a
+ ld [current_tile_x], a
cp a, b ; ar they dfifernet?
ret z ; no need to proceed
@draw_new:
+
+ ; save current tile
+ ; this can be used in various places
+ ld a, [current_tile_y]
+ ld b, a
+ ld a, [current_tile_x]
+ ld c, a
+ call map_get_tile
+ ld a, h
+ ld [current_tile], a
+ ld a, l
+ ld [current_tile+1], a
+ ld hl, ui_draw_tile_name
call ui_request_draw
ret
; requests a draw
; for UI information about the current tile
+ ; inputs:
+ ; hl: routine ptr to draw
ui_request_draw:
+ ld a, h
+ ld [ui_draw_routine], a
+ ld a, l
+ ld [ui_draw_routine+1], a
+ ret
+
+ ; no draw
+ui_draw_nop:
+ ret
+
+ ; ui draw tile name
+ui_draw_tile_name:
+ ld a, [current_tile]
+ ld h, a
+ ld a, [current_tile+1]
+
+ ld a, [hl] ; load type
+ add a, a ; * 2 for offset
+
+ ld d, 0
+ ld e, a
+ ld hl, tile_str_table
+ add hl, de
+
+ ld a, [hl+]
+ ld b, a
+ ld a, [hl]
+ ld h, a
+ ld a, b
+ ld l, a
+
+ ld de, UI_TILE_NAME
+ call puts
+
+ ld hl, ui_draw_nop
+ call ui_request_draw
ret
; draws the entire UI
; only call during blank
-ui_draw_all:
- ret
+ui_draw:
+ ld a, [ui_draw_routine]
+ ld h, a
+ ld a, [ui_draw_routine+1]
+ ld l, a
+ xor a, h
+ ret z
+ jp hl
+
tile_curr: .adv 2
tiles: .adv t_size * MAP_TILES
-ui_prev_tile_y: .adv 1
-ui_prev_tile_x: .adv 1
+
+ui_draw_routine: .adv 1
+
+ ; the following valuess are set by ui_update
+ ; coordinates of current tile
+current_tile_y: .adv 1
+current_tile_x: .adv 1
+ ; ptr to current tile
+ ; selected by the player cursor
+current_tile: .adv 2
+
+ ; the next tile to be updated
+next_update_tile: .adv 2