diff options
author | Rangi <remy.oukaour+rangi42@gmail.com> | 2020-07-07 11:57:03 -0400 |
---|---|---|
committer | Rangi <remy.oukaour+rangi42@gmail.com> | 2020-07-07 14:15:39 -0400 |
commit | 1e593d8f8cd07e1072992dc1fc962b6de7508aad (patch) | |
tree | bded15a11f943c7bc63cd0e47faf1ee2c39ed0b0 /engine/overworld/sprite_collisions.asm | |
parent | 13129459f11e73df8c556f0c02cd4fca7266a346 (diff) |
Remove c1x*/c2x* comments, use struct offset constants
Diffstat (limited to 'engine/overworld/sprite_collisions.asm')
-rw-r--r-- | engine/overworld/sprite_collisions.asm | 72 |
1 files changed, 37 insertions, 35 deletions
diff --git a/engine/overworld/sprite_collisions.asm b/engine/overworld/sprite_collisions.asm index 6f8e3c2c..dc57d5b9 100644 --- a/engine/overworld/sprite_collisions.asm +++ b/engine/overworld/sprite_collisions.asm @@ -1,15 +1,15 @@ _UpdateSprites:: ld h, $c1 inc h - ld a, wSpritePlayerStateData2ImageBaseOffset - wSpritePlayerStateData2 + ld a, SPRITESTATEDATA2_IMAGEBASEOFFSET .spriteLoop ld l, a - sub wSpritePlayerStateData2ImageBaseOffset - wSpritePlayerStateData2 + sub SPRITESTATEDATA2_IMAGEBASEOFFSET ld c, a ldh [hCurrentSpriteOffset], a ld a, [hl] and a - jr z, .skipSprite ; tests $c2Xe + jr z, .skipSprite ; tests SPRITESTATEDATA2_IMAGEBASEOFFSET push hl push de push bc @@ -20,7 +20,7 @@ _UpdateSprites:: .skipSprite ld a, l add $10 ; move to next sprite - cp wSpritePlayerStateData2ImageBaseOffset - wSpritePlayerStateData2 ; test for overflow (back at beginning) + cp SPRITESTATEDATA2_IMAGEBASEOFFSET ; test for overflow (back at beginning) jr nz, .spriteLoop ret .updateCurrentSprite @@ -43,11 +43,12 @@ UpdateNonPlayerSprite: ; This detects if the current sprite (whose offset is at hCurrentSpriteOffset) ; is going to collide with another sprite by looping over the other sprites. -; The current sprite's offset will be labelled with i (e.g. $c1i0). -; The loop sprite's offset will labelled with j (e.g. $c1j0). +; The current sprite's offset will be labelled with i (e.g. i#SPRITESTATEDATA1_PICTUREID). +; The loop sprite's offset will labelled with j (e.g. j#SPRITESTATEDATA1_PICTUREID). ; -; Note that the Y coordinate of the sprite (in [$c1k4]) is one of the following -; 9 values when the sprite is aligned with the grid: $fc, $0c, $1c, $2c, ..., $7c. +; Note that the Y coordinate of the sprite (in [k#SPRITESTATEDATA1_YPIXELS]) +; is one of the following 9 values when the sprite is aligned with the grid: +; $fc, $0c, $1c, $2c, ..., $7c. ; The reason that 4 is added below to the coordinate is to make it align with a ; multiple of $10 to make comparisons easier. DetectCollisionBetweenSprites: @@ -58,7 +59,7 @@ DetectCollisionBetweenSprites: add LOW(wSpriteStateData1) ld l, a - ld a, [hl] ; a = [$c1i0] (picture) (0 if slot is unused) + ld a, [hl] ; a = [i#SPRITESTATEDATA1_PICTUREID] (0 if slot is unused) and a ; is this sprite slot slot used? ret z ; return if not used @@ -66,10 +67,10 @@ DetectCollisionBetweenSprites: add 3 ld l, a - ld a, [hli] ; a = [$c1i3] (delta Y) (-1, 0, or 1) + ld a, [hli] ; a = [i#SPRITESTATEDATA1_YSTEPVECTOR] (-1, 0, or 1) call SetSpriteCollisionValues - ld a, [hli] ; a = [$C1i4] (Y screen coordinate) + ld a, [hli] ; a = [i#SPRITESTATEDATA1_YPIXELS] add 4 ; align with multiple of $10 ; The effect of the following 3 lines is to @@ -81,9 +82,9 @@ DetectCollisionBetweenSprites: ldh [hFF90], a ; store Y coordinate adjusted for direction of movement - ld a, [hli] ; a = [$c1i5] (delta X) (-1, 0, or 1) + ld a, [hli] ; a = [i#SPRITESTATEDATA1_XSTEPVECTOR] (-1, 0, or 1) call SetSpriteCollisionValues - ld a, [hl] ; a = [$C1i6] (X screen coordinate) + ld a, [hl] ; a = [i#SPRITESTATEDATA1_XPIXELS] ; The effect of the following 3 lines is to ; add 7 to a if moving east or @@ -99,13 +100,13 @@ DetectCollisionBetweenSprites: ld l, a xor a - ld [hld], a ; zero [$c1id] XXX what's [$c1id] for? - ld [hld], a ; zero [$c1ic] (directions in which collisions occurred) + ld [hld], a ; zero [i#SPRITESTATEDATA1_0D] XXX what's this for? + ld [hld], a ; zero [i#SPRITESTATEDATA1_COLLISIONDATA] ldh a, [hFF91] - ld [hld], a ; [$c1ib] = adjusted X coordinate + ld [hld], a ; [i#SPRITESTATEDATA1_XADJUSTED] ldh a, [hFF90] - ld [hl], a ; [$c1ia] = adjusted Y coordinate + ld [hl], a ; [i#SPRITESTATEDATA1_YADJUSTED] xor a ; zero the loop counter @@ -118,13 +119,13 @@ DetectCollisionBetweenSprites: jp z, .next ; go to the next sprite if they match ld d, h - ld a, [de] ; a = [$c1j0] (picture) (0 if slot is unused) + ld a, [de] ; a = [j#SPRITESTATEDATA1_PICTUREID] (0 if slot is unused) and a ; is this sprite slot slot used? jp z, .next ; go the next sprite if not used inc e inc e - ld a, [de] ; a = [$c1j2] ($ff means the sprite is offscreen) + ld a, [de] ; a = [j#SPRITESTATEDATA1_IMAGEINDEX] ($ff means the sprite is offscreen) inc a jp z, .next ; go the next sprite if offscreen @@ -133,11 +134,11 @@ DetectCollisionBetweenSprites: ld l, a inc e - ld a, [de] ; a = [$c1j3] (delta Y) + ld a, [de] ; a = [j#SPRITESTATEDATA1_YSTEPVECTOR] call SetSpriteCollisionValues inc e - ld a, [de] ; a = [$C1j4] (Y screen coordinate) + ld a, [de] ; a = [j#SPRITESTATEDATA1_YPIXELS] add 4 ; align with multiple of $10 ; The effect of the following 3 lines is to @@ -147,7 +148,7 @@ DetectCollisionBetweenSprites: and $f0 or c - sub [hl] ; subtract the adjusted Y coordinate of sprite i ([$c1ia]) from that of sprite j + sub [hl] ; subtract [i#SPRITESTATEDATA1_YADJUSTED] from [j#SPRITESTATEDATA1_YADJUSTED] ; calculate the absolute value of the difference to get the distance jr nc, .noCarry1 @@ -157,8 +158,8 @@ DetectCollisionBetweenSprites: ldh [hFF90], a ; store the distance between the two sprites' adjusted Y values ; Use the carry flag set by the above subtraction to determine which sprite's -; Y coordinate is larger. This information is used later to set [$c1ic], -; which stores which direction the collision occurred in. +; Y coordinate is larger. This information is used later to set +; [i#SPRITESTATEDATA1_COLLISIONDATA]. ; The following 5 lines set the lowest 2 bits of c, which are later shifted left by 2. ; If sprite i's Y is larger, set lowest 2 bits of c to 10. ; If sprite j's Y is larger or both are equal, set lowest 2 bits of c to 01. @@ -170,7 +171,7 @@ DetectCollisionBetweenSprites: ; If sprite i's delta Y is 0, then b = 7, else b = 9. ld b, 7 - ld a, [hl] ; a = [$c1ia] (adjusted Y coordinate) + ld a, [hl] ; a = [i#SPRITESTATEDATA1_YADJUSTED] and $f jr z, .next1 ld b, 9 @@ -186,7 +187,7 @@ DetectCollisionBetweenSprites: ; If sprite j's delta Y is 0, then b = 7, else b = 9. ld b, 7 dec e - ld a, [de] ; a = [$c1j3] (delta Y) + ld a, [de] ; a = [j#SPRITESTATEDATA1_YSTEPVECTOR] inc e and a jr z, .next2 @@ -201,13 +202,13 @@ DetectCollisionBetweenSprites: .checkXDistance inc e inc l - ld a, [de] ; a = [$c1j5] (delta X) + ld a, [de] ; a = [j#SPRITESTATEDATA1_XSTEPVECTOR] push bc call SetSpriteCollisionValues inc e - ld a, [de] ; a = [$c1j6] (X screen coordinate) + ld a, [de] ; a = [j#SPRITESTATEDATA1_XPIXELS] ; The effect of the following 3 lines is to ; add 7 to a if moving east or @@ -218,7 +219,7 @@ DetectCollisionBetweenSprites: pop bc - sub [hl] ; subtract the adjusted X coordinate of sprite i ([$c1ib]) from that of sprite j + sub [hl] ; subtract [i#SPRITESTATEDATA1_XADJUSTED] from [j#SPRITESTATEDATA1_XADJUSTED] ; calculate the absolute value of the difference to get the distance jr nc, .noCarry2 @@ -228,8 +229,8 @@ DetectCollisionBetweenSprites: ldh [hFF91], a ; store the distance between the two sprites' adjusted X values ; Use the carry flag set by the above subtraction to determine which sprite's -; X coordinate is larger. This information is used later to set [$c1ic], -; which stores which direction the collision occurred in. +; X coordinate is larger. This information is used later to set +; [i#SPRITESTATEDATA1_COLLISIONDATA]. ; The following 5 lines set the lowest 2 bits of c. ; If sprite i's X is larger, set lowest 2 bits of c to 10. ; If sprite j's X is larger or both are equal, set lowest 2 bits of c to 01. @@ -241,7 +242,7 @@ DetectCollisionBetweenSprites: ; If sprite i's delta X is 0, then b = 7, else b = 9. ld b, 7 - ld a, [hl] ; a = [$c1ib] (adjusted X coordinate) + ld a, [hl] ; a = [i#SPRITESTATEDATA1_XADJUSTED] and $f jr z, .next3 ld b, 9 @@ -257,7 +258,7 @@ DetectCollisionBetweenSprites: ; If sprite j's delta X is 0, then b = 7, else b = 9. ld b, 7 dec e - ld a, [de] ; a = [$c1j5] (delta X) + ld a, [de] ; a = [j#SPRITESTATEDATA1_XSTEPVECTOR] inc e and a jr z, .next4 @@ -287,11 +288,12 @@ DetectCollisionBetweenSprites: .next6 ld a, c ; c has 2 bits set (one of bits 0-1 is set for the X axis and one of bits 2-3 for the Y axis) and b ; we select either the bit in bits 0-1 or bits 2-3 based on the calculation immediately above - or [hl] ; or with existing collision direction bits in [$c1ic] + or [hl] ; or with existing collision direction bits in [i#SPRITESTATEDATA1_COLLISIONDATA] ld [hl], a ; store new value ld a, c ; useless code because a is overwritten before being used again -; set bit in [$c1ie] or [$c1if] to indicate which sprite the collision occurred with +; set bit in [i#SPRITESTATEDATA1_0E] or [i#SPRITESTATEDATA1_0F] +; to indicate which sprite the collision occurred with inc l inc l ldh a, [hFF8F] ; a = loop counter |