From: Lukas Krickl Date: Sun, 11 May 2025 15:31:43 +0000 (+0200) Subject: unit: Added basic drawing rotuine for demo_1 unit X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=3f4b790170f795d827cb49af1fe2f0a75b5dd311;p=gbrg%2F.git unit: Added basic drawing rotuine for demo_1 unit --- diff --git a/src/player.s b/src/player.s index 8a13571..b7e87a7 100644 --- a/src/player.s +++ b/src/player.s @@ -1,6 +1,3 @@ -; 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 @@ -33,13 +30,10 @@ cursor_player_update: 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 diff --git a/src/sys.s b/src/sys.s index 6030700..500aac4 100644 --- a/src/sys.s +++ b/src/sys.s @@ -49,3 +49,33 @@ call_tbl: ; 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 diff --git a/src/unit.s b/src/unit.s index fa45815..365f572 100644 --- a/src/unit.s +++ b/src/unit.s @@ -4,6 +4,7 @@ ; inputs: ; hl: unit table (p0/p1) units_update: + ; loop counter ld a, UNITS_MAX @@ -40,10 +41,79 @@ units_update: 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 diff --git a/src/update.s b/src/update.s index 6e73f56..1edf380 100644 --- a/src/update.s +++ b/src/update.s @@ -36,6 +36,10 @@ update: ld a, [frame_count] inc a ld [frame_count], a + + ; reset objects + xor a, a + ld [unit_sprite], a ld de, game_mode jp st_update diff --git a/src/wram.s b/src/wram.s index fb71539..1fbe1b9 100644 --- a/src/wram.s +++ b/src/wram.s @@ -6,6 +6,9 @@ shadow_oam: .adv OBJSMAX * oamsize frame_ready: .adv 1 frame_count: .adv 1 + ; current sprite +unit_sprite: .adv 1 + ; current frame's inputs curr_inputs: .adv 1 ; previous frame's inputs