|
|
@ -1,5 +1,6 @@ |
|
|
|
INCLUDE "hardware.inc" |
|
|
|
INCLUDE "input.inc" |
|
|
|
INCLUDE "oam.inc" |
|
|
|
|
|
|
|
Section "Player Data", WRAM0 |
|
|
|
|
|
|
@ -11,7 +12,8 @@ Section "Player Code", ROM0 |
|
|
|
spriteData: |
|
|
|
INCBIN "png/sprite/player.2bpp" |
|
|
|
|
|
|
|
DEF SPRITE_IDX EQU 32 |
|
|
|
DEF SPRITE_OAM_IDX EQU 0 |
|
|
|
DEF SPRITE_IDX EQU 32 ; tile index, rename later |
|
|
|
DEF SPRITE_WIDTH EQU 2 |
|
|
|
DEF SPRITE_HEIGHT EQU 2 |
|
|
|
|
|
|
@ -25,46 +27,10 @@ Player_Init:: |
|
|
|
ld d, 16 * (SPRITE_WIDTH * SPRITE_HEIGHT) |
|
|
|
call memcpy |
|
|
|
|
|
|
|
; top left |
|
|
|
ld hl, _OAM |
|
|
|
ld a, 144-8-8 |
|
|
|
ld [hli], a |
|
|
|
ld a, 8 |
|
|
|
ld [hli], a |
|
|
|
ld a, SPRITE_IDX |
|
|
|
ld [hli], a |
|
|
|
xor 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 |
|
|
|
OAM_set SPRITE_OAM_IDX + 0, 8, 144-8-8, SPRITE_IDX, 0 |
|
|
|
OAM_set SPRITE_OAM_IDX + 1, 16, 144-8-8, SPRITE_IDX + 1, 0 |
|
|
|
OAM_set SPRITE_OAM_IDX + 2, 8, 144-8, SPRITE_IDX + 2, 0 |
|
|
|
OAM_set SPRITE_OAM_IDX + 3, 16, 144-8, SPRITE_IDX + 3, 0 |
|
|
|
|
|
|
|
ld bc, _OAMRAM |
|
|
|
ld hl, _OAM |
|
|
@ -79,7 +45,7 @@ Player_Update:: |
|
|
|
ld a, [hl] |
|
|
|
and %1 |
|
|
|
cp %1 |
|
|
|
jr nz, .done |
|
|
|
ret nz |
|
|
|
|
|
|
|
ld hl, keys |
|
|
|
ld b, [hl] |
|
|
@ -90,17 +56,40 @@ Player_Update:: |
|
|
|
jr z, .left |
|
|
|
|
|
|
|
; check for right boundary |
|
|
|
ld hl, _OAM + 1 |
|
|
|
ld_OAM_x hl, SPRITE_OAM_IDX + 1 |
|
|
|
ld a, [hl] |
|
|
|
cp 160 - 8 |
|
|
|
jr nc, .done |
|
|
|
cp SCRN_X |
|
|
|
jr nc, .left |
|
|
|
|
|
|
|
; TODO: check collision |
|
|
|
call move_right |
|
|
|
|
|
|
|
.left: |
|
|
|
; check for left button |
|
|
|
ld a, b |
|
|
|
and BTN_LEFT |
|
|
|
ret z |
|
|
|
|
|
|
|
; check for left boundary |
|
|
|
ld_OAM_x hl, SPRITE_OAM_IDX |
|
|
|
ld a, [hl] |
|
|
|
cp 9 |
|
|
|
ret c |
|
|
|
|
|
|
|
; TODO: check collision |
|
|
|
call move_left |
|
|
|
|
|
|
|
ret |
|
|
|
|
|
|
|
move_right: |
|
|
|
ld_OAM_x hl, SPRITE_OAM_IDX |
|
|
|
|
|
|
|
; update top left sprite |
|
|
|
inc [hl] |
|
|
|
inc hl |
|
|
|
ld [hl], SPRITE_IDX |
|
|
|
inc hl |
|
|
|
res 5, [hl] |
|
|
|
res OAMB_XFLIP, [hl] |
|
|
|
|
|
|
|
; update top right sprite |
|
|
|
inc hl |
|
|
@ -109,7 +98,7 @@ Player_Update:: |
|
|
|
inc hl |
|
|
|
ld [hl], SPRITE_IDX + 1 |
|
|
|
inc hl |
|
|
|
res 5, [hl] |
|
|
|
res OAMB_XFLIP, [hl] |
|
|
|
|
|
|
|
; update bottom left sprite |
|
|
|
inc hl |
|
|
@ -118,7 +107,7 @@ Player_Update:: |
|
|
|
inc hl |
|
|
|
ld [hl], SPRITE_IDX + 2 |
|
|
|
inc hl |
|
|
|
res 5, [hl] |
|
|
|
res OAMB_XFLIP, [hl] |
|
|
|
|
|
|
|
; update bottom right sprite |
|
|
|
inc hl |
|
|
@ -127,53 +116,45 @@ Player_Update:: |
|
|
|
inc hl |
|
|
|
ld [hl], SPRITE_IDX + 3 |
|
|
|
inc hl |
|
|
|
res 5, [hl] |
|
|
|
res OAMB_XFLIP, [hl] |
|
|
|
|
|
|
|
.left: |
|
|
|
; check for left button |
|
|
|
ld a, b |
|
|
|
and BTN_LEFT |
|
|
|
jr z, .done |
|
|
|
ret |
|
|
|
|
|
|
|
; check for left boundary |
|
|
|
ld hl, _OAM + 1 |
|
|
|
ld a, [hl] |
|
|
|
cp 9 |
|
|
|
jr c, .done |
|
|
|
move_left: |
|
|
|
ld_OAM_x hl, SPRITE_OAM_IDX |
|
|
|
|
|
|
|
; update top left sprite |
|
|
|
; top left |
|
|
|
dec [hl] |
|
|
|
inc hl |
|
|
|
ld [hl], SPRITE_IDX + 1 |
|
|
|
inc hl |
|
|
|
set 5, [hl] |
|
|
|
set OAMB_XFLIP, [hl] |
|
|
|
|
|
|
|
; update top right sprite |
|
|
|
; top right |
|
|
|
inc hl |
|
|
|
inc hl |
|
|
|
dec [hl] |
|
|
|
inc hl |
|
|
|
ld [hl], SPRITE_IDX |
|
|
|
inc hl |
|
|
|
set 5, [hl] |
|
|
|
set OAMB_XFLIP, [hl] |
|
|
|
|
|
|
|
; update bottom left sprite |
|
|
|
; bottom left |
|
|
|
inc hl |
|
|
|
inc hl |
|
|
|
dec [hl] |
|
|
|
inc hl |
|
|
|
ld [hl], SPRITE_IDX + 3 |
|
|
|
inc hl |
|
|
|
set 5, [hl] |
|
|
|
set OAMB_XFLIP, [hl] |
|
|
|
|
|
|
|
; update bottom right sprite |
|
|
|
; bottom right |
|
|
|
inc hl |
|
|
|
inc hl |
|
|
|
dec [hl] |
|
|
|
inc hl |
|
|
|
ld [hl], SPRITE_IDX + 2 |
|
|
|
inc hl |
|
|
|
set 5, [hl] |
|
|
|
set OAMB_XFLIP, [hl] |
|
|
|
|
|
|
|
.done: |
|
|
|
ret |