Browse Source

Optimize collision routines

master
Forest Belton 3 years ago
parent
commit
06ae65e643
1 changed files with 11 additions and 19 deletions
  1. +11
    -19
      src/collision.s

+ 11
- 19
src/collision.s View File

@ -1,13 +1,12 @@
INCLUDE "oam.inc"
SECTION "Collision", ROMX
SECTION "Collision", ROM0
; Determines if player has hit the background
; @return NZ = false, Z = true
player_bg_collides::
; c = x % 8 == 0 ? x/8 : x/8 + 1
ld hl, PLAYER_X
ld a, [hl]
ld a, [PLAYER_X]
ld c, a
and %111
jr z, .skip_inc_c
@ -20,8 +19,7 @@ player_bg_collides::
srl c
; b = y % 8 == 0 ? y/8 : y/8 + 1
inc hl
ld a, [hl]
ld a, [PLAYER_Y]
ld b, a
and %111
jr z, .skip_inc_b
@ -58,8 +56,7 @@ player_bg_collides::
; @note NZ = false, Z = true
player_in_air::
; c = x % 8 == 0 ? x/8 : x/8 + 1
ld hl, PLAYER_X
ld a, [hl]
ld a, [PLAYER_X]
ld c, a
and %111
jr z, .skip_inc_c
@ -72,8 +69,7 @@ player_in_air::
srl c
; b = y % 8 == 0 ? y/8 : y/8 + 1
inc hl
ld a, [hl]
ld a, [PLAYER_Y]
ld b, a
and %111
jr z, .skip_inc_b
@ -107,18 +103,14 @@ can_move_to:
push bc
push hl
; hl = bg_collision_data
ld hl, BG_COLLISION_DATA
ld d, [hl]
inc hl
ld e, [hl]
push de
ld a, [BG_COLLISION_DATA]
ld h, a
ld a, [BG_COLLISION_DATA + 1]
ld l, a
; de = map width
ld hl, BG_MAP_WIDTH
ld a, [BG_MAP_WIDTH]
ld d, 0
ld e, [hl]
pop hl
ld e, a
; compute map index (HL + B * (BG_MAP_WIDTH + 1) + C)
.mul_y_width:

Loading…
Cancel
Save