Sonic drop and hold.

This commit is contained in:
Randy Thiemann 2023-10-20 08:40:34 +02:00
parent 0f2e811130
commit 61ef24a9e8
3 changed files with 144 additions and 8 deletions

View File

@ -501,20 +501,40 @@ FieldProcess::
pop de pop de
call DrawPiece 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? ; Gravity?
ldh a, [hTicksUntilG] : ldh a, [hTicksUntilG]
dec a dec a
ldh [hTicksUntilG], a ldh [hTicksUntilG], a
jr nz, .nograv jr nz, .nograv
ldh a, [hCurrentFramesPerGravityTick] ldh a, [hCurrentFramesPerGravityTick]
ldh [hTicksUntilG], a ldh [hTicksUntilG], a
; Move the piece down, but first check if there's still sufficient "down" to go. ; Move the piece down, but first check if there's still sufficient "down" to go.
ldh a, [hCurrentGravityPerTick] ldh a, [hCurrentGravityPerTick]
ld b, a ld b, a
.grav
: ldh a, [hCurrentPieceY] : ldh a, [hCurrentPieceY]
add a, b add a, b
cp a, 22 cp a, 23
jr c, :+ jr c, :+
dec b dec b
jr z, .nograv jr z, .nograv
@ -536,18 +556,21 @@ FieldProcess::
jr z, .nograv jr z, .nograv
jr :- jr :-
.dolower .dolower
pop bc pop bc
ldh a, [hCurrentPieceY] ldh a, [hCurrentPieceY]
add a, b add a, b
ldh [hCurrentPieceY], a ldh [hCurrentPieceY], a
.nograv .nograv
ldh a, [hCurrentPieceX] ldh a, [hCurrentPieceX]
ldh [hWantX], a ldh [hWantX], a
ldh a, [hCurrentPieceRotationState] ldh a, [hCurrentPieceRotationState]
ldh [hWantRotation], a ldh [hWantRotation], a
; Want left? ; Want left?
.wantleft .wantleft
ldh a, [hLeftState] ldh a, [hLeftState]
@ -563,6 +586,7 @@ FieldProcess::
dec a dec a
ldh [hWantX], a ldh [hWantX], a
; Want right? ; Want right?
.wantright .wantright
ldh a, [hRightState] ldh a, [hRightState]
@ -611,7 +635,7 @@ FieldProcess::
ld b, a ld b, a
ldh a, [hCurrentPieceX] ldh a, [hCurrentPieceX]
cp a, b cp a, b
jr z, .postmove ; Neither move nor rotate. jp z, .postmove ; Neither move nor rotate.
; Move only. ; Move only.
ldh a, [hCurrentPieceY] ldh a, [hCurrentPieceY]
@ -623,10 +647,11 @@ FieldProcess::
call GetPieceData call GetPieceData
call CanPieceFit call CanPieceFit
cp a, $FF cp a, $FF
jr nz, .postmove jp nz, .postmove
ldh a, [hWantX] ldh a, [hWantX]
ldh [hCurrentPieceX], a ldh [hCurrentPieceX], a
jr .postmove jp .postmove
.trymoverot .trymoverot
ldh a, [hCurrentPieceY] ldh a, [hCurrentPieceY]
@ -650,8 +675,95 @@ FieldProcess::
pop bc pop bc
call CanPieceFit call CanPieceFit
cp a, $FF 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 jr nz, .postmove
ldh a, [hWantX] ldh a, [hWantX]
dec a
ldh [hCurrentPieceX], a ldh [hCurrentPieceX], a
ldh a, [hWantRotation] ldh a, [hWantRotation]
ldh [hCurrentPieceRotationState], a ldh [hCurrentPieceRotationState], a

View File

@ -25,7 +25,7 @@ hCurrentPieceX:: ds 1
hCurrentPieceY:: ds 1 hCurrentPieceY:: ds 1
hCurrentPieceRotationState:: ds 1 hCurrentPieceRotationState:: ds 1
hHeldPiece: ds 1 hHeldPiece: ds 1
hHoldSpent: ds 1 hHoldSpent:: ds 1
hSkipJingle: ds 1 hSkipJingle: ds 1
@ -227,7 +227,31 @@ spawnPieceMode:
; Field will let us know when it has locked in place. ; Field will let us know when it has locked in place.
pieceInMotionMode: pieceInMotionMode:
call FieldProcess 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: delayMode:

View File

@ -1,5 +1,5 @@
#Emulicious settings file #Emulicious settings file
#Fri Oct 20 08:16:53 CEST 2023 #Fri Oct 20 08:40:06 CEST 2023
WindowEventViewerWindowHeight=1416 WindowEventViewerWindowHeight=1416
WindowEventViewerWindowDivider=876 WindowEventViewerWindowDivider=876
WindowMemoryTracerWindowY=631 WindowMemoryTracerWindowY=631