.PHONY: sprites
sprites:
- ./tools/tmx2map.py assets/sprites/sword.tmx > sprites/sword.inc
+ ./tools/tmx2map.py assets/sprites/sword.tmx 1 > sprites/sword.inc
; 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
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
; 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
; 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
; combat data
combat: .adv combat_size
-
- ; sprite overlay temporary registers
-so_tmp_y: .adv 1
-so_tmp_x: .adv 1
; 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