|
@ -2,8 +2,12 @@ INCLUDE "oam.inc" |
|
|
|
|
|
|
|
|
SECTION "Collision", ROM0 |
|
|
SECTION "Collision", ROM0 |
|
|
|
|
|
|
|
|
|
|
|
DEF COLLF_WALK EQU (1 << 0) |
|
|
|
|
|
DEF COLLF_LADDER EQU (1 << 1) |
|
|
|
|
|
DEF COLLF_PORTAL EQU (1 << 2) |
|
|
|
|
|
|
|
|
; Determines if player has hit the background |
|
|
; Determines if player has hit the background |
|
|
; @return NZ = true, Z = false |
|
|
|
|
|
|
|
|
; @return NZ = false, Z = true |
|
|
player_bg_collides:: |
|
|
player_bg_collides:: |
|
|
; C = MAP X = PLAYER X / 8 + CAMERA X |
|
|
; C = MAP X = PLAYER X / 8 + CAMERA X |
|
|
ld a, [PLAYER_X] |
|
|
ld a, [PLAYER_X] |
|
@ -15,16 +19,16 @@ player_bg_collides:: |
|
|
ld c, a |
|
|
ld c, a |
|
|
|
|
|
|
|
|
; C < 0 |
|
|
; C < 0 |
|
|
bit 7, c |
|
|
|
|
|
ret nz |
|
|
|
|
|
|
|
|
ld a, c |
|
|
|
|
|
cpl |
|
|
|
|
|
bit 7, a |
|
|
|
|
|
ret z |
|
|
|
|
|
|
|
|
; C >= MAP WIDTH |
|
|
; C >= MAP WIDTH |
|
|
ld a, [CURRENT_MAP_WIDTH] |
|
|
ld a, [CURRENT_MAP_WIDTH] |
|
|
cp c |
|
|
cp c |
|
|
jr nz, .load_y |
|
|
jr nz, .load_y |
|
|
|
|
|
|
|
|
; Set NZ |
|
|
|
|
|
or $ff |
|
|
|
|
|
ret |
|
|
ret |
|
|
|
|
|
|
|
|
.load_y: |
|
|
.load_y: |
|
@ -38,8 +42,10 @@ player_bg_collides:: |
|
|
ld b, a |
|
|
ld b, a |
|
|
|
|
|
|
|
|
; B < 0 |
|
|
; B < 0 |
|
|
bit 7, b |
|
|
|
|
|
ret nz |
|
|
|
|
|
|
|
|
ld a, b |
|
|
|
|
|
cpl |
|
|
|
|
|
bit 7, a |
|
|
|
|
|
ret z |
|
|
|
|
|
|
|
|
; B >= MAP HEIGHT |
|
|
; B >= MAP HEIGHT |
|
|
ld a, [CURRENT_MAP_HEIGHT] |
|
|
ld a, [CURRENT_MAP_HEIGHT] |
|
@ -53,18 +59,18 @@ player_bg_collides:: |
|
|
.check_tiles: |
|
|
.check_tiles: |
|
|
; top left |
|
|
; top left |
|
|
call can_move_to |
|
|
call can_move_to |
|
|
ret nz |
|
|
|
|
|
|
|
|
ret z |
|
|
|
|
|
|
|
|
; top right |
|
|
; top right |
|
|
inc c |
|
|
inc c |
|
|
call can_move_to |
|
|
call can_move_to |
|
|
ret nz |
|
|
|
|
|
|
|
|
ret z |
|
|
|
|
|
|
|
|
; bottom left |
|
|
; bottom left |
|
|
dec c |
|
|
dec c |
|
|
inc b |
|
|
inc b |
|
|
call can_move_to |
|
|
call can_move_to |
|
|
ret nz |
|
|
|
|
|
|
|
|
ret z |
|
|
|
|
|
|
|
|
; bottom right |
|
|
; bottom right |
|
|
inc c |
|
|
inc c |
|
@ -73,7 +79,7 @@ player_bg_collides:: |
|
|
ret |
|
|
ret |
|
|
|
|
|
|
|
|
; Check if the player is in mid-air |
|
|
; Check if the player is in mid-air |
|
|
; @note NZ = false, Z = true |
|
|
|
|
|
|
|
|
; @note NZ = true, Z = false |
|
|
player_in_air:: |
|
|
player_in_air:: |
|
|
; c = x % 8 == 0 ? x/8 : x/8 + 1 |
|
|
; c = x % 8 == 0 ? x/8 : x/8 + 1 |
|
|
ld a, [PLAYER_X] |
|
|
ld a, [PLAYER_X] |
|
@ -97,7 +103,7 @@ player_in_air:: |
|
|
inc b |
|
|
inc b |
|
|
|
|
|
|
|
|
call can_move_to |
|
|
call can_move_to |
|
|
ret nz |
|
|
|
|
|
|
|
|
ret z |
|
|
|
|
|
|
|
|
inc c |
|
|
inc c |
|
|
call can_move_to |
|
|
call can_move_to |
|
@ -108,7 +114,7 @@ player_in_air:: |
|
|
; @param b y-coordinate |
|
|
; @param b y-coordinate |
|
|
; @param c x-coordinate |
|
|
; @param c x-coordinate |
|
|
; @destroy a, d, e |
|
|
; @destroy a, d, e |
|
|
; @note NZ = false, Z = true |
|
|
|
|
|
|
|
|
; @note NZ = true, Z = false |
|
|
can_move_to: |
|
|
can_move_to: |
|
|
push bc |
|
|
push bc |
|
|
push hl |
|
|
push hl |
|
@ -129,9 +135,8 @@ can_move_to: |
|
|
jr nz, .mul_y_width |
|
|
jr nz, .mul_y_width |
|
|
add hl, bc |
|
|
add hl, bc |
|
|
|
|
|
|
|
|
; check [hl] = 1 |
|
|
|
|
|
ld a, [hl] |
|
|
ld a, [hl] |
|
|
cp 1 |
|
|
|
|
|
|
|
|
and COLLF_WALK |
|
|
|
|
|
|
|
|
pop hl |
|
|
pop hl |
|
|
pop bc |
|
|
pop bc |
|
|