player: Added overlay drawing for player weapon
authorLukas Krickl <lukas@krickl.dev>
Tue, 6 Jan 2026 04:53:46 +0000 (05:53 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 6 Jan 2026 04:53:46 +0000 (05:53 +0100)
makefile
sprites/sword.inc
src/player.s
src/sprites.s
src/wram.s
tiles/bank8800.inc

index 9c33a7de0eafbe28cf35e6c994081efd316ff218..91d1a59303f2b18db12a7eb8b2d99c8428fa7582 100644 (file)
--- 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 > sprites/sword.inc
index c3c8394abea6dabeec738b3373e7fdd4e407ce20..d3971402e60c89995872b78faf4ff3cb39a857f1 100644 (file)
@@ -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
 
index 4eddb94261bee1b2f35cafb3581e2a53943aec8c..85b02fb973b33618340bf8eebfc3f0f1ffc0a40f 100644 (file)
@@ -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
index 4ad97faa8ada13a577250400aeb93443a34bd972..a46e762cd73d89d710f027b091e37eac5d499fd8 100644 (file)
@@ -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
index 435e54f2056ddf66bb2291192463d4d16d5dafca..36131b2b17d1dedf01a11524a2cb2afb959cbb1d 100644 (file)
@@ -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
index e26554a133f81543b97a0f542eda259110642ee8..8a298cd885aff98c30fccdc1608c6b4a827f3f5f 100644 (file)
@@ -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