Added player collision checks

This commit is contained in:
blondie7575 2017-09-02 20:52:19 -07:00
parent fb11e3dbd0
commit 72f724ff29
7 changed files with 192 additions and 66 deletions

View File

@ -19,6 +19,7 @@
7099E3841F41022100182A82 /* gameobject.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameobject.s; sourceTree = "<group>"; };
7099E3851F4107B100182A82 /* GenerateVRAMYOffset.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = GenerateVRAMYOffset.py; sourceTree = "<group>"; };
70A80FB01F43D7F200BD34C9 /* gamemanager.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gamemanager.s; sourceTree = "<group>"; };
70C073091F5BAA3E009844A9 /* collision.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = collision.s; sourceTree = "<group>"; };
70E9D85F1F2BD95400555C19 /* equates.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = equates.s; sourceTree = "<group>"; };
70E9D8601F2BD95400555C19 /* graphics.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = graphics.s; sourceTree = "<group>"; };
70E9D8611F2BD95400555C19 /* gscats.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gscats.s; sourceTree = "<group>"; };
@ -40,6 +41,7 @@
706DF1641F2D39F700AA6680 /* loader.s */,
700FFAFB1F40F3BF00A442DE /* font.s */,
706DF1651F2D4A8100AA6680 /* terrain.s */,
70C073091F5BAA3E009844A9 /* collision.s */,
70F086A01F4230CB002446C3 /* utility.s */,
700C39C51F2E5CA800C24F9C /* tables.s */,
70F0869F1F413A89002446C3 /* player.s */,

122
collision.s Normal file
View File

@ -0,0 +1,122 @@
;
; collision
;
; Created by Quinn Dunki on 9/2/17
;
rectParams:
.word 0 ; x
.word 0 ; y 0=terrain bottom, +y=up
.word 0 ; w
.word 0 ; h
rectParams2:
.word 0 ; x
.word 0 ; y 0=terrain bottom, +y=up
.word 0 ; w
.word 0 ; h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; intersectRectTerrain
;
; A => non zero if rectangle is intersecting terrain
;
intersectRectTerrain:
phy
; Convert X to words and compute horizontal extent
; Note that X counts from right terrain edge
lda rectParams
clc
adc rectParams+4 ; Reverse rect horizontally
lsr ; Convert X to bytes
and #$fffe ; Force even
sta rectParams
lda #TERRAINWIDTH/2 ; Reverse X coordinate system
sec
sbc rectParams
sta rectParams
tay ; We'll need this later as an index into height data words
lsr rectParams+4 ; Convert width to bytes
sec
sbc rectParams+4 ; Convert width to extent
sta rectParams+4
; Convert height to vertical extent
lda rectParams+2
sec
sbc rectParams+6
sta rectParams+6
; Check Y bottom
intersectRectTerrainBottomLoop:
lda terrainData,y
cmp rectParams+6
bpl intersectRectTerrainYep
dey
dey
cpy rectParams+4
bpl intersectRectTerrainBottomLoop
lda #0
ply
rts
intersectRectTerrainYep:
lda #1
ply
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; intersectRectRect
;
; A => non zero if rectangle is intersecting rectangle2
;
intersectRectRect:
lda rectParams+0 ; Convert widths to extents
clc
adc rectParams+4
sta rectParams+4
lda rectParams2+0
clc
adc rectParams2+4
sta rectParams2+4
lda rectParams+2 ; Convert heights to extents
sec
sbc rectParams+6
sta rectParams+6
lda rectParams2+2
sec
sbc rectParams2+6
sta rectParams2+6
lda rectParams+0 ; Past their right edge?
cmp rectParams2+4
bpl intersectRectRectNope
lda rectParams+4 ; Before their left edge?
cmp rectParams2+0
bmi intersectRectRectNope
lda rectParams+2 ; Past their bottom edge?
cmp rectParams2+6
bmi intersectRectRectNope
lda rectParams+6 ; Before their top edge?
cmp rectParams2+2
bpl intersectRectRectNope
lda #1
rts
intersectRectRectNope:
lda #0
rts

Binary file not shown.

View File

@ -31,6 +31,7 @@ quitGame:
.include "graphics.s"
.include "font.s"
.include "terrain.s"
.include "collision.s"
.include "gameobject.s"
.include "player.s"
.include "utility.s"

View File

@ -103,7 +103,7 @@ playerDeltaAngleClampHigh:
; Y = Player index
;
playerFire:
SAVE_AY
pha
PLAYERPTR_Y
lda playerData+GO_POSX,y
@ -118,7 +118,30 @@ playerFire:
sta projectileParams+6
jsr fireProjectile
RESTORE_AY
pla
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; playerIntersectRect
;
; Y = Player index
; rectParams = Rectangle to intersect with us
; A => non zero if rectangle is intersecting player
;
playerIntersectRect:
PLAYERPTR_Y
lda playerData+GO_POSX,y
sta rectParams2+0
lda playerData+GO_POSY,y
sta rectParams2+2
lda #GAMEOBJECTWIDTH
sta rectParams2+4
lda #GAMEOBJECTHEIGHT
sta rectParams2+6
jsr intersectRectRect
rts

View File

@ -98,8 +98,10 @@ fireProjectile:
updateProjectiles:
SAVE_AY
lda projectileData+GO_POSX
bmi updateProjectilesDone
bpl updateProjectilesActive
jmp updateProjectilesDone
updateProjectilesActive:
; Integrate gravity over velocity
lda projectileData+JD_VY
clc
@ -127,10 +129,15 @@ updateProjectiles:
lsr
lsr
sta projectileData+GO_POSX
bmi updateProjectilesDelete
bmi updateProjectilesOffWorld
cmp #TERRAINWIDTH-GAMEOBJECTWIDTH-1
bpl updateProjectilesDelete
bpl updateProjectilesOffWorld
bra updateProjectilesContinue
updateProjectilesOffWorld:
jmp updateProjectilesDelete
updateProjectilesContinue:
; Integrate Y velocity over position
lda projectileData+JD_VY
; Convert 8.8 to 12.4
@ -157,6 +164,29 @@ updateProjectiles:
cmp #201
bpl updateProjectilesDelete
; Check for player collisions
ldy #0
lda projectileData+GO_POSX
sta rectParams
lda projectileData+GO_POSY
sta rectParams+2
lda #GAMEOBJECTWIDTH
sta rectParams+4
lda #GAMEOBJECTHEIGHT
sta rectParams+6
updateProjectilesPlayerLoop:
iny
cpy #NUMPLAYERS
beq updateProjectilesPlayerDone
cpy currentPlayer
beq updateProjectilesPlayerLoop
jsr playerIntersectRect
cmp #0
bne updateProjectilesPlayerHit
updateProjectilesPlayerDone:
; Check for terrain collisions
lda projectileData+GO_POSX
sta rectParams
@ -167,9 +197,9 @@ updateProjectiles:
lda #GAMEOBJECTHEIGHT
sta rectParams+6
jsr intersectRect
jsr intersectRectTerrain
cmp #0
bne updateProjectilesDelete
bne updateProjectilesTerrainHit
updateProjectilesDone:
RESTORE_AY
@ -182,6 +212,13 @@ updateProjectilesDelete:
sta turnRequested
bra updateProjectilesDone
updateProjectilesPlayerHit:
brk
bra updateProjectilesDelete
updateProjectilesTerrainHit:
bra updateProjectilesDelete
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; deleteProjectile

View File

@ -271,65 +271,6 @@ generateTerrainLoop:
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; intersectRect
;
; A = non zero if rectangle is intersecting terrain
;
rectParams:
.word 0 ; x
.word 0 ; y 0=terrain bottom, +y=up
.word 0 ; w
.word 0 ; h
intersectRect:
phy
; Convert X to words and compute horizontal extent
; Note that X counts from right terrain edge
lda rectParams
clc
adc rectParams+4 ; Reverse rect horizontally
lsr ; Convert X to bytes
and #$fffe ; Force even
sta rectParams
lda #TERRAINWIDTH/2 ; Reverse X coordinate system
sec
sbc rectParams
sta rectParams
tay ; We'll need this later as an index into height data words
lsr rectParams+4 ; Convert width to bytes
sec
sbc rectParams+4 ; Convert width to extent
sta rectParams+4
; Convert height to vertical extent
lda rectParams+2
sec
sbc rectParams+6
sta rectParams+6
; Check Y bottom
intersectRectBottomLoop:
lda terrainData,y
cmp rectParams+6
bpl intersectRectYep
dey
dey
cpy rectParams+4
bpl intersectRectBottomLoop
lda #0
ply
rts
intersectRectYep:
lda #1
ply
rts
; Terrain data, stored as height values 4 pixels wide