OAM animation of gaining or losing coins during blue/red space effect (#22)

This commit is contained in:
xCrystal 2023-12-26 21:04:20 +01:00
parent 28bd777632
commit b530cf90f4
5 changed files with 130 additions and 11 deletions

View File

@ -35,11 +35,12 @@ DEF NOON_HOUR EQU 12 ; 12 PM
DEF MAX_DAYS EQU 36 * 7 ; 252
; significant coins values
DEF START_COINS EQU 100
DEF MOM_COINS EQU 2300
DEF MAX_COINS EQU 999999
DEF MAX_LEVEL_COINS EQU 99999
DEF MAX_CHIPS EQU 9999
DEF START_COINS EQU 100
DEF MOM_COINS EQU 2300
DEF MAX_COINS EQU 999999
DEF MAX_LEVEL_COINS EQU 99999
DEF MAX_DELTA_COINS_DIGITS EQU 5
DEF MAX_CHIPS EQU 9999
; link record
DEF MAX_LINK_RECORD EQU 9999

View File

@ -8,12 +8,13 @@ DEF AUTO_INPUT EQU $ff
; wDisplaySecondarySprites
const_def
const SECONDARYSPRITES_BOARD_MENU_F ; 0
const SECONDARYSPRITES_DIE_ROLL_F ; 1
const SECONDARYSPRITES_SPACES_LEFT_F ; 2
const SECONDARYSPRITES_BRANCH_SPACE_F ; 3
const SECONDARYSPRITES_VIEW_MAP_MODE_F ; 4
const SECONDARYSPRITES_TALKER_EVENT_F ; 5
const SECONDARYSPRITES_BOARD_MENU_F ; 0
const SECONDARYSPRITES_DIE_ROLL_F ; 1
const SECONDARYSPRITES_SPACES_LEFT_F ; 2
const SECONDARYSPRITES_BRANCH_SPACE_F ; 3
const SECONDARYSPRITES_VIEW_MAP_MODE_F ; 4
const SECONDARYSPRITES_TALKER_EVENT_F ; 5
const SECONDARYSPRITES_GAIN_OR_LOSE_COINS_F ; 6
; wCurDexMode::
const_def

View File

@ -113,6 +113,8 @@ SpecialsPointers::
add_special FadeOutMusic
add_special Diploma
add_special PrintDiploma
add_special PrintGainCoins
add_special PrintLoseCoins
; Crystal only
add_special Reset ; bank 0

View File

@ -6,6 +6,7 @@ BlueSpaceScript::
scall LandedInRegularSpaceScript_BeforeSpaceEffect
givecoins CUR_LEVEL_COINS, BLUE_RED_SPACE_COINS
playsound SFX_TRANSACTION
special PrintGainCoins
scall LandedInRegularSpaceScript_AfterSpaceEffect
.not_landed
end
@ -16,6 +17,7 @@ RedSpaceScript::
scall LandedInRegularSpaceScript_BeforeSpaceEffect
takecoins CUR_LEVEL_COINS, BLUE_RED_SPACE_COINS
playsound SFX_TRANSACTION
special PrintLoseCoins
scall LandedInRegularSpaceScript_AfterSpaceEffect
.not_landed
end
@ -315,4 +317,43 @@ UnionSpaceScript::
call LoadCurSpaceData
ret
PrintGainCoins:
ld hl, wStringBuffer1
ld a, "<COIN>"
ld [hli], a
ld a, "<PLUS>"
ld [hli], a
jr PrintGainOrLoseCoins
PrintLoseCoins:
ld hl, wStringBuffer1
ld a, "<COIN>"
ld [hli], a
ld a, "<MINUS>"
ld [hli], a
; fallthrough
PrintGainOrLoseCoins:
push hl
; fill string space with "@" to ensure that it is terminated with at least one "@"
ld a, "@"
ld c, MAX_DELTA_COINS_DIGITS + 1
.loop
ld [hli], a
dec c
jr nz, .loop
pop hl
; copy coins amount string to wStringBuffer1 + $2
ld de, hCoinsTemp
lb bc, 3 | 1 << 6, MAX_DELTA_COINS_DIGITS ; 3 bytes, left aligned, no leading zeros, 5 digits
call PrintNum
ld hl, wDisplaySecondarySprites
set SECONDARYSPRITES_GAIN_OR_LOSE_COINS_F, [hl]
call UpdateActiveSprites
ld c, 45 ; 750 ms
call DelayFrames
ld hl, wDisplaySecondarySprites
res SECONDARYSPRITES_GAIN_OR_LOSE_COINS_F, [hl]
ret
INCLUDE "engine/board/disabled_spaces.asm"

View File

@ -3118,6 +3118,8 @@ InitSecondarySprites:
call nz, InitViewMapModeSprites
bit SECONDARYSPRITES_TALKER_EVENT_F, a
call nz, InitTalkerEventSprites
bit SECONDARYSPRITES_GAIN_OR_LOSE_COINS_F, a
call nz, InitGainOrLoseCoinsSprites
ret
InitBoardMenuSprites:
@ -3374,6 +3376,8 @@ InitViewMapModeSprites:
ret
InitTalkerEventSprites:
push af
; find the beginning of free space in OAM, and assure there's space for 8 objects
ldh a, [hUsedSpriteIndex]
cp (NUM_SPRITE_OAM_STRUCTS * SPRITEOAMSTRUCT_LENGTH) - (8 * SPRITEOAMSTRUCT_LENGTH) + 1
@ -3406,4 +3410,74 @@ InitTalkerEventSprites:
pop af
ret
InitGainOrLoseCoinsSprites:
push af
; print string at wStringBuffer1 as OAM
; get string length
ld hl, wStringBuffer1
ld c, 0
.get_length_loop
ld a, [hli]
cp "@"
jr z, .got_length
inc c
ld a, c
cp $2 + MAX_DELTA_COINS_DIGITS + 1
jr nz, .get_length_loop
.got_length
ld e, c
; find the beginning of free space in OAM, and assure there's space for c objects
ld a, (NUM_SPRITE_OAM_STRUCTS * SPRITEOAMSTRUCT_LENGTH) + 1
sla c ;
sla c ; c *= SPRITEOAMSTRUCT_LENGTH
sub c
ld b, a ; b = (NUM_SPRITE_OAM_STRUCTS * SPRITEOAMSTRUCT_LENGTH) - (c * SPRITEOAMSTRUCT_LENGTH) + 1
ldh a, [hUsedSpriteIndex]
cp b
jr nc, .oam_full
; align OAM in the X axis according to the string length (e)
ld a, 10 * TILE_WIDTH
ld c, TILE_WIDTH / 2
.x_coord_loop
sub c
dec e
jr nz, .x_coord_loop
; b = SPRITEOAMSTRUCT_XCOORD
ld b, a
; c = SPRITEOAMSTRUCT_YCOORD
ld c, 8 * TILE_WIDTH
; de = address within wShadowOAM
ld a, [hUsedSpriteIndex]
ld e, a
ld d, HIGH(wShadowOAM)
ld hl, wStringBuffer1
.print_oam_loop
ld a, c
ld [de], a ; SPRITEOAMSTRUCT_YCOORD
inc de
ld a, b
ld [de], a ; SPRITEOAMSTRUCT_XCOORD
inc de
add 1 * TILE_WIDTH
ld b, a
ld a, [hli]
ld [de], a ; SPRITEOAMSTRUCT_TILE_ID
inc de
ld a, PAL_OW_MISC
ld [de], a ; SPRITEOAMSTRUCT_ATTRIBUTES
inc de
ld a, [hl]
cp "@"
jr nz, .print_oam_loop
ld a, e
ld [hUsedSpriteIndex], a
.oam_full
pop af
ret
INCLUDE "data/sprites/secondary_sprites.asm"