Add pause.

This commit is contained in:
Randy Thiemann 2023-10-21 20:21:49 +02:00
parent e0669afe3a
commit 61ae2c524b
5 changed files with 110 additions and 30 deletions

Binary file not shown.

View File

@ -28,6 +28,7 @@ Please do not try running it on older emulators such as VBA, since this game use
- A — Rotate 1 - A — Rotate 1
- B — Rotate 2 - B — Rotate 2
- Select — Hold - Select — Hold
- Start — Pause
- Up — Sonic drop - Up — Sonic drop
- Down — Soft drop/Lock - Down — Soft drop/Lock
- Left/Right — Move - Left/Right — Move

View File

@ -68,6 +68,9 @@ CHARMAP "#", 125
SECTION "Static Data", ROM0 SECTION "Static Data", ROM0
sLeady:: db " READY? " sLeady:: db " READY? "
sGo:: db " GO " sGo:: db " GO "
sPause::
db "P A U S E "
db " P A U S E"
sPieceXOffsets:: ; How to draw each piece. X-offsets of the sprites. sPieceXOffsets:: ; How to draw each piece. X-offsets of the sprites.
db 0, 8, 16, 24 ; I db 0, 8, 16, 24 ; I
db 0, 8, 8, 16 ; Z db 0, 8, 8, 16 ; Z

View File

@ -152,6 +152,7 @@ DEF GAME_OVER_R10 EQU 133
DEF GAME_OVER_R12 EQU 153 DEF GAME_OVER_R12 EQU 153
DEF GAME_OVER_R14 EQU 173 DEF GAME_OVER_R14 EQU 173
DEF GAME_OVER_OTHER EQU 131 DEF GAME_OVER_OTHER EQU 131
DEF LEADY_GO_TIME EQU 90
ENDC ENDC

View File

@ -31,12 +31,9 @@ DEF MODE_PIECE_IN_MOTION EQU 5
DEF MODE_DELAY EQU 6 DEF MODE_DELAY EQU 6
DEF MODE_GAME_OVER EQU 7 DEF MODE_GAME_OVER EQU 7
DEF MODE_PRE_GAME_OVER EQU 8 DEF MODE_PRE_GAME_OVER EQU 8
DEF MODE_PAUSED EQU 9
SECTION "Gameplay Variables", WRAM0
wMode: ds 1
wModeCounter: ds 1
SECTION "Critical Gameplay Variables", HRAM SECTION "Critical Gameplay Variables", HRAM
hCurrentPiece:: ds 1 hCurrentPiece:: ds 1
hCurrentPieceX:: ds 1 hCurrentPieceX:: ds 1
@ -45,6 +42,9 @@ hCurrentPieceRotationState:: ds 1
hHeldPiece: ds 1 hHeldPiece: ds 1
hHoldSpent:: ds 1 hHoldSpent:: ds 1
hSkipJingle: ds 1 hSkipJingle: ds 1
hMode: ds 1
hModeCounter: ds 1
hPrePause: ds 1
SECTION "Gameplay Functions", ROM0 SECTION "Gameplay Functions", ROM0
@ -90,9 +90,9 @@ SwitchToGameplay::
; Leady mode. ; Leady mode.
ld a, MODE_LEADY ld a, MODE_LEADY
ld [wMode], a ldh [hMode], a
ld a, 90 ld a, LEADY_GO_TIME
ld [wModeCounter], a ldh [hModeCounter], a
; Install the event loop handlers. ; Install the event loop handlers.
ld a, 1 ld a, 1
@ -110,7 +110,7 @@ SwitchToGameplay::
GamePlayEventLoopHandler:: GamePlayEventLoopHandler::
; What mode are we in? ; What mode are we in?
ld a, [wMode] ld a, [hMode]
cp MODE_LEADY cp MODE_LEADY
jr z, leadyMode jr z, leadyMode
cp MODE_GO cp MODE_GO
@ -129,12 +129,14 @@ GamePlayEventLoopHandler::
jp z, preGameOverMode jp z, preGameOverMode
cp MODE_GAME_OVER cp MODE_GAME_OVER
jp z, gameOverMode jp z, gameOverMode
cp MODE_PAUSED
jp z, pauseMode
; Draw "READY" and wait a bit. ; Draw "READY" and wait a bit.
leadyMode: leadyMode:
ld a, [wModeCounter] ldh a, [hModeCounter]
cp a, 90 cp a, LEADY_GO_TIME
jr nz, :+ jr nz, :+
call SFXKill call SFXKill
ld a, SFX_READY_GO ld a, SFX_READY_GO
@ -142,9 +144,9 @@ leadyMode:
: dec a : dec a
jr nz, :+ jr nz, :+
ld a, MODE_GO ld a, MODE_GO
ld [wMode], a ldh [hMode], a
ld a, 90 ld a, LEADY_GO_TIME
: ld [wModeCounter], a : ldh [hModeCounter], a
ld de, sLeady ld de, sLeady
ld hl, wField+(14*10) ld hl, wField+(14*10)
ld bc, 10 ld bc, 10
@ -154,13 +156,13 @@ leadyMode:
; Draw "GO" and wait a bit. ; Draw "GO" and wait a bit.
goMode: goMode:
ld a, [wModeCounter] ldh a, [hModeCounter]
dec a dec a
jr nz, :+ jr nz, :+
ld a, MODE_POSTGO ld a, MODE_POSTGO
ld [wMode], a ldh [hMode], a
xor a, a xor a, a
: ld [wModeCounter], a : ldh [hModeCounter], a
ld de, sGo ld de, sGo
ld hl, wField+(14*10) ld hl, wField+(14*10)
ld bc, 10 ld bc, 10
@ -171,7 +173,7 @@ goMode:
; Clear the field, ready for gameplay. ; Clear the field, ready for gameplay.
postGoMode: postGoMode:
ld a, MODE_FETCH_PIECE ld a, MODE_FETCH_PIECE
ld [wMode], a ldh [hMode], a
call FieldClear call FieldClear
jp drawStaticInfo jp drawStaticInfo
@ -259,7 +261,7 @@ fetchPieceMode:
call SFXEnqueue call SFXEnqueue
.skipJingle .skipJingle
ld a, MODE_SPAWN_PIECE ld a, MODE_SPAWN_PIECE
ld [wMode], a ldh [hMode], a
; State falls through to the next. ; State falls through to the next.
@ -269,16 +271,25 @@ spawnPieceMode:
cp a, $FF cp a, $FF
jr z, :+ jr z, :+
ld a, MODE_PRE_GAME_OVER ld a, MODE_PRE_GAME_OVER
ld [wMode], a ldh [hMode], a
jp drawStaticInfo jp drawStaticInfo
: ld a, MODE_PIECE_IN_MOTION : ld a, MODE_PIECE_IN_MOTION
ld [wMode], a ldh [hMode], a
; This mode lasts for as long as the piece is in motion. ; This mode lasts for as long as the piece is in motion.
; 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 ldh a, [hStartState]
cp a, 1
jr nz, :+
ldh a, [hMode]
ldh [hPrePause], a
ld a, MODE_PAUSED
ldh [hMode], a
jp drawStaticInfo
: call FieldProcess
; Do we hold? ; Do we hold?
ld a, [hSelectState] ld a, [hSelectState]
@ -297,14 +308,14 @@ pieceInMotionMode:
ldh [hCurrentPieceRotationState], a ldh [hCurrentPieceRotationState], a
call DoHold call DoHold
ld a, MODE_SPAWN_PIECE ld a, MODE_SPAWN_PIECE
ld [wMode], a ldh [hMode], a
; Do we go into delay state? ; Do we go into delay state?
: ldh a, [hCurrentLockDelayRemaining] : ldh a, [hCurrentLockDelayRemaining]
cp a, 0 cp a, 0
jr nz, :+ jr nz, :+
ld a, MODE_DELAY ld a, MODE_DELAY
ld [wMode], a ldh [hMode], a
call ToShadowField call ToShadowField
; No fall through this time. ; No fall through this time.
@ -312,13 +323,22 @@ pieceInMotionMode:
delayMode: delayMode:
call FieldDelay ldh a, [hStartState]
cp a, 1
jr nz, :+
ldh a, [hMode]
ldh [hPrePause], a
ld a, MODE_PAUSED
ldh [hMode], a
jp drawStaticInfo
: call FieldDelay
ldh a, [hRemainingDelay] ldh a, [hRemainingDelay]
cp a, 0 cp a, 0
jr nz, :+ jr nz, :+
ld a, MODE_FETCH_PIECE ld a, MODE_FETCH_PIECE
ld [wMode], a ldh [hMode], a
: jp drawStaticInfo : jp drawStaticInfo
@ -417,7 +437,7 @@ preGameOverMode:
.skip7\@ .skip7\@
ENDR ENDR
ld a, MODE_GAME_OVER ld a, MODE_GAME_OVER
ld [wMode], a ldh [hMode], a
gameOverMode: gameOverMode:
@ -434,10 +454,10 @@ gameOverMode:
xor a, a xor a, a
ldh [hHoldSpent], a ldh [hHoldSpent], a
ld a, MODE_LEADY ld a, MODE_LEADY
ld [wMode], a ldh [hMode], a
ld a, 90 ld a, LEADY_GO_TIME
ld [wModeCounter], a ldh [hModeCounter], a
jr drawStaticInfo jp drawStaticInfo
; Quit ; Quit
: ldh a, [hBState] : ldh a, [hBState]
@ -447,6 +467,61 @@ gameOverMode:
jp EventLoopPostHandler jp EventLoopPostHandler
pauseMode:
ldh a, [hStartState]
cp a, 1
jr nz, :+
ldh a, [hPrePause]
ldh [hMode], a
jp drawStaticInfo
; Draw PAUSE all over the field, but not if we came from delay mode.
: ldh a, [hPrePause]
cp a, MODE_DELAY
jr z, drawStaticInfo
ld de, sPause
ld hl, wField+(4*10)
ld bc, 20
call UnsafeMemCopy
ld de, sPause
ld hl, wField+(6*10)
ld bc, 20
call UnsafeMemCopy
ld de, sPause
ld hl, wField+(8*10)
ld bc, 20
call UnsafeMemCopy
ld de, sPause
ld hl, wField+(10*10)
ld bc, 20
call UnsafeMemCopy
ld de, sPause
ld hl, wField+(12*10)
ld bc, 20
call UnsafeMemCopy
ld de, sPause
ld hl, wField+(14*10)
ld bc, 20
call UnsafeMemCopy
ld de, sPause
ld hl, wField+(16*10)
ld bc, 20
call UnsafeMemCopy
ld de, sPause
ld hl, wField+(18*10)
ld bc, 20
call UnsafeMemCopy
ld de, sPause
ld hl, wField+(20*10)
ld bc, 20
call UnsafeMemCopy
ld de, sPause
ld hl, wField+(22*10)
ld bc, 20
call UnsafeMemCopy
jr drawStaticInfo
; Always draw the score, level, next piece, and held piece. ; Always draw the score, level, next piece, and held piece.
drawStaticInfo: drawStaticInfo:
: ld a, [wNextPiece] : ld a, [wNextPiece]