|
|
@ -2,49 +2,8 @@ INCLUDE "oam.inc" |
|
|
|
|
|
|
|
SECTION "Collision", ROMX |
|
|
|
|
|
|
|
; Check whether a 16x16 metasprite collides with the background |
|
|
|
; @param a The index of the first (top left) OAM entry of the sprite |
|
|
|
; @destroy hl |
|
|
|
; note: doesn't work atm (use srl, not sra?) |
|
|
|
sprite16x16_bg_collides:: |
|
|
|
; compute oam entry address (_OAM + a * 4) |
|
|
|
; a is guaranteed not to overflow since l = $00 and a < 40 |
|
|
|
ld hl, _OAM |
|
|
|
sla a |
|
|
|
sla a |
|
|
|
add l |
|
|
|
ld l, a |
|
|
|
|
|
|
|
; top left (x,y) |
|
|
|
ld a, [hl+] |
|
|
|
sra a |
|
|
|
sra a |
|
|
|
sra a |
|
|
|
ld c, [hl] |
|
|
|
sra c |
|
|
|
sra c |
|
|
|
sra c |
|
|
|
call can_move_to |
|
|
|
ret nz |
|
|
|
|
|
|
|
; other three sprites |
|
|
|
REPT 3 |
|
|
|
ld a, [hl+] |
|
|
|
sra a |
|
|
|
sra a |
|
|
|
sra a |
|
|
|
ld c, [hl] |
|
|
|
sra c |
|
|
|
sra c |
|
|
|
sra c |
|
|
|
call can_move_to |
|
|
|
ret nz |
|
|
|
ENDR |
|
|
|
|
|
|
|
ret |
|
|
|
|
|
|
|
player_bg_collides:: |
|
|
|
; c = x/8 |
|
|
|
; c = x % 8 == 0 ? x/8 : x/8 + 1 |
|
|
|
ld hl, PLAYER_X |
|
|
|
ld a, [hl] |
|
|
|
ld c, a |
|
|
@ -58,7 +17,7 @@ player_bg_collides:: |
|
|
|
srl c |
|
|
|
srl c |
|
|
|
|
|
|
|
; b = y/8 |
|
|
|
; b = y % 8 == 0 ? y/8 : y/8 + 1 |
|
|
|
inc hl |
|
|
|
ld a, [hl] |
|
|
|
ld b, a |
|
|
|