.def int CURSOR_TILE = 0x04
-#define CURSOR_MOVE_TIMER TILE_SIZE
-#define CURSOR_MOVE_SPEED 8
-
- ; init the player
-cursor_player_init:
- ld de, st_cursor
- ld hl, actor_player
- ld bc, st_size
- call memcpy
-
- ret
-
- ; update the player
- ; players do not behave like regular actors
- ; and are not allocate to the regular
- ; actor table
- ; inputs:
- ; hl: pointer to player memory
-cursor_player_update:
- call cursor_handle_inputs
- push bc
- call cursor_player_draw_cursor
- pop bc
- ret
-
- ; updates the cursor
- ; sprites
-cursor_player_draw_cursor:
-@draw_cursor:
- ; draw cursor
- call load_scroll
-
- ; 8x8 small cursor
- call load_unit_obj
-
- ld a, [cursor_y]
- add a, OBJ_OFF_Y
- sub a, b
- ld [hl+], a
-
- ld a, [cursor_x]
- add a, OBJ_OFF_X
- sub a, c
- ld [hl+], a
-
- ld a, CURSOR_TILE
- ld [hl+], a
-
- xor a, a
- ld [hl+], a
-
- ldnull bc
- ret
-
-cursor_handle_inputs:
- input_held BTNA
- jr z, @not_a REL
- ; TODO: remove demo actor load
- ; and load real units
- call map_load_demo_actors
- call game_init
-@not_a:
-
- ; movement keys with cooldown
-
- input_held BTNDOWN
- jr z, @notdown REL
-
- call cursor_try_abort_move_down
- jp z, @done
-
- cursor_move_direction cursor_move_y, cursor_move_x, 1
-
- ; adjust scroll
- cursor_adjust_scroll add, scroll_move_y
-
- call cursor_move
- ld bc, st_cursor_delay
- ret
-@notdown:
-
- input_held BTNUP
- jr z, @notup REL
-
- call cursor_try_abort_move_up
- jp z, @done
-
- cursor_move_direction cursor_move_y, cursor_move_x, NEGATE
-
- ; adjust scroll
- cursor_adjust_scroll sub, scroll_move_y
-
- call cursor_move
- ld bc, st_cursor_delay
- ret
-@notup:
-
- input_held BTNLEFT
- jr z, @notleft REL
-
- call cursor_try_abort_move_left
- jr z, @done REL
-
- cursor_move_direction cursor_move_x, cursor_move_y, NEGATE
-
- ; adjust scroll
- cursor_adjust_scroll sub, scroll_move_x
-
- call cursor_move
- ld bc, st_cursor_delay
- ret
-@notleft:
-
- input_held BTNRIGHT
- jr z, @notright REL
-
- call cursor_try_abort_move_right
- jr z, @done REL
-
- cursor_move_direction cursor_move_x, cursor_move_y, 1
-
- ; adjust scroll
- cursor_adjust_scroll add, scroll_move_x
-
- call cursor_move
- ld bc, st_cursor_delay
- ret
-@notright:
-
- input_just BTNSELECT
- jr z, @not_select REL
- ; select goes to build menu
-
- ldnull bc
- ret
-@not_select:
-@done:
- ldnull bc
- ret
-
-cursor_move:
- ld a, [cursor_y]
- ld b, a
-
- ld a, [cursor_move_y]
- add a, b
- ld [cursor_y], a
-
- ld a, [cursor_x]
- ld b, a
-
- ld a, [cursor_move_x]
- add a, b
- ld [cursor_x], a
-
- call scroll_update
- ret
-
-cursor_try_abort_move_left:
- ld b, CURSOR_MIN_X
- ld hl, cursor_x
- jp try_abort_move_at
-
-cursor_try_abort_move_right:
- ld b, CURSOR_MAX_X
- ld hl, cursor_x
- jp try_abort_move_at
-
-cursor_try_abort_move_up:
- ld b, CURSOR_MIN_Y
- ld hl, cursor_y
- jp try_abort_move_at
-
-cursor_try_abort_move_down:
- ld b, CURSOR_MAX_Y
- ld hl, cursor_y
- jp try_abort_move_at
-
- ; aborts a move direciton
- ; inputs:
- ; b: compare variable (e.g. min or max value)
- ; hl: position ptr
- ; returns: z == 0 if move was aborted
-try_abort_move_at:
- ; do not abort if position is wrong
- ld a, [hl]
- cp a, b
- ret
-
- ; gets the current cell
- ; the cursor is pointing at
- ; at cursor_y/x
- ; returns:
- ; hl: cell ptr
-cursor_get_cell:
- cursor_get_at_generic state_cells, MAP_W * c_size, c_size
-
- ret
-
- ; gets the current tile in SCRN0
- ; based on cursor's location
- ; cursor_y/x
- ; retunrs:
- ; hl: tile position
-cursor_get_tile:
- cursor_get_at_generic SCRN0, MAP_W, 1
-
- ret
-
-
st_null:
st_def 0xFF, st_null_fn, st_null
-st_cursor:
- st_def 0x00, cursor_player_update, st_cursor
-st_cursor_draw:
- st_def 0x00, cursor_player_draw_cursor, st_cursor
-st_cursor_delay:
- st_def CURSOR_MOVE_TIMER, st_null_fn, st_cursor
-
st_update_game:
st_def 0x00, update_game, st_update_game
-st_update_unit_placement:
- st_def 0x00, update_unit_placement, st_update_unit_placement
st_update_pause:
st_def 0x00, update_pause, st_update_pause
st_update_game_over:
st_def 0x00, unit_idle, st_unit_idle
st_unit_delay_to_active:
- st_def CURSOR_MOVE_TIMER, unit_delay_to_active, st_unit_switch_to_active
+ st_def 8, unit_delay_to_active, st_unit_switch_to_active
st_unit_switch_to_active:
st_def 0, unit_switch_to_active, st_unit_switch_to_active
unit_next_best_act_ptr: .adv 2
unit_next_timer: .adv 1
- ; actors
- ; actors are state machines
- ; they get updated once a frame
- ; actor player is a simple cursor
- ; that has deploymnet control
-actor_player: .adv act_size
-
; offset into bg_update_queue
bg_update_index: .adv 2
bg_update_queue: .adv bge_size * BGE_MAX
; last d16 result
d16: .adv 1
-cursor:
-cursor_y: .adv 1
-cursor_x: .adv 1
-cursor_move_y: .adv 1
-cursor_move_x: .adv 1
-
; +/-1 for each time the cursor moves
; allows us to move scroll when needed
scroll_move_y: .adv 1