From: Lukas Krickl Date: Sun, 8 Jun 2025 15:09:08 +0000 (+0200) Subject: unit: added basic random move cpu state X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=aa5887ad237446a7180cda4b085968afeaf7884b;p=gbrg%2F.git unit: added basic random move cpu state --- diff --git a/src/unit.s b/src/unit.s index fd956c2..804d3b8 100644 --- a/src/unit.s +++ b/src/unit.s @@ -88,7 +88,49 @@ unit_demo_1_update: pop de ret - + + ; cpu controllerd unit update +unit_demo_1_cpu_update: + push de + ld hl, act_oam_flags + add hl, de + ld a, [hl] + or a, OAM_DMG_PAL + ld [hl], a + pop de + + push de + call unit_handle_cpu_inputs + pop de + + push de + call unit_scroll_center + pop de + ret + +unit_handle_cpu_inputs: + ; pick where to go + call roll_d16 + and a, 3 ; 0-3 + ; 0 == left + cp a, 0 + call z, unit_try_move_left + + ; 1 == right + cp a, 1 + call z, unit_try_move_right + + ; 2 == up + cp a, 2 + call z, unit_try_move_up + + ; 3 == down + cp a, 3 + call z, unit_try_move_down + + ld bc, st_unit_delay_to_active + ret + ; inputs ; de: actor @@ -785,13 +827,16 @@ unit_demo_3: act_inventory_empty act_equipment_empty act_effects_empty - act_st_def NULL, NULL, st_unit_demo_1_update, st_unit_idle + act_st_def NULL, NULL, st_unit_demo_1_cpu_update, st_unit_idle act_def_draw unit_draw, 0x84, 0 act_rt_def st_unit_demo_1_update: st_def 0x00, unit_demo_1_update, st_unit_demo_1_update +st_unit_demo_1_cpu_update: + st_def 0x00, unit_demo_1_cpu_update, st_unit_demo_1_cpu_update + st_unit_idle: st_def 0x00, unit_idle, st_unit_idle