From 61ef24a9e87bcd3a81a15d46177bcd986e5246c9 Mon Sep 17 00:00:00 2001 From: Randy Thiemann Date: Fri, 20 Oct 2023 08:40:34 +0200 Subject: [PATCH] Sonic drop and hold. --- src/field.asm | 122 +++++++++++++++++++++++++++++++++++++++-- src/state_gameplay.asm | 28 +++++++++- tools/Emulicious.ini | 2 +- 3 files changed, 144 insertions(+), 8 deletions(-) diff --git a/src/field.asm b/src/field.asm index 2b2a946..46f9287 100644 --- a/src/field.asm +++ b/src/field.asm @@ -501,20 +501,40 @@ FieldProcess:: pop de call DrawPiece + + ; Check if we're about to hold. + ld a, [hSelectState] + cp a, 1 + jr nz, :+ + ld a, [hHoldSpent] + cp a, $FF + ret nz + + + ; If we press up, we want to do a sonic drop. + ldh a, [hUpState] + cp a, 1 + jr nz, :+ + ld b, 20 + jr .grav + + ; Gravity? - ldh a, [hTicksUntilG] +: ldh a, [hTicksUntilG] dec a ldh [hTicksUntilG], a jr nz, .nograv ldh a, [hCurrentFramesPerGravityTick] ldh [hTicksUntilG], a + ; Move the piece down, but first check if there's still sufficient "down" to go. ldh a, [hCurrentGravityPerTick] ld b, a +.grav : ldh a, [hCurrentPieceY] add a, b - cp a, 22 + cp a, 23 jr c, :+ dec b jr z, .nograv @@ -536,18 +556,21 @@ FieldProcess:: jr z, .nograv jr :- + .dolower pop bc ldh a, [hCurrentPieceY] add a, b ldh [hCurrentPieceY], a + .nograv ldh a, [hCurrentPieceX] ldh [hWantX], a ldh a, [hCurrentPieceRotationState] ldh [hWantRotation], a + ; Want left? .wantleft ldh a, [hLeftState] @@ -563,6 +586,7 @@ FieldProcess:: dec a ldh [hWantX], a + ; Want right? .wantright ldh a, [hRightState] @@ -611,7 +635,7 @@ FieldProcess:: ld b, a ldh a, [hCurrentPieceX] cp a, b - jr z, .postmove ; Neither move nor rotate. + jp z, .postmove ; Neither move nor rotate. ; Move only. ldh a, [hCurrentPieceY] @@ -623,10 +647,11 @@ FieldProcess:: call GetPieceData call CanPieceFit cp a, $FF - jr nz, .postmove + jp nz, .postmove ldh a, [hWantX] ldh [hCurrentPieceX], a - jr .postmove + jp .postmove + .trymoverot ldh a, [hCurrentPieceY] @@ -650,8 +675,95 @@ FieldProcess:: pop bc call CanPieceFit cp a, $FF + jr nz, .maybekick + ldh a, [hWantX] + ldh [hCurrentPieceX], a + ldh a, [hWantRotation] + ldh [hCurrentPieceRotationState], a + call SetPieceDataOffset + jp .postmove + + + ; Try kicks if the piece isn't I or O. And in the case of J L and T, only if the blocked side is the left or right. +.maybekick + ld c, a + ldh a, [hCurrentPiece] + cp a, PIECE_I + jr z, .postmove + cp a, PIECE_O + jr z, .postmove + cp a, PIECE_S + jr z, .trykickright + cp a, PIECE_Z + jr z, .trykickright + ld a, c + cp a, 1 + jr z, .postmove + cp a, 5 + jr z, .postmove + cp a, 9 + jr z, .postmove + + +.trykickright + ldh a, [hCurrentPieceY] + ld b, a + ldh a, [hWantX] + inc a + call XYToSFieldPtr + ld d, h + ld e, l + ldh a, [hPieceDataBase] + ld l, a + ldh a, [hPieceDataBase+1] + ld h, a + ldh a, [hWantRotation] + rlc a + rlc a + push bc + ld c, a + xor a, a + ld b, a + add hl, bc + pop bc + call CanPieceFit + cp a, $FF + jr nz, .trykickleft + ldh a, [hWantX] + inc a + ldh [hCurrentPieceX], a + ldh a, [hWantRotation] + ldh [hCurrentPieceRotationState], a + call SetPieceDataOffset + jr .postmove + + +.trykickleft + ldh a, [hCurrentPieceY] + ld b, a + ldh a, [hWantX] + dec a + call XYToSFieldPtr + ld d, h + ld e, l + ldh a, [hPieceDataBase] + ld l, a + ldh a, [hPieceDataBase+1] + ld h, a + ldh a, [hWantRotation] + rlc a + rlc a + push bc + ld c, a + xor a, a + ld b, a + add hl, bc + pop bc + call CanPieceFit + cp a, $FF jr nz, .postmove ldh a, [hWantX] + dec a ldh [hCurrentPieceX], a ldh a, [hWantRotation] ldh [hCurrentPieceRotationState], a diff --git a/src/state_gameplay.asm b/src/state_gameplay.asm index 200417f..f52dbf4 100644 --- a/src/state_gameplay.asm +++ b/src/state_gameplay.asm @@ -25,7 +25,7 @@ hCurrentPieceX:: ds 1 hCurrentPieceY:: ds 1 hCurrentPieceRotationState:: ds 1 hHeldPiece: ds 1 -hHoldSpent: ds 1 +hHoldSpent:: ds 1 hSkipJingle: ds 1 @@ -227,7 +227,31 @@ spawnPieceMode: ; Field will let us know when it has locked in place. pieceInMotionMode: call FieldProcess - jr drawStaticInfo + + ; Do we hold? + ld a, [hSelectState] + cp a, 1 + jr nz, :+ + ld a, [hHoldSpent] + cp a, $FF + jr z, :+ + ; Reset position and rotation. + ld a, 5 + ldh [hCurrentPieceX], a + ld a, 3 + ldh [hCurrentPieceY], a + xor a, a + ldh [hSkipJingle], a + ldh [hCurrentPieceRotationState], a + call DoHold + ld a, MODE_SPAWN_PIECE + ld [wMode], a + + ; Do we go into delay state? + ; TODO + + +: jr drawStaticInfo delayMode: diff --git a/tools/Emulicious.ini b/tools/Emulicious.ini index 2cbb59e..581a548 100644 --- a/tools/Emulicious.ini +++ b/tools/Emulicious.ini @@ -1,5 +1,5 @@ #Emulicious settings file -#Fri Oct 20 08:16:53 CEST 2023 +#Fri Oct 20 08:40:06 CEST 2023 WindowEventViewerWindowHeight=1416 WindowEventViewerWindowDivider=876 WindowMemoryTracerWindowY=631