Skip to content

Commit

Permalink
started on collision detection between objects
Browse files Browse the repository at this point in the history
  • Loading branch information
LaroldsJubilantJunkyard committed Dec 16, 2023
1 parent fdc11d4 commit c1d93b8
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 171 deletions.
15 changes: 10 additions & 5 deletions galactic-armada/src/main/states/gameplay/objects/enemies.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include "src/main/includes/constants.inc"
SECTION "Enemies", ROM0
; ANCHOR_END: enemies-start

; ANCHOR: enemies-update
; ANCHOR: enemies-update1
UpdateEnemy::

; get the start of our object back in hl
Expand Down Expand Up @@ -37,6 +37,9 @@ UpdateEnemy::
cp a, 10
jp nc, DeactivateEnemy

; ANCHOR_END: enemies-update1
; ANCHOR: enemies-update2

push hl

; Check for collision for current enemy
Expand All @@ -52,14 +55,16 @@ UpdateEnemy::
cp a, ENEMY_COLLISION_DAMAGED
jp z, DamageEnemy
ret
; ANCHOR_END: enemies-update
; ANCHOR_END: enemies-update2

; ANCHOR: enemies-damage
DamageEnemy:

; Save our pointers
push hl
; Decrease the enemies health byte
push de

; Move to the health byte
ld de, object_healthByte
add hl, de
ld a, [hl]
Expand All @@ -81,7 +86,7 @@ DamageEnemy:
pop de

; Set as damaged for 128 frames
ld a, 128
ld a, 32
ld [hl], a

; Move to the next
Expand Down
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
8 changes: 4 additions & 4 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@
- [Drawing Text](part3/drawing-text.md)
- [Included Utilities](part3/utilities.md)
- [Compilation](part3/compilation.md)
- [Collision Detection](part3/collision.md)
- [Game State Management](part3/game-state-management.md)
- [Title Screen](part3/title-screen.md)
- [Story Screen](part3/story-screen.md)
- [Gameplay](part3/gameplay.md)
- [Object Pools](part3/object-pools.md)
- [Object Collision Detection](part3/object-collisions.md)
- [Scrolling Background](part3/scrolling-background.md)
- [Heads-Up Interface](part3/heads-up-interface.md)
- [The Player](part3/the-player.md)
- [Bullets](part3/bullets.md)
- [Enemies](part3/enemies.md)
- [Collision Detection](part3/collision.md)
- [Enemy Collisions](part3/collision.md)
- [Spawning Enemies](part3/enemy-spawning.md)
- [Enemy Collisions](part3/enemy-collision.md)
- [Conclusion](part3/conclusion.md)



[Where to go next](next.md)
[Resources](resources.md)
[Thanks](thanks.md)
Loading

0 comments on commit c1d93b8

Please sign in to comment.