-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started on collision detection between objects
- Loading branch information
1 parent
fdc11d4
commit c1d93b8
Showing
11 changed files
with
224 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
235 changes: 120 additions & 115 deletions
235
...cts/collision/object-object-collision.asm → ...tes/gameplay/objects/object-collision.asm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,120 @@ | ||
|
||
; ANCHOR: enemy-bullet-collision-start | ||
include "src/main/includes/hardware.inc" | ||
include "src/main/includes/constants.inc" | ||
include "src/main/includes/hardware.inc" | ||
|
||
|
||
SECTION "ObjectObjectCollisionVariables", WRAM0 | ||
wSizeY:: db | ||
wSizeX:: db | ||
wCheckByte: db | ||
|
||
SECTION "ObjectObjectCollision", ROM0 | ||
|
||
CheckCollisionWithObjectsInHL_andDE:: | ||
|
||
; SAve original values for y axis | ||
push de | ||
push hl | ||
|
||
XAxis: | ||
|
||
; Save which byte we are checking | ||
ld a, object_xLowByte | ||
ld [wCheckByte], a | ||
|
||
; Save if the minimum distance | ||
ld a, [wSizeX] | ||
ld [wSize], a | ||
|
||
call CheckObjectBytesOfObjects_InDE_AndHL | ||
|
||
; Restore original vaues just in case | ||
pop hl | ||
pop de | ||
|
||
jp nz, YAxis | ||
|
||
ld a,0 | ||
and a | ||
ret | ||
|
||
YAxis: | ||
|
||
; Save which byte we are checking | ||
ld a, object_yLowByte | ||
ld [wCheckByte], a | ||
|
||
; Save if the minimum distance | ||
ld a, [wSizeY] | ||
ld [wSize], a | ||
|
||
call CheckObjectBytesOfObjects_InDE_AndHL | ||
|
||
; Normal return with the z/c flags as-is | ||
ret | ||
|
||
|
||
CheckObjectBytesOfObjects_InDE_AndHL:: | ||
|
||
; put de in hl so we can get the x bytes (for the de object) in bc and descale just to c | ||
|
||
push hl | ||
; Offset de by the check byte | ||
ld a, [wCheckByte] | ||
add a,e | ||
ld e,a | ||
|
||
; copy the low byte to c | ||
ld a, [de] | ||
ld c, a | ||
|
||
; move to the high byte | ||
inc de | ||
|
||
; copy the high byte to b | ||
ld a, [de] | ||
ld b, a | ||
|
||
; Descale | ||
REPT 4 | ||
srl b | ||
rr c | ||
ENDR | ||
|
||
ld a, c | ||
ld [wObject1Value], a | ||
|
||
pop hl | ||
|
||
; get the bytes (for the hl object) in bc and descale just to c | ||
ld a, [wCheckByte] | ||
add a, l | ||
ld l, a | ||
|
||
; move to the high byte | ||
ld a, [hli] | ||
ld c, a | ||
|
||
; copy the high byte to b | ||
ld a, [hl] | ||
ld b, a | ||
|
||
; Descale | ||
REPT 4 | ||
srl b | ||
rr c | ||
ENDR | ||
|
||
ld a, c | ||
ld [wObject2Value], a | ||
|
||
call CheckObjectPositionDifference | ||
ret | ||
|
||
; ANCHOR: object-collision-start | ||
include "src/main/includes/hardware.inc" | ||
include "src/main/includes/constants.inc" | ||
include "src/main/includes/hardware.inc" | ||
|
||
|
||
SECTION "ObjectObjectCollisionVariables", WRAM0 | ||
wSizeY:: db | ||
wSizeX:: db | ||
wCheckByte: db | ||
|
||
SECTION "ObjectObjectCollision", ROM0 | ||
|
||
; ANCHOR_END: object-collision-start | ||
; ANCHOR: object-collision-x | ||
|
||
CheckCollisionWithObjectsInHL_andDE:: | ||
|
||
; SAve original values for y axis | ||
push de | ||
push hl | ||
XAxis: | ||
|
||
; Save which byte we are checking | ||
ld a, object_xLowByte | ||
ld [wCheckByte], a | ||
|
||
; Save if the minimum distance | ||
ld a, [wSizeX] | ||
ld [wSize], a | ||
|
||
call CheckObjectBytesOfObjects_InDE_AndHL | ||
|
||
; Restore original vaues just in case | ||
pop hl | ||
pop de | ||
|
||
jp nz, YAxis | ||
|
||
ld a,0 | ||
and a | ||
ret | ||
; ANCHOR_END: object-collision-x | ||
; ANCHOR: object-collision-y | ||
YAxis: | ||
|
||
; Save which byte we are checking | ||
ld a, object_yLowByte | ||
ld [wCheckByte], a | ||
|
||
; Save if the minimum distance | ||
ld a, [wSizeY] | ||
ld [wSize], a | ||
|
||
call CheckObjectBytesOfObjects_InDE_AndHL | ||
|
||
; Normal return with the z/c flags as-is | ||
ret | ||
; ANCHOR_END: object-collision-y | ||
|
||
; ANCHOR: object-collision-check-bytes | ||
CheckObjectBytesOfObjects_InDE_AndHL:: | ||
|
||
; put de in hl so we can get the x bytes (for the de object) in bc and descale just to c | ||
|
||
push hl | ||
; Offset de by the check byte | ||
ld a, [wCheckByte] | ||
add a,e | ||
ld e,a | ||
|
||
; copy the low byte to c | ||
ld a, [de] | ||
ld c, a | ||
|
||
; move to the high byte | ||
inc de | ||
|
||
; copy the high byte to b | ||
ld a, [de] | ||
ld b, a | ||
|
||
; Descale | ||
REPT 4 | ||
srl b | ||
rr c | ||
ENDR | ||
|
||
ld a, c | ||
ld [wObject1Value], a | ||
|
||
pop hl | ||
|
||
; get the bytes (for the hl object) in bc and descale just to c | ||
ld a, [wCheckByte] | ||
add a, l | ||
ld l, a | ||
|
||
; move to the high byte | ||
ld a, [hli] | ||
ld c, a | ||
|
||
; copy the high byte to b | ||
ld a, [hl] | ||
ld b, a | ||
|
||
; Descale | ||
REPT 4 | ||
srl b | ||
rr c | ||
ENDR | ||
|
||
ld a, c | ||
ld [wObject2Value], a | ||
|
||
call CheckObjectPositionDifference | ||
ret | ||
; ANCHOR_END: object-collision-check-bytes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.