diff --git a/GSCats.xcodeproj/project.pbxproj b/GSCats.xcodeproj/project.pbxproj index 096eb84..320c646 100644 --- a/GSCats.xcodeproj/project.pbxproj +++ b/GSCats.xcodeproj/project.pbxproj @@ -19,6 +19,7 @@ 7099E3841F41022100182A82 /* gameobject.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameobject.s; sourceTree = ""; }; 7099E3851F4107B100182A82 /* GenerateVRAMYOffset.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = GenerateVRAMYOffset.py; sourceTree = ""; }; 70A80FB01F43D7F200BD34C9 /* gamemanager.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gamemanager.s; sourceTree = ""; }; + 70C073091F5BAA3E009844A9 /* collision.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = collision.s; sourceTree = ""; }; 70E9D85F1F2BD95400555C19 /* equates.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = equates.s; sourceTree = ""; }; 70E9D8601F2BD95400555C19 /* graphics.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = graphics.s; sourceTree = ""; }; 70E9D8611F2BD95400555C19 /* gscats.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gscats.s; sourceTree = ""; }; @@ -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 */, diff --git a/collision.s b/collision.s new file mode 100644 index 0000000..b308d8d --- /dev/null +++ b/collision.s @@ -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 diff --git a/gscats.2mg b/gscats.2mg index 298dce0..f69079f 100644 Binary files a/gscats.2mg and b/gscats.2mg differ diff --git a/gscats.s b/gscats.s index f63edc2..7e47cd4 100644 --- a/gscats.s +++ b/gscats.s @@ -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" diff --git a/player.s b/player.s index 9375992..ed23201 100644 --- a/player.s +++ b/player.s @@ -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 diff --git a/projectile.s b/projectile.s index dad5f3c..feb1e26 100644 --- a/projectile.s +++ b/projectile.s @@ -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 diff --git a/terrain.s b/terrain.s index 2efab52..76bdb06 100644 --- a/terrain.s +++ b/terrain.s @@ -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