ld l, a
jp hl
+ ; offsets position in the y direction
+ ; inputs:
+ ; a: y pos in tiles
+ ; returns:
+ ; a: adjusted y
+#macro _act_pos_offset_y
+ ld b, a
+ ld a, [map_offset_y]
+ add a, b
+
+ mul8 a
+ add a, OBJ_OFF_Y
+#endmacro
+
+ ; offsets position in the x direction
+ ; inputs:
+ ; a: x pos in tiles
+ ; returns:
+ ; a: adjusted x
+#macro _act_pos_offset_x
+ ld b, a
+ ld a, [map_offset_x]
+ add a, b
+
+ mul8 a
+ add a, OBJ_OFF_X
+#endmacro
+
; draws the bat actor
; inputs:
; de: actor ptr
; y pos
ld a, [de]
- ld b, a
- ld a, [map_offset_y]
- add a, b
-
- mul8 a
- add a, OBJ_OFF_Y
+ _act_pos_offset_y
ld [hl+], a
; x pos
inc de ; de = act pos x in tiles
ld a, [de]
- ld b, a
- ld a, [map_offset_x]
- add a, b
-
- mul8 a
- add a, OBJ_OFF_X
+ _act_pos_offset_x
ld [hl+], a
; tile
+#define PLAYER_TARGET_CURSOR 0x86
; sets up the player actor
player_init:
; draws player
player_draw:
- ld a, 1
+ ld a, 2
call oamalloc
+ ; draw player actual position
+
; y pos
ld a, 72
add a, b
; flags
xor a, a
+ ld [hl+], a
+
+ ; flicker target position
+ ; for transparaency
+ ld a, [frame_count]
+ and a, 1
+ ret z
+
+
+ ; draw target position
+ ; y pos
+ ld a, [player_target_y]
+ _act_pos_offset_y
+ ld [hl+], a
+
+ ; x pos
+ ld a, [player_target_x]
+ _act_pos_offset_x
+ ld [hl+], a
+
+ ; tile
+ ld a, PLAYER_TARGET_CURSOR
+ ld [hl+], a
+
+ ; flags
+ ld a, OAM_FPRIO
ld [hl], a
ret
+ ; sets player target positon
+ ; inputs:
+ ; $1: inc/dec for y position (e.g. 0, 1, -1)
+ ; $2: inc/dec for x position (e.g. 0, 1, -1)
+#macro _player_set_target
+ ld a, [player+act_pos_y]
+ add a, $1 & 0xFF
+ ld [player_target_y], a
+
+ ld a, [player+act_pos_x]
+ add a, $2 & 0xFF
+ ld [player_target_x], a
+#endmacro
; player attack call
player_attack:
cp a, 0
call z, player_moved
call player_collided
+
+ _player_set_target 0, -1
@not_left:
ld b, DIRRIGHT
cp a, 0
call z, player_moved
call player_collided
+
+ _player_set_target 0, 1
@not_right:
ld b, DIRUP
cp a, 0
call z, player_moved
call player_collided
+
+ _player_set_target -1, 0
@not_up:
ld b, DIRDOWN
cp a, 0
call z, player_moved
call player_collided
+
+ _player_set_target 1, 0
@not_down:
ret
; player view distance radius
player_viewradius: .adv 1
+ ; player target position
+ ; used for attacks and casts
+player_target_y: .adv 1
+player_target_x: .adv 1
+
actors:
player: .adv act_size
map_actors: .adv act_size * ACT_MAX