From 520aaa5a346b62eb11fddf7166c6670f246a8b13 Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Tue, 17 Nov 2020 22:53:30 -0500 Subject: [PATCH] Add collision detection for all of the bug types. Remove the debug code for shooting bugs. It is almost a functional game now! --- BuGS.xcodeproj/project.pbxproj | 8 ++--- BuGS/game.s | 32 -------------------- BuGS/gameFlea.s | 21 +++++++++++++ BuGS/gameScorpion.s | 23 ++++++++++++++ BuGS/gameSegments.s | 55 ++++++++++++++++++++++++---------- BuGS/gameShot.s | 38 +++++++++++++++++++++-- BuGS/gameSpider.s | 39 +++++++++++++++++++++++- BuGS/make/launchEmulator | 2 +- 8 files changed, 162 insertions(+), 56 deletions(-) diff --git a/BuGS.xcodeproj/project.pbxproj b/BuGS.xcodeproj/project.pbxproj index 17777b3..e300575 100644 --- a/BuGS.xcodeproj/project.pbxproj +++ b/BuGS.xcodeproj/project.pbxproj @@ -80,7 +80,7 @@ 9D47CBE02547BEDB00CDA5CB /* gameMushroom.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameMushroom.s; sourceTree = ""; }; 9D47CC14254A698900CDA5CB /* gamePlayer.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gamePlayer.s; sourceTree = ""; }; 9D47CCBA25525C1A00CDA5CB /* tileData.pl */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; path = tileData.pl; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.perl; }; - 9D53E5B32562320300E10169 /* gameShot.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameShot.s; sourceTree = ""; }; + 9D53E5B32562320300E10169 /* gameShot.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameShot.s; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.asm.orcam; }; 9D62AF3B249871A300348F45 /* colour.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = colour.s; sourceTree = ""; }; 9D62AF3F2499CD1E00348F45 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; 9D62AF402499CD3A00348F45 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; @@ -89,11 +89,11 @@ 9D8FFC602491CA28005C9327 /* game.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = game.s; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.asm.orcam; }; 9D8FFC612491CAF0005C9327 /* game.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = game.h; sourceTree = ""; }; 9D9F07F92553AB3800875B29 /* TODO.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = TODO.md; sourceTree = ""; }; - 9DB1505024C3801100558B87 /* gameFlea.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameFlea.s; sourceTree = ""; }; - 9DB1505124C6875C00558B87 /* gameScorpion.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameScorpion.s; sourceTree = ""; }; + 9DB1505024C3801100558B87 /* gameFlea.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameFlea.s; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.asm.orcam; }; + 9DB1505124C6875C00558B87 /* gameScorpion.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameScorpion.s; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.asm.orcam; }; 9DB1505224C7495400558B87 /* globals.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = globals.s; sourceTree = ""; }; 9DB1505324C9E54C00558B87 /* gameSpider.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameSpider.s; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.asm.orcam; }; - 9DB1505424D3BF6C00558B87 /* gameSegments.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameSegments.s; sourceTree = ""; }; + 9DB1505424D3BF6C00558B87 /* gameSegments.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameSegments.s; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.asm.orcam; }; 9DB1505524D3BFCE00558B87 /* global.macros */ = {isa = PBXFileReference; lastKnownFileType = text; path = global.macros; sourceTree = ""; }; 9DC4D7BD24B7652100BACF4B /* ship.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = ship.s; sourceTree = ""; }; 9DC4D7BE24B80C9600BACF4B /* shot.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = shot.s; sourceTree = ""; }; diff --git a/BuGS/game.s b/BuGS/game.s index fce8b63..9558e59 100644 --- a/BuGS/game.s +++ b/BuGS/game.s @@ -264,44 +264,12 @@ checkKey_loop2 anop beq checkKey_quit cmp #$001b beq checkKey_quit - - cmp #'f' - beq checkKey_shootFlea - cmp #'F' - beq checkKey_shootFlea - - cmp #'s' - beq checkKey_shootScorpion - cmp #'S' - beq checkKey_shootScorpion - - cmp #'p' - beq checkKey_shootSpider - cmp #'P' - beq checkKey_shootSpider cmp #'g' beq checkKey_game - - cmp #'c' - beq checkKey_shootCentipede - cmp #'C' - beq checkKey_shootCentipede checkKey_done anop rtl - -checkKey_shootFlea anop - jmp shootFlea - -checkKey_shootScorpion anop - jmp shootScorpion - -checkKey_shootSpider anop - jmp shootSpider - -checkKey_shootCentipede anop - jmp shootRandomSegment checkKey_quit anop stz shouldQuit diff --git a/BuGS/gameFlea.s b/BuGS/gameFlea.s index 3290ad0..aa47438 100644 --- a/BuGS/gameFlea.s +++ b/BuGS/gameFlea.s @@ -253,6 +253,27 @@ setFleaSpeed_fast anop sta fleaUpdatePerTile rtl + +; See the isSpiderCollision for info about the requirements and limitations of this routine +isFleaCollision entry + ldx fleaState + cpx #FLEA_STATE_FALLING + bne isFleaCollision_returnFalse + cmp fleaTileOffsets + beq isFleaCollision_returnTrue + cmp fleaTileOffsets+2 + beq isFleaCollision_returnTrue + cmp fleaTileOffsets+4 + beq isFleaCollision_returnTrue + cmp fleaTileOffsets+6 + bne isFleaCollision_returnFalse +isFleaCollision_returnTrue anop + sec + rtl +isFleaCollision_returnFalse anop + clc + rtl + shootFlea entry lda fleaState diff --git a/BuGS/gameScorpion.s b/BuGS/gameScorpion.s index e5d583d..b87842d 100644 --- a/BuGS/gameScorpion.s +++ b/BuGS/gameScorpion.s @@ -332,6 +332,29 @@ addScorpion_done anop rtl +; See isSpiderCollision for the requirements of this routine and +; for info about its limitation +isScorpionCollision entry + ldx scorpionState + beq isScorpionCollision_returnFalse + cpx #SCORPION_STATE_EXPLODING + bne isScorpionCollision_test +isScorpionCollision_returnFalse anop + clc + rtl + +isScorpionCollision_test anop + cmp scorpionTileOffsets + beq isScorpionCollision_returnTrue + cmp scorpionTileOffsets+2 + beq isScorpionCollision_returnTrue + cmp scorpionTileOffsets+4 + bne isScorpionCollision_returnFalse +isScorpionCollision_returnTrue anop + sec + rtl + + shootScorpion entry lda scorpionState beq shootScorpion_done diff --git a/BuGS/gameSegments.s b/BuGS/gameSegments.s index 2b5ab04..4b94132 100644 --- a/BuGS/gameSegments.s +++ b/BuGS/gameSegments.s @@ -1677,8 +1677,46 @@ addCentipede_body anop plx addCentipede_done anop rtl - + +; The accummulator has the tile offset where the collision happened +; The y register has the address where the collision happened +; +; The result is a clear carry if there is no collision found or +; a set carry and the segment num * 2 in the X register +isSegmentCollision entry + ldy numSegments + beq isSegmentCollision_returnFalse + + ldx #SEGMENT_MAX_OFFSET +isSegmentCollision_loop anop + ldy segmentStates,x + beq isSegmentCollision_nextSegment + cpy #SEGMENT_STATE_EXPLODING + beq isSegmentCollision_nextSegment + ldy segmentPosOffset,x + cmp segmentTileOffsetsLL,y + beq isSegmentCollision_returnTrue + cmp segmentTileOffsetsLR,y + beq isSegmentCollision_returnTrue + cmp segmentTileOffsetsUL,y + beq isSegmentCollision_returnTrue + cmp segmentTileOffsetsUR,y + beq isSegmentCollision_returnTrue +isSegmentCollision_nextSegment anop + dex + dex + bpl isSegmentCollision_loop + +isSegmentCollision_returnFalse anop + clc + rtl + +isSegmentCollision_returnTrue anop + sec + rtl + + ; Call this with the segment num * 2 in the X register shootSegment entry dec numSegments @@ -1732,21 +1770,6 @@ shootSegment_skipMushroom anop sta segmentStates+2,x shootSegment_done anop rtl - - -shootRandomSegment entry - lda numSegments - bne shootRandomSegment_hasSegments - rtl -shootRandomSegment_hasSegments anop - lda #12 - jsl randN - asl a - tax - lda segmentStates,x - cmp #SEGMENT_STATE_HEAD - blt shootRandomSegment_hasSegments - jmp shootSegment segmentsAddEnabled dc i2'1' diff --git a/BuGS/gameShot.s b/BuGS/gameShot.s index ffb48b6..97955fb 100644 --- a/BuGS/gameShot.s +++ b/BuGS/gameShot.s @@ -142,8 +142,42 @@ updateShot_checkCollision anop updateShot_collision anop and #$3333 bne updateShot_maybeMushroom -; TODO - Write the code to test for a collision with fleas, spiders, scorpions or centipede segments - bra updateShot_done + + txy + txa + sec + sbc #SCREEN_ADDRESS + and #$fffc + tax + lda >screenToTileOffset,x + cmp #SPIDER_STARTING_TOP_ROW_OFFSET + blt updateShot_maybeScorpion + jsl isSpiderCollision + bcc updateShot_notSpiderOrScorpion + lda #SHOT_STATE_NONE + sta shotState + jmp shootSpider + +updateShot_maybeScorpion anop + jsl isScorpionCollision + bcc updateShot_notSpiderOrScorpion + lda #SHOT_STATE_NONE + sta shotState + jmp shootScorpion + +updateShot_notSpiderOrScorpion anop + jsl isFleaCollision + bcc updateShot_maybeSegment + lda #SHOT_STATE_NONE + sta shotState + jmp shootFlea + +updateShot_maybeSegment anop + jsl isSegmentCollision + bcc updateShot_done + lda #SHOT_STATE_NONE + sta shotState + jmp shootSegment updateShot_maybeMushroom anop txa diff --git a/BuGS/gameSpider.s b/BuGS/gameSpider.s index 41cb334..5a32963 100644 --- a/BuGS/gameSpider.s +++ b/BuGS/gameSpider.s @@ -758,7 +758,44 @@ setSpiderSpeed_fast anop long i,m rtl - + + +; The accumulator has the tile where the collision occurred. +; The y register has the address where the collision occurred. +; This routine is expected to preserve the y register and the +; accummulator. It can change the x register. +; +; For now, the implementation is very rough and just looks to see if +; collision is in a tile overlapping with the spider. It would be +; better to look closely at the address and try to figure out if it +; really collided. +; +; The result here is returned in the C bit of the processor status +; register +isSpiderCollision entry + ldx spiderState + cpx #SPIDER_STATE_LEFT_DIAG_DOWN + bge isSpiderCollision_test +isSpiderCollision_returnFalse anop + clc + rtl +isSpiderCollision_test anop + cmp spiderTileOffsets + beq isSpiderCollision_returnTrue + cmp spiderTileOffsets+2 + beq isSpiderCollision_returnTrue + cmp spiderTileOffsets+4 + beq isSpiderCollision_returnTrue + cmp spiderTileOffsets+6 + beq isSpiderCollision_returnTrue + cmp spiderTileOffsets+8 + beq isSpiderCollision_returnTrue + cmp spiderTileOffsets+10 + bne isSpiderCollision_returnFalse +isSpiderCollision_returnTrue anop + sec + rtl + shootSpider entry lda spiderState diff --git a/BuGS/make/launchEmulator b/BuGS/make/launchEmulator index e9e7086..9d26123 100755 --- a/BuGS/make/launchEmulator +++ b/BuGS/make/launchEmulator @@ -27,7 +27,7 @@ sed -i "" "s:^s7d1 *=.*$:s7d1 = $DISKIMAGE:" config.txt # This magic ensure that clicking stop in Xcode results in the emulator terminating. -$EMULATORPATH & +$EMULATORPATH -fullscreen & PID=$! trap 'kill $PID' SIGTERM SIGINT SIGHUP EXIT