From 8aa3555e8c8f0545587b3f4579edf164a3952810 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 19 Jan 2026 08:12:27 +0100 Subject: [PATCH] player: Added target positon drawing --- assets | 2 +- src/actor.s | 42 ++++++++++++++++++++++++++----------- src/main.s | 2 +- src/player.s | 52 +++++++++++++++++++++++++++++++++++++++++++++- src/wram.s | 5 +++++ tiles/bank8800.inc | 12 +++++------ 6 files changed, 94 insertions(+), 21 deletions(-) diff --git a/assets b/assets index aa6c341..c85a7a2 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit aa6c3410c430d60d31286558ce3c54bcd49deb0b +Subproject commit c85a7a2d1bd18cb702f347819b838c8ad9d9fb97 diff --git a/src/actor.s b/src/actor.s index fe553ee..4479668 100644 --- a/src/actor.s +++ b/src/actor.s @@ -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 diff --git a/src/main.s b/src/main.s index 2f9d183..189c048 100644 --- a/src/main.s +++ b/src/main.s @@ -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" diff --git a/src/player.s b/src/player.s index 1202ccd..5310d11 100644 --- a/src/player.s +++ b/src/player.s @@ -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 diff --git a/src/wram.s b/src/wram.s index 465408e..7f99904 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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 diff --git a/tiles/bank8800.inc b/tiles/bank8800.inc index 2f86dd4..536e5ab 100644 --- a/tiles/bank8800.inc +++ b/tiles/bank8800.inc @@ -51,14 +51,14 @@ .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 -- 2.30.2