Add grading system courtesy CreeperCraftYT

This commit is contained in:
Randy Thiemann 2023-10-31 16:32:31 +01:00
parent 12bfe77ed3
commit 5121d1a4c5
11 changed files with 2973 additions and 2686 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -2055,6 +2055,9 @@ FieldDelay::
; Copy over the newly cleaned field.
call ToShadowField
; Rank checks.
call UpdateGrade
; Don't do anything if there were line clears
ldh a, [hLineClearCt]
cp a, 0
@ -4176,6 +4179,9 @@ BigFieldDelay::
; Copy over the newly cleaned field.
call BigToShadowField
; Rank checks.
call UpdateGrade
; Don't do anything if there were line clears
ldh a, [hLineClearCt]
cp a, 0

164
src/grading_systems.asm Normal file
View File

@ -0,0 +1,164 @@
; DMGTRIS
; Copyright (C) 2023 - Randy Thiemann <randy.thiemann@gmail.com>
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <https://www.gnu.org/licenses/>.
IF !DEF(GRADING_SYSTEMS_ASM)
DEF GRADING_SYSTEMS_ASM EQU 1
INCLUDE "globals.asm"
SECTION "Grade Variables", WRAM0
wDecayRate: ds 1
wGradePoints: ds 1
wInternalGrade: ds 1
wDisplayedGrade:: ds 1
SECTION "Grading Data", ROM0
sGradeScores:
dw $0004 ;00 — 8
dw $0008 ;00 — 7
dw $0014 ;00 — 6
dw $0020 ;00 — 5
dw $0035 ;00 — 4
dw $0055 ;00 — 3
dw $0080 ;00 — 2
dw $0120 ;00 — 1
dw $0160 ;00 — S1
dw $0220 ;00 — S2
dw $0300 ;00 — S3
dw $0400 ;00 — S4
dw $0520 ;00 — S5
dw $0660 ;00 — S6
dw $0820 ;00 — S7
dw $1000 ;00 — S8
dw $1200 ;00 — S9
SECTION "Grading Functions", ROM0
; Wipe the grading variables.
GradeInit::
xor a, a
ld [wDecayRate], a
ld [wGradePoints], a
ld [wInternalGrade], a
ld [wDisplayedGrade], a
ret
; Gets the highest grade the player qualifies for.
UpdateGrade::
; Skip to GM check if past S9.
ld a, [wDisplayedGrade]
cp a, GRADE_S9
jr c, .trygradeup
jr CheckForGM
.trygradeup
; Get our score into BC
call PrepareScore
; Double our current grade and use it as an offset into the scoring table.
ld a, [wDisplayedGrade]
add a
ld d, 0
ld e, a
; Have HL point to the next required score and get it into DE.
ld hl, sGradeScores
add hl, de
; LSB
ld a, [hl+]
ld e, a
; MSB
ld a, [hl]
ld d, a
; Check if BC >= DE...
; Return if B < D.
ld a, b
cp a, d
ret c
; We can confidently increase the grade if B > D.
jr nz, .increasegrade
; If B == D, we need to check C and E...
; Return if C < E. Otherwise increase the grade.
ld a, c
cp a, e
ret c
.increasegrade
; Add 1 to the grade.
ld a, [wDisplayedGrade]
inc a
ld [wDisplayedGrade], a
; Play the jingle.
ld a, SFX_RANKUP
call SFXEnqueue
; Loop and see if we can increment more grades.
ld a, [wDisplayedGrade]
cp a, GRADE_S9
ret z
jr .trygradeup
CheckForGM:
; Grade has to be S9.
ld a, [wDisplayedGrade]
cp a, GRADE_S9
ret nz
; Level needs to be 1000 or greater.
ld a, [hCLevel]
cp a, 1
ret c
; Set the grade to GM
ld a, GRADE_GM
ld [wDisplayedGrade], a
; Sound effect
ld a, SFX_RANKUP
jp SFXEnqueue
; Get the four most significant figures of the score in BC as BCD.
PrepareScore:
ld a, [hScore+3]
ld b, a
ld a, [hScore+2]
swap a
or b
ld c, a
ld a, [hScore+1]
ld b, a
ld a, [hScore]
swap a
or b
ld b, a
ret
ENDC

View File

@ -304,4 +304,25 @@ DEF EASTER_1 EQU $9865
; Magic location for bank id.
DEF rBANKID EQU $4007
; Grade names.
DEF GRADE_9 EQU 0
DEF GRADE_8 EQU 1
DEF GRADE_7 EQU 2
DEF GRADE_6 EQU 3
DEF GRADE_5 EQU 4
DEF GRADE_4 EQU 5
DEF GRADE_3 EQU 6
DEF GRADE_2 EQU 7
DEF GRADE_1 EQU 8
DEF GRADE_S1 EQU 9
DEF GRADE_S2 EQU 10
DEF GRADE_S3 EQU 11
DEF GRADE_S4 EQU 12
DEF GRADE_S5 EQU 13
DEF GRADE_S6 EQU 14
DEF GRADE_S7 EQU 15
DEF GRADE_S8 EQU 16
DEF GRADE_S9 EQU 17
DEF GRADE_GM EQU 18
ENDC

View File

@ -1134,10 +1134,10 @@ sTiles::
DB $82,$82,$82,$82,$EC,$EC,$00,$00
DB $44,$44,$CA,$CA,$4A,$4A,$4A,$4A
DB $4A,$4A,$4A,$4A,$E4,$E4,$00,$00
DB $C4,$C4,$2A,$2A,$2A,$2A,$4A,$4A
DB $2A,$2A,$2A,$2A,$C4,$C4,$00,$00
DB $00,$00,$00,$00,$00,$00,$0A,$0A
DB $0A,$0A,$04,$04,$08,$08,$00,$00
DB $C4,$C4,$2C,$2C,$24,$24,$44,$44
DB $24,$24,$24,$24,$CE,$CE,$00,$00
DB $00,$00,$42,$42,$BD,$BD,$42,$42
DB $BD,$BD,$42,$42,$00,$00,$00,$00
sTilesEnd::
sColorTiles::

Binary file not shown.

View File

@ -56,6 +56,8 @@ wSPRModeRNG:: ds 4
wSPRModeRot:: ds 4
wSPRModeDrop:: ds 4
wSPRModeHiG:: ds 4
wGrade0:: ds 4
wGrade1:: ds 4
wUnused0:: ds 4
wUnused1:: ds 4
wUnused2:: ds 4
@ -64,8 +66,6 @@ wUnused4:: ds 4
wUnused5:: ds 4
wUnused6:: ds 4
wUnused7:: ds 4
wUnused8:: ds 4
wUnused9:: ds 4
ENDU
@ -263,7 +263,7 @@ ApplyNext::
ld [wSPRQueue2A+2], a
inc a
ld [wSPRQueue2B+2], a
ret
jp GradeRendering
; Draws the held piece.
@ -603,5 +603,64 @@ SetNumberSpritePositions::
ld [hl], a
ret
GradeRendering::
; Set the Y position of the grade objects.
ld a, $17
ld [wGrade0], a
ld [wGrade1], a
; Set the X position of the grade objects.
ld a, $91
ld [wGrade0+1], a
add a, $8
ld [wGrade1+1], a
; Set the palette of the grade objects.
ld a, $7
ld [wGrade0+3], a
ld [wGrade1+3], a
; Set the grades to blank
ld a, $1
ld [wGrade0+2], a
ld [wGrade1+2], a
; Is the grade S1 or better?
ld a, [wDisplayedGrade]
cp a, GRADE_S1
jr nc, .sgrade
.regulargrade
; Draw as a regular grade.
ld b, a
ld a, "9"
sub a, b
ld [wGrade1+2], a
ret
.sgrade
; Is the grade a GM?
cp a, GRADE_GM
jr z, .gmgrade
; Draw as S grade.
ld a, "S"
ld [wGrade0+2], a
ld a, [wDisplayedGrade]
sub a, GRADE_S1
ld b, a
ld a, "1"
add a, b
ld [wGrade1+2], a
ret
.gmgrade
; Draw as GM grade.
ld a, "G"
ld [wGrade0+2], a
ld a, "M"
ld [wGrade1+2], a
ret
ENDC

View File

@ -120,6 +120,7 @@ SwitchToGameplayB:
call ScoreInit
call LevelInit
call FieldInit
call GradeInit
; We don't start with hold spent.
xor a, a
@ -517,6 +518,7 @@ GamePlayEventLoopHandlerB::
call ScoreInit
call LevelInit
call FieldInit
call GradeInit
xor a, a
ldh [hHoldSpent], a
ld a, MODE_LEADY
@ -738,6 +740,7 @@ SwitchToGameplayBigB:
call ScoreInit
call LevelInit
call BigFieldInit
call GradeInit
; We don't start with hold spent.
xor a, a
@ -1133,6 +1136,7 @@ GamePlayBigEventLoopHandlerB:
call ScoreInit
call LevelInit
call BigFieldInit
call GradeInit
xor a, a
ldh [hHoldSpent], a
ld a, MODE_LEADY