Browse Source

Use a 16x16 metasprite for player

master
Forest Belton 3 years ago
parent
commit
08f399336d
3 changed files with 121 additions and 8 deletions
  1. BIN
      png/player.png
  2. +99
    -8
      src/player.s
  3. +22
    -0
      src/util.s

BIN
png/player.png View File

Before After
Width: 8  |  Height: 8  |  Size: 135 B Width: 16  |  Height: 16  |  Size: 158 B

+ 99
- 8
src/player.s View File

@ -12,6 +12,8 @@ spriteData:
INCBIN "png/player.2bpp" INCBIN "png/player.2bpp"
DEF SPRITE_IDX EQU 32 DEF SPRITE_IDX EQU 32
DEF SPRITE_WIDTH EQU 2
DEF SPRITE_HEIGHT EQU 2
Player_Init:: Player_Init::
ld a, 8 ld a, 8
@ -20,11 +22,12 @@ Player_Init::
ld bc, _VRAM8000 + SPRITE_IDX * 16 ld bc, _VRAM8000 + SPRITE_IDX * 16
ld hl, spriteData ld hl, spriteData
ld d, 16
ld d, 16 * (SPRITE_WIDTH * SPRITE_HEIGHT)
call memcpy call memcpy
; top left
ld hl, _OAM ld hl, _OAM
ld a, 144-8
ld a, 144-8-8
ld [hli], a ld [hli], a
ld a, 8 ld a, 8
ld [hli], a ld [hli], a
@ -33,9 +36,39 @@ Player_Init::
xor a xor a
ld [hli], a ld [hli], a
; top right
ld a, 144-8-8
ld [hli], a
ld a, 8 + 8
ld [hli], a
ld a, SPRITE_IDX + 1
ld [hli], a
xor a
ld [hli], a
; bottom left
ld a, 144-8
ld [hli], a
ld a, 8
ld [hli], a
ld a, SPRITE_IDX + 2
ld [hli], a
xor a
ld [hli], a
; bottom right
ld a, 144-8
ld [hli], a
ld a, 8 + 8
ld [hli], a
ld a, SPRITE_IDX + 3
ld [hli], a
xor a
ld [hli], a
ld bc, _OAMRAM ld bc, _OAMRAM
ld hl, _OAM ld hl, _OAM
ld d, 4
ld d, 4 * (SPRITE_WIDTH * SPRITE_HEIGHT)
call memcpy call memcpy
ret ret
@ -59,12 +92,41 @@ Player_Update::
; check for right boundary ; check for right boundary
ld hl, _OAM + 1 ld hl, _OAM + 1
ld a, [hl] ld a, [hl]
cp 160
cp 160 - 8
jr nc, .done jr nc, .done
; Update x-position and set x-flip = false
; update top left sprite
inc [hl]
inc hl
ld [hl], SPRITE_IDX
inc hl
res 5, [hl]
; update top right sprite
inc hl
inc hl
inc [hl]
inc hl
ld [hl], SPRITE_IDX + 1
inc hl
res 5, [hl]
; update bottom left sprite
inc hl
inc hl
inc [hl]
inc hl
ld [hl], SPRITE_IDX + 2
inc hl
res 5, [hl]
; update bottom right sprite
inc hl
inc hl
inc [hl] inc [hl]
ld hl, _OAM + 3
inc hl
ld [hl], SPRITE_IDX + 3
inc hl
res 5, [hl] res 5, [hl]
.left: .left:
@ -79,9 +141,38 @@ Player_Update::
cp 9 cp 9
jr c, .done jr c, .done
; Update x-position and set x-flip = true
; update top left sprite
dec [hl]
inc hl
ld [hl], SPRITE_IDX + 1
inc hl
set 5, [hl]
; update top right sprite
inc hl
inc hl
dec [hl]
inc hl
ld [hl], SPRITE_IDX
inc hl
set 5, [hl]
; update bottom left sprite
inc hl
inc hl
dec [hl]
inc hl
ld [hl], SPRITE_IDX + 3
inc hl
set 5, [hl]
; update bottom right sprite
inc hl
inc hl
dec [hl] dec [hl]
ld hl, _OAM + 3
inc hl
ld [hl], SPRITE_IDX + 2
inc hl
set 5, [hl] set 5, [hl]
.done: .done:

+ 22
- 0
src/util.s View File

@ -29,3 +29,25 @@ memset::
dec c dec c
jr nz, memset jr nz, memset
ret ret
; Divides a value by 10 (http://homepage.divms.uiowa.edu/~jones/bcd/decimal.html#division)
; @param b Dividend
; @return a Quotient
div10::
ld a, b
srl a
srl a
add b
srl a
add b
srl a
srl a
srl a
add b
srl a
add b
srl a
srl a
srl a
srl a
ret

Loading…
Cancel
Save