From e83537e3d353f80233f1790f2eda772a0893abce Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Tue, 6 Jan 2026 05:53:46 +0100 Subject: [PATCH] player: Added overlay drawing for player weapon --- makefile | 2 +- sprites/sword.inc | 2 +- src/player.s | 38 -------------------- src/sprites.s | 88 ++++++++++++++++++++++++++++++++++++++++++++-- src/wram.s | 4 --- tiles/bank8800.inc | 8 ++--- 6 files changed, 91 insertions(+), 51 deletions(-) diff --git a/makefile b/makefile index 9c33a7d..91d1a59 100644 --- a/makefile +++ b/makefile @@ -54,4 +54,4 @@ levels: .PHONY: sprites sprites: - ./tools/tmx2map.py assets/sprites/sword.tmx > sprites/sword.inc + ./tools/tmx2map.py assets/sprites/sword.tmx 1 > sprites/sword.inc diff --git a/sprites/sword.inc b/sprites/sword.inc index c3c8394..d397140 100644 --- a/sprites/sword.inc +++ b/sprites/sword.inc @@ -1,4 +1,4 @@ ; this map was generated by tmx2map.py -.db -0x42, -0x51, -0x51, -0x51, -0x33, -0x42, -0x51, -0x31, -0x51, -0x33, -0x32, -0x51, -0x51, -0x22, -0x51, -0x21 +.db 0x1e, 0x0, 0x0, 0x0, 0x2d, 0x1e, 0xf, 0x2f, 0x0, 0x2d, 0x2e, 0x0, 0x0, 0x3e, 0x0, 0x3f diff --git a/src/player.s b/src/player.s index 4eddb94..85b02fb 100644 --- a/src/player.s +++ b/src/player.s @@ -82,49 +82,11 @@ player_update: ret -#define PLAYER_WEAPON_Y WINDOW_Y-16 -#define PLAYER_WEAPON_X 120 - - ; draws part of player weapon - ; inputs: - ; $1: y offset - ; $2: x offset - ; $3: tile id - ; hl: ptr to oam - ; returns: - ; hl: next oam -#macro player_draw_weapon_part - ld a, PLAYER_WEAPON_Y + $1 - ld [hl+], a - ld a, PLAYER_WEAPON_X + $2 - ld [hl+], a - ld a, $3 - ld [hl+], a - xor a, a - ld [hl+], a -#endmacro ; draws weapon spirte player_draw_weapon: ld de, so_sword call sprite_overlay_draw - - ; TODO: for now we just draw a placeholder - ld a, 8 - call oamalloc - - player_draw_weapon_part 0, 0, PLAYER_PLACEHOLDER_WEAPON_0 - player_draw_weapon_part 8, 0, PLAYER_PLACEHOLDER_WEAPON_1 - - player_draw_weapon_part 8, 8, PLAYER_PLACEHOLDER_WEAPON_0 - player_draw_weapon_part 16, 8, PLAYER_PLACEHOLDER_WEAPON_1 - - player_draw_weapon_part 16, 16, PLAYER_PLACEHOLDER_WEAPON_2 - player_draw_weapon_part 12, 24, PLAYER_PLACEHOLDER_WEAPON_3 - - player_draw_weapon_part 24, 12, PLAYER_PLACEHOLDER_WEAPON_4 - player_draw_weapon_part 24, 24, PLAYER_PLACEHOLDER_WEAPON_5 - ret ; player attack call diff --git a/src/sprites.s b/src/sprites.s index 4ad97fa..a46e762 100644 --- a/src/sprites.s +++ b/src/sprites.s @@ -1,10 +1,70 @@ ; this file contains rendering code for sprite overlays ; this can be e.g. weapons displayed in first person view +#define PLAYER_WEAPON_Y WINDOW_Y-16 +#define PLAYER_WEAPON_X 120 + so_sword: -osdef 6, 20, 20 +osdef 9, PLAYER_WEAPON_Y, PLAYER_WEAPON_X #include "sword.inc" + ; draws the next object + ; in the so list + ; inputs: + ; hl: oam + ; de: oam data + ; bc: current y/x position + ; returns: + ; hl: next obj + ; de: next oam data + ; bc: x position + 8 +#macro _so_draw_next +.beginscope + ; do not draw if the tile id is 0 + ld a, [de] + cp a, 0 + jr z, @skip REL + + ; y/x + ld a, b + ld [hl+], a + ld a, c + ld [hl+], a + + ; tile + ld a, [de] + ; static offset to get to oam tilese + add a, 0x80 + ld [hl+], a + + ; flags + xor a, a + ld [hl+], a + +@skip: + inc de + ; x pos + 8 + ld a, c + add a, 8 + ld c, a + +.endscope +#endmacro + + ; advances the y position by 8 pixels + ; subtracts OS_WIDT*8 from x + ; inputs: + ; bc: current y/x position +#macro _so_next_row + ld a, b + add a, 8 + ld b, a + + ld a, c + sub a, OS_WIDTH*8 + ld c, a +#endmacro + ; draws a sprite overlay ; inputs: ; de: sprite overlay ptr @@ -19,13 +79,35 @@ sprite_overlay_draw: ; load y/x origin ld a, [de] - ld [so_tmp_y], a + ld b, a inc de ld a, [de] - ld [so_tmp_x], a + ld c, a inc de ; de = oam data + _so_draw_next + _so_draw_next + _so_draw_next + _so_draw_next + _so_next_row + + _so_draw_next + _so_draw_next + _so_draw_next + _so_draw_next + _so_next_row + + _so_draw_next + _so_draw_next + _so_draw_next + _so_draw_next + _so_next_row + _so_draw_next + _so_draw_next + _so_draw_next + _so_draw_next + _so_next_row ret diff --git a/src/wram.s b/src/wram.s index 435e54f..36131b2 100644 --- a/src/wram.s +++ b/src/wram.s @@ -136,7 +136,3 @@ dir_tfs_end: ; combat data combat: .adv combat_size - - ; sprite overlay temporary registers -so_tmp_y: .adv 1 -so_tmp_x: .adv 1 diff --git a/tiles/bank8800.inc b/tiles/bank8800.inc index e26554a..8a298cd 100644 --- a/tiles/bank8800.inc +++ b/tiles/bank8800.inc @@ -1,9 +1,9 @@ ; this tileset was generated by png2chr.py ; tile 0 -.chr 32130000 -.chr 13330000 -.chr 23000000 -.chr 33000000 +.chr 00000000 +.chr 00000000 +.chr 00000000 +.chr 00000000 .chr 00000000 .chr 00000000 .chr 00000000 -- 2.30.2