unit: added basic random move cpu state
authorLukas Krickl <lukas@krickl.dev>
Sun, 8 Jun 2025 15:09:08 +0000 (17:09 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 8 Jun 2025 15:09:08 +0000 (17:09 +0200)
src/unit.s

index fd956c2728bafcd0c5a2f9d15190ca13aa6fd7a2..804d3b82b43e0ff36cc25a24d725476713cfc0ca 100644 (file)
@@ -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