Skip to content

Commit

Permalink
Replace magic numbers with TILE_WIDTH (#1056)
Browse files Browse the repository at this point in the history
* Replace magic numbers with TILE_WIDTH

* Address more instances
  • Loading branch information
Idain authored Jul 27, 2023
1 parent 1d64bef commit 94df3c5
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 62 deletions.
20 changes: 10 additions & 10 deletions engine/battle/trainer_huds.asm
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ ShowPlayerMonsRemaining:
ld de, wPartyCount
call StageBallTilesData
; ldpixel wPlaceBallsX, 12, 12
ld a, 12 * 8
ld a, 12 * TILE_WIDTH
ld hl, wPlaceBallsX
ld [hli], a
ld [hl], a
ld a, 8
ld a, TILE_WIDTH
ld [wPlaceBallsDirection], a
ld hl, wShadowOAMSprite00
jp LoadTrainerHudOAM
Expand All @@ -36,10 +36,10 @@ ShowOTTrainerMonsRemaining:
call StageBallTilesData
; ldpixel wPlaceBallsX, 9, 4
ld hl, wPlaceBallsX
ld a, 9 * 8
ld a, 9 * TILE_WIDTH
ld [hli], a
ld [hl], 4 * 8
ld a, -8
ld [hl], 4 * TILE_WIDTH
ld a, -TILE_WIDTH
ld [wPlaceBallsDirection], a
ld hl, wShadowOAMSprite00 + PARTY_LENGTH * SPRITEOAMSTRUCT_LENGTH
jp LoadTrainerHudOAM
Expand Down Expand Up @@ -182,10 +182,10 @@ LinkBattle_TrainerHuds:
ld de, wPartyCount
call StageBallTilesData
ld hl, wPlaceBallsX
ld a, 10 * 8
ld a, 10 * TILE_WIDTH
ld [hli], a
ld [hl], 8 * 8
ld a, 8
ld [hl], 8 * TILE_WIDTH
ld a, TILE_WIDTH
ld [wPlaceBallsDirection], a
ld hl, wShadowOAMSprite00
call LoadTrainerHudOAM
Expand All @@ -194,9 +194,9 @@ LinkBattle_TrainerHuds:
ld de, wOTPartyCount
call StageBallTilesData
ld hl, wPlaceBallsX
ld a, 10 * 8
ld a, 10 * TILE_WIDTH
ld [hli], a
ld [hl], 13 * 8
ld [hl], 13 * TILE_WIDTH
ld hl, wShadowOAMSprite00 + PARTY_LENGTH * SPRITEOAMSTRUCT_LENGTH
jp LoadTrainerHudOAM

Expand Down
6 changes: 3 additions & 3 deletions engine/battle_anims/core.asm
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ InitBattleAnimBuffer:
add hl, bc
ld a, [hli]
ld d, a
ld a, (-10 * 8) + 4
ld a, (-10 * TILE_WIDTH) + 4
sub d
ld [wBattleAnimTempXCoord], a
ld a, [hli]
ld d, a
ld a, [wBattleAnimTempFixY]
cp $ff
jr nz, .check_kinesis_softboiled_milkdrink
ld a, 5 * 8
ld a, 5 * TILE_WIDTH
add d
jr .done

Expand All @@ -270,7 +270,7 @@ InitBattleAnimBuffer:
jr nz, .no_sub
.do_sub
pop af
sub 1 * 8
sub 1 * TILE_WIDTH
jr .done

.no_sub
Expand Down
2 changes: 1 addition & 1 deletion engine/events/field_moves.asm
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ FlyToAnim:
ld [hl], SPRITE_ANIM_SEQ_FLY_TO
ld hl, SPRITEANIMSTRUCT_VAR4
add hl, bc
ld [hl], 11 * 8
ld [hl], 11 * TILE_WIDTH
ld a, 64
ld [wFrameCounter], a
.loop
Expand Down
14 changes: 7 additions & 7 deletions engine/games/slot_machine.asm
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ Slots_InitReelTiles:
ld [hl], d
ld hl, REEL_X_COORD
add hl, bc
ld [hl], 6 * 8
ld [hl], 6 * TILE_WIDTH
call .OAM

ld bc, wReel2
Expand All @@ -699,7 +699,7 @@ Slots_InitReelTiles:
ld [hl], d
ld hl, REEL_X_COORD
add hl, bc
ld [hl], 10 * 8
ld [hl], 10 * TILE_WIDTH
call .OAM

ld bc, wReel3
Expand All @@ -717,7 +717,7 @@ Slots_InitReelTiles:
ld [hl], d
ld hl, REEL_X_COORD
add hl, bc
ld [hl], 14 * 8
ld [hl], 14 * TILE_WIDTH
call .OAM
ret

Expand Down Expand Up @@ -785,7 +785,7 @@ Slots_UpdateReelPositionAndOAM:
add hl, bc
ld a, [hl]
ld [wCurReelXCoord], a
ld a, 10 * 8
ld a, 10 * TILE_WIDTH
ld [wCurReelYCoord], a
ld hl, REEL_POSITION
add hl, bc
Expand Down Expand Up @@ -2019,7 +2019,7 @@ Slots_AnimateGolem:
jr c, .play_sound
dec [hl]
ld e, a
ld d, 14 * 8
ld d, 14 * TILE_WIDTH
farcall BattleAnim_Sine_e
ld a, e
ld hl, SPRITEANIMSTRUCT_YOFFSET
Expand All @@ -2046,7 +2046,7 @@ Slots_AnimateGolem:
ld a, [hl]
inc [hl]
inc [hl]
cp 9 * 8
cp 9 * TILE_WIDTH
jr nc, .restart
and $3
ret nz
Expand Down Expand Up @@ -2090,7 +2090,7 @@ Slots_AnimateChansey:
add hl, bc
ld a, [hl]
inc [hl]
cp 13 * 8
cp 13 * TILE_WIDTH
jr z, .limit
and $f
ret nz
Expand Down
4 changes: 2 additions & 2 deletions engine/gfx/color.asm
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ InitCGBPals::
ldh [rVBK], a
ld a, 1 << rBGPI_AUTO_INCREMENT
ldh [rBGPI], a
ld c, 4 * 8
ld c, 4 * TILE_WIDTH
.bgpals_loop
ld a, LOW(PALRGB_WHITE)
ldh [rBGPD], a
Expand All @@ -892,7 +892,7 @@ InitCGBPals::
jr nz, .bgpals_loop
ld a, 1 << rOBPI_AUTO_INCREMENT
ldh [rOBPI], a
ld c, 4 * 8
ld c, 4 * TILE_WIDTH
.obpals_loop
ld a, LOW(PALRGB_WHITE)
ldh [rOBPD], a
Expand Down
12 changes: 6 additions & 6 deletions engine/gfx/mon_icons.asm
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ Mobile_InitAnimatedMonIcon:
ld [hl], a
ld hl, SPRITEANIMSTRUCT_XCOORD
add hl, bc
ld a, 9 * 8
ld a, 9 * TILE_WIDTH
ld [hl], a
ld hl, SPRITEANIMSTRUCT_YCOORD
add hl, bc
ld a, 9 * 8
ld a, 9 * TILE_WIDTH
ld [hl], a
ret

Expand All @@ -105,11 +105,11 @@ Mobile_InitPartyMenuBGPal71:
ld [hl], a
ld hl, SPRITEANIMSTRUCT_XCOORD
add hl, bc
ld a, 3 * 8
ld a, 3 * TILE_WIDTH
ld [hl], a
ld hl, SPRITEANIMSTRUCT_YCOORD
add hl, bc
ld a, 12 * 8
ld a, 12 * TILE_WIDTH
ld [hl], a
ld a, c
ld [wc608], a
Expand Down Expand Up @@ -234,8 +234,8 @@ MoveList_InitAnimatedMonIcon:
ld [wCurIcon], a
xor a
call GetIconGFX
ld d, 3 * 8 + 2 ; depixel 3, 4, 2, 4
ld e, 4 * 8 + 4
ld d, 3 * TILE_WIDTH + 2 ; depixel 3, 4, 2, 4
ld e, 4 * TILE_WIDTH + 4
ld a, SPRITE_ANIM_INDEX_PARTY_MON
call _InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_ANIM_SEQ_ID
Expand Down
6 changes: 3 additions & 3 deletions engine/gfx/sprite_anims.asm
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ AnimSeq_SlotsChanseyEgg:
ld hl, SPRITEANIMSTRUCT_XCOORD
add hl, bc
ld a, [hl]
cp 15 * 8
cp 15 * TILE_WIDTH
jr c, .move_right
call DeinitializeSprite
ld a, $4
Expand Down Expand Up @@ -682,7 +682,7 @@ AnimSeq_FlyLeaf:
ld hl, SPRITEANIMSTRUCT_XCOORD
add hl, bc
ld a, [hl]
cp -9 * 8
cp -9 * TILE_WIDTH
jr nc, .delete_leaf
inc [hl]
inc [hl]
Expand Down Expand Up @@ -711,7 +711,7 @@ AnimSeq_FlyTo:
ld hl, SPRITEANIMSTRUCT_YCOORD
add hl, bc
ld a, [hl]
cp 10 * 8 + 4
cp 10 * TILE_WIDTH + 4
ret z

ld hl, SPRITEANIMSTRUCT_YCOORD
Expand Down
8 changes: 4 additions & 4 deletions engine/menus/intro_menu.asm
Original file line number Diff line number Diff line change
Expand Up @@ -955,10 +955,10 @@ Intro_PlacePlayerSprite:
.sprites
db 4
; y pxl, x pxl, tile offset
db 9 * 8 + 4, 9 * 8, 0
db 9 * 8 + 4, 10 * 8, 1
db 10 * 8 + 4, 9 * 8, 2
db 10 * 8 + 4, 10 * 8, 3
db 9 * TILE_WIDTH + 4, 9 * TILE_WIDTH, 0
db 9 * TILE_WIDTH + 4, 10 * TILE_WIDTH, 1
db 10 * TILE_WIDTH + 4, 9 * TILE_WIDTH, 2
db 10 * TILE_WIDTH + 4, 10 * TILE_WIDTH, 3


const_def
Expand Down
2 changes: 1 addition & 1 deletion engine/menus/naming_screen.asm
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ NamingScreenJoypadLoop:
depixel 10, 3
call NamingScreen_IsTargetBox
jr nz, .got_cursor_position
ld d, 8 * 8
ld d, 8 * TILE_WIDTH
.got_cursor_position
ld a, SPRITE_ANIM_INDEX_NAMING_SCREEN_CURSOR
call InitSpriteAnimStruct
Expand Down
6 changes: 3 additions & 3 deletions engine/overworld/map_objects.asm
Original file line number Diff line number Diff line change
Expand Up @@ -880,12 +880,12 @@ MovementFunction_Shadow:
add hl, de
ld a, [hl]
maskbits NUM_DIRECTIONS
ld d, 1 * 8 + 6
ld d, 1 * TILE_WIDTH + 6
cp DOWN
jr z, .ok
cp UP
jr z, .ok
ld d, 1 * 8 + 4
ld d, 1 * TILE_WIDTH + 4
.ok
ld hl, OBJECT_SPRITE_Y_OFFSET
add hl, bc
Expand All @@ -909,7 +909,7 @@ MovementFunction_Emote:
ld [hl], 0
ld hl, OBJECT_SPRITE_Y_OFFSET
add hl, bc
ld [hl], -2 * 8
ld [hl], -2 * TILE_WIDTH
ld hl, OBJECT_SPRITE_X_OFFSET
add hl, bc
ld [hl], 0
Expand Down
8 changes: 4 additions & 4 deletions engine/pokegear/pokegear.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2555,10 +2555,10 @@ Pokedex_GetArea:

.PlayerOAM:
; y pxl, x pxl, tile offset
db -1 * 8, -1 * 8, 0 ; top left
db -1 * 8, 0 * 8, 1 ; top right
db 0 * 8, -1 * 8, 2 ; bottom left
db 0 * 8, 0 * 8, 3 ; bottom right
db -1 * TILE_WIDTH, -1 * TILE_WIDTH, 0 ; top left
db -1 * TILE_WIDTH, 0 * TILE_WIDTH, 1 ; top right
db 0 * TILE_WIDTH, -1 * TILE_WIDTH, 2 ; bottom left
db 0 * TILE_WIDTH, 0 * TILE_WIDTH, 3 ; bottom right
db $80 ; terminator

.CheckPlayerLocation:
Expand Down
6 changes: 3 additions & 3 deletions engine/pokemon/breeding.asm
Original file line number Diff line number Diff line change
Expand Up @@ -779,9 +779,9 @@ EggHatch_CrackShell:
ret nc
swap a
srl a
add 9 * 8 + 4
add 9 * TILE_WIDTH + 4
ld d, a
ld e, 11 * 8
ld e, 11 * TILE_WIDTH
ld a, SPRITE_ANIM_INDEX_EGG_CRACK
call InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
Expand Down Expand Up @@ -838,7 +838,7 @@ Hatch_InitShellFragments:

MACRO shell_fragment
; y tile, y pxl, x tile, x pxl, frameset offset, ???
db (\1 * 8) % $100 + \2, (\3 * 8) % $100 + \4, \5 - SPRITE_ANIM_FRAMESET_EGG_HATCH_1, \6
db (\1 * TILE_WIDTH) % $100 + \2, (\3 * TILE_WIDTH) % $100 + \4, \5 - SPRITE_ANIM_FRAMESET_EGG_HATCH_1, \6
ENDM

.SpriteData:
Expand Down
4 changes: 2 additions & 2 deletions engine/pokemon/health.asm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ HealPartyMon:
ret

ComputeHPBarPixels:
; e = bc * (6 * 8) / de
; e = bc * HP_BAR_LENGTH_PX / de
ld a, b
or c
jr z, .zero
Expand All @@ -64,7 +64,7 @@ ComputeHPBarPixels:
ldh [hMultiplicand + 1], a
ld a, c
ldh [hMultiplicand + 2], a
ld a, 6 * 8
ld a, HP_BAR_LENGTH_PX
ldh [hMultiplier], a
call Multiply
; We need de to be under 256 because hDivisor is only 1 byte.
Expand Down
4 changes: 2 additions & 2 deletions macros/scripts/battle_anims.asm
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ MACRO anim_obj
else
; LEGACY: Support the tile+offset format
db \1 ; object
db (\2) * 8 + (\3) ; x_tile, x
db (\4) * 8 + (\5) ; y_tile, y
db (\2) * TILE_WIDTH + (\3) ; x_tile, x
db (\4) * TILE_WIDTH + (\5) ; y_tile, y
db \6 ; param
endc
ENDM
Expand Down
6 changes: 3 additions & 3 deletions mobile/fixed_words.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2623,12 +2623,12 @@ AnimateEZChatCursor:
ret

.nine
ld d, -13 * 8
ld d, -13 * TILE_WIDTH
ld a, SPRITE_ANIM_FRAMESET_EZCHAT_CURSOR_7
jr .eight_nine_load

.eight
ld d, 2 * 8
ld d, 2 * TILE_WIDTH
ld a, SPRITE_ANIM_FRAMESET_EZCHAT_CURSOR_6
.eight_nine_load
push de
Expand All @@ -2640,7 +2640,7 @@ AnimateEZChatCursor:
ld e, a
sla a
add e
add 8 * 8
add 8 * TILE_WIDTH
ld hl, SPRITEANIMSTRUCT_YCOORD
add hl, bc
ld [hld], a
Expand Down
8 changes: 4 additions & 4 deletions mobile/mobile_42.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1516,9 +1516,9 @@ MobileTradeAnim_AnimateSentPulse:
ld hl, SPRITEANIMSTRUCT_YCOORD
add hl, bc
ld a, [hl]
cp -1 * 8 - 6
cp -1 * TILE_WIDTH - 6
jr z, .delete
sub 1 * 8
sub 1 * TILE_WIDTH
ld [hl], a
ret

Expand All @@ -1530,9 +1530,9 @@ MobileTradeAnim_AnimateOTPulse:
ld hl, SPRITEANIMSTRUCT_YCOORD
add hl, bc
ld a, [hl]
cp 9 * 8 + 2
cp 9 * TILE_WIDTH + 2
ret z
add 1 * 8
add 1 * TILE_WIDTH
ld [hl], a
ret

Expand Down
Loading

0 comments on commit 94df3c5

Please sign in to comment.