-; player gets 3 sprite slots in a row
-.def int PLAYER_SPRITE1 = shadow_oam + 0
-
.def int CURSOR_TILE = 0x04
#define CURSOR_MOVE_TIMER TILE_SIZE
cursor_player_draw_cursor:
@draw_cursor:
; draw cursor
- ld a, [scroll_y]
- ld b, a ; b = scroll_y
- ld a, [scroll_x]
- ld c, a ; c = scroll_x
+ call load_scroll
; 8x8 small cursor
- ld hl, PLAYER_SPRITE1
+ call load_unit_obj
ld a, [cursor_y]
add a, OBJ_OFF_Y
; hl = function value
jp hl
+ ; loads scroll into bc
+ ; returns:
+ ; b: scroll y
+ ; c: scroll x
+load_scroll:
+ ld a, [scroll_y]
+ ld b, a ; b = scroll_y
+ ld a, [scroll_x]
+ ld c, a ; c = scroll_x
+ ret
+
+ ; loads unit sprite into hl
+ ; increments unit sprite
+ ; returns;
+ ; hl: current unit sprite
+load_unit_obj:
+ ld a, [unit_sprite]
+
+
+ ld d, 0
+ ld e, a
+ ld hl, shadow_oam
+
+ add hl, de ; hl = next oam
+
+ ; next object
+ add a, oamsize
+ ld [unit_sprite], a
+
+ ret
; inputs:
; hl: unit table (p0/p1)
units_update:
+
; loop counter
ld a, UNITS_MAX
ret
+unit_demo_1_init:
+ ldnull bc
+ ret
+
unit_demo_1_update:
+ ; TODO: call with correct values
+ ldnull hl
+ ld a, 1 ; hard-coded action remaining
+ call unit_handle_inputs
+
+unit_demo_1_draw:
+ ld b, 0x84 ; tile
+ ld c, 0x00 ; flags
+ call unit_generic_draw
+ ldnull bc
+ ret
+
+ ; draws any unit
+ ; inputs:
+ ; b: tile
+ ; c: flags
+unit_generic_draw:
+ push bc
+
+ ld hl, act_pos_y
+ add hl, de ; hl = act_pos_y
+ push hl
+
+ call load_scroll
+ call load_unit_obj
+
+ pop de ; de = act_pos_y
+
+ ; set y pos
+ ld a, [de]
+ mul8 a
+ add a, OBJ_OFF_Y
+ add a, b
+ ld [hl+], a
+
+ ; set x pos
+ inc de
+ ld a, [de]
+ mul8 a
+ add a, OBJ_OFF_X
+ add a, b
+ ld [hl+], a
+
+ pop bc ; bc = inputs again
+
+ ; set tile
+ ld a, b
+ ld [hl+], a
+
+
+ ; set flags
+ ld a, c
+ ld [hl+], a
+
+ ldnull bc
+ ret
+
+ ; generic unit input handler
+ ; inputs:
+ ; hl: action table
+ ; a: remaining moves
+unit_handle_inputs:
ldnull bc
ret
unit_demo_1:
- st_def 0x00, unit_demo_1_update, unit_demo_1
+ st_def 0x00, unit_demo_1_init, st_unit_demo_1_update
act_def ACT_T_DEMO_1, 0, 1, 1, 1, 1, 1, 2, 2, 0
+
+st_unit_demo_1_update:
+ st_def 0x00, unit_demo_1_update, st_unit_demo_1_update