player: Added target positon drawing
authorLukas Krickl <lukas@krickl.dev>
Mon, 19 Jan 2026 07:12:27 +0000 (08:12 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 19 Jan 2026 07:12:27 +0000 (08:12 +0100)
assets
src/actor.s
src/main.s
src/player.s
src/wram.s
tiles/bank8800.inc

diff --git a/assets b/assets
index aa6c3410c430d60d31286558ce3c54bcd49deb0b..c85a7a2d1bd18cb702f347819b838c8ad9d9fb97 160000 (submodule)
--- a/assets
+++ b/assets
@@ -1 +1 @@
-Subproject commit aa6c3410c430d60d31286558ce3c54bcd49deb0b
+Subproject commit c85a7a2d1bd18cb702f347819b838c8ad9d9fb97
index fe553ee81a0541b4edd5d39f889faa779a435bf1..447966830cb4276fa860f574b48b04ee52e5866f 100644 (file)
@@ -169,6 +169,34 @@ act_update:
        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
@@ -183,24 +211,14 @@ act_d_bat:
 
        ; 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
index 2f9d183bf9843ba788c638635622295d95afd20e..189c04869f28b7057d5b5c0a0f894d53bb2fe4e8 100644 (file)
@@ -57,6 +57,7 @@ main:
 #include "sys.s"
 #include "input.s"
 #include "map.s"
+#include "actor.s"
 #include "player.s"
 #include "enemy.s"
 #include "update.s"
@@ -64,7 +65,6 @@ main:
 #include "audio.s"
 #include "math.s"
 #include "game.s"
-#include "actor.s"
 #include "mainmenu.s"
 #include "tiles.s"
 #include "levels.s"
index 1202ccdf9ae578ea6892431ee5646988513d4152..5310d11dd49df6a109315c8fbf5b7683fb1a075c 100644 (file)
@@ -1,4 +1,5 @@
 
+#define PLAYER_TARGET_CURSOR 0x86
 
        ; sets up the player actor
 player_init:
@@ -72,9 +73,11 @@ player_update:
 
        ; draws player
 player_draw:
-       ld a, 1
+       ld a, 2
        call oamalloc 
        
+       ; draw player actual position
+
        ; y pos
        ld a, 72
        add a, b
@@ -90,10 +93,49 @@ player_draw:
 
        ; 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:
@@ -127,6 +169,8 @@ player_handle_move:
                cp a, 0
                call z, player_moved
                call player_collided
+
+               _player_set_target 0, -1
 @not_left:
 
        ld b, DIRRIGHT
@@ -145,6 +189,8 @@ player_handle_move:
                cp a, 0
                call z, player_moved
                call player_collided
+
+               _player_set_target 0, 1
 @not_right:
 
        ld b, DIRUP
@@ -163,6 +209,8 @@ player_handle_move:
                cp a, 0
                call z, player_moved
                call player_collided
+
+               _player_set_target -1, 0
 @not_up:
 
        ld b, DIRDOWN
@@ -181,6 +229,8 @@ player_handle_move:
                cp a, 0
                call z, player_moved
                call player_collided
+
+               _player_set_target 1, 0
 @not_down:
        ret
        
index 465408eafe4ecaab46be162619d601f343080d4f..7f9990485c28726b5eca0c36cad7ccf01ef3dc1e 100644 (file)
@@ -93,6 +93,11 @@ player_eq: .adv eq_size
        ; 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
index 2f86dd4392b1ce32115b3f9d866bbb31507d6376..536e5ab3544c91132af0d1cbd644d45edd4e030a 100644 (file)
 .chr 00333030
 .chr 03303300
 ; tile 3
+.chr 33300333
+.chr 30000003
+.chr 30000003
 .chr 00000000
 .chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 30000003
+.chr 30000003
+.chr 33300333
 .chr 00000000
 .chr 00000000
 .chr 00000000