From f275790aec4a796ed969b099364abfdf25385967 Mon Sep 17 00:00:00 2001 From: Rangi Date: Thu, 2 Jul 2020 23:30:21 -0400 Subject: Add subdirectories to engine/ similar to pokecrystal --- engine/overworld/auto_movement.asm | 292 +++++++++++++++++++++++ engine/overworld/cable_club_npc.asm | 151 ------------ engine/overworld/card_key.asm | 112 --------- engine/overworld/cinnabar_lab.asm | 123 ---------- engine/overworld/dust_smoke.asm | 93 ++++++++ engine/overworld/hidden_items.asm | 161 ------------- engine/overworld/item.asm | 54 ----- engine/overworld/map_sprite_functions1.asm | 356 ----------------------------- engine/overworld/npc_movement.asm | 292 ----------------------- engine/overworld/oaks_aide.asm | 71 ------ engine/overworld/oam.asm | 189 --------------- engine/overworld/pathfinding.asm | 201 ++++++++++++++++ engine/overworld/pewter_guys.asm | 102 --------- engine/overworld/poison.asm | 112 --------- engine/overworld/pokecenter.asm | 68 ------ engine/overworld/pokemart.asm | 272 ---------------------- engine/overworld/saffron_guards.asm | 15 -- engine/overworld/set_blackout_map.asm | 25 -- engine/overworld/special_warps.asm | 149 ++++++++++++ engine/overworld/sprite_collisions.asm | 356 +++++++++++++++++++++++++++++ engine/overworld/ssanne.asm | 93 -------- engine/overworld/tileset_header.asm | 60 ----- engine/overworld/tilesets.asm | 60 +++++ engine/overworld/trainer_sight.asm | 349 ++++++++++++++++++++++++++++ engine/overworld/trainers.asm | 349 ---------------------------- engine/overworld/turn_sprite.asm | 25 ++ 26 files changed, 1525 insertions(+), 2605 deletions(-) create mode 100755 engine/overworld/auto_movement.asm delete mode 100755 engine/overworld/cable_club_npc.asm delete mode 100755 engine/overworld/card_key.asm delete mode 100755 engine/overworld/cinnabar_lab.asm create mode 100755 engine/overworld/dust_smoke.asm delete mode 100755 engine/overworld/hidden_items.asm delete mode 100644 engine/overworld/item.asm delete mode 100644 engine/overworld/map_sprite_functions1.asm delete mode 100755 engine/overworld/npc_movement.asm delete mode 100755 engine/overworld/oaks_aide.asm delete mode 100644 engine/overworld/oam.asm create mode 100644 engine/overworld/pathfinding.asm delete mode 100755 engine/overworld/pewter_guys.asm delete mode 100644 engine/overworld/poison.asm delete mode 100755 engine/overworld/pokecenter.asm delete mode 100755 engine/overworld/pokemart.asm delete mode 100755 engine/overworld/saffron_guards.asm delete mode 100644 engine/overworld/set_blackout_map.asm create mode 100644 engine/overworld/special_warps.asm create mode 100644 engine/overworld/sprite_collisions.asm delete mode 100755 engine/overworld/ssanne.asm delete mode 100644 engine/overworld/tileset_header.asm create mode 100644 engine/overworld/tilesets.asm create mode 100755 engine/overworld/trainer_sight.asm delete mode 100755 engine/overworld/trainers.asm create mode 100755 engine/overworld/turn_sprite.asm (limited to 'engine/overworld') diff --git a/engine/overworld/auto_movement.asm b/engine/overworld/auto_movement.asm new file mode 100755 index 00000000..e478c9ad --- /dev/null +++ b/engine/overworld/auto_movement.asm @@ -0,0 +1,292 @@ +PlayerStepOutFromDoor:: + ld hl, wd730 + res 1, [hl] + call IsPlayerStandingOnDoorTile + jr nc, .notStandingOnDoor + ld a, $fc + ld [wJoyIgnore], a + ld hl, wd736 + set 1, [hl] + ld a, $1 + ld [wSimulatedJoypadStatesIndex], a + ld a, D_DOWN + ld [wSimulatedJoypadStatesEnd], a + xor a + ld [wSpriteStateData1 + 2], a + call StartSimulatingJoypadStates + ret +.notStandingOnDoor + xor a + ld [wWastedByteCD3A], a + ld [wSimulatedJoypadStatesIndex], a + ld [wSimulatedJoypadStatesEnd], a + ld hl, wd736 + res 0, [hl] + res 1, [hl] + ld hl, wd730 + res 7, [hl] + ret + +_EndNPCMovementScript:: + ld hl, wd730 + res 7, [hl] + ld hl, wd72e + res 7, [hl] + ld hl, wd736 + res 0, [hl] + res 1, [hl] + xor a + ld [wNPCMovementScriptSpriteOffset], a + ld [wNPCMovementScriptPointerTableNum], a + ld [wNPCMovementScriptFunctionNum], a + ld [wWastedByteCD3A], a + ld [wSimulatedJoypadStatesIndex], a + ld [wSimulatedJoypadStatesEnd], a + ret + +PalletMovementScriptPointerTable:: + dw PalletMovementScript_OakMoveLeft + dw PalletMovementScript_PlayerMoveLeft + dw PalletMovementScript_WaitAndWalkToLab + dw PalletMovementScript_WalkToLab + dw PalletMovementScript_Done + +PalletMovementScript_OakMoveLeft: + ld a, [wXCoord] + sub $a + ld [wNumStepsToTake], a + jr z, .playerOnLeftTile +; The player is on the right tile of the northern path out of Pallet Town and +; Prof. Oak is below. +; Make Prof. Oak step to the left. + ld b, 0 + ld c, a + ld hl, wNPCMovementDirections2 + ld a, NPC_MOVEMENT_LEFT + call FillMemory + ld [hl], $ff + ld a, [wSpriteIndex] + ld [H_SPRITEINDEX], a + ld de, wNPCMovementDirections2 + call MoveSprite + ld a, $1 + ld [wNPCMovementScriptFunctionNum], a + jr .done +; The player is on the left tile of the northern path out of Pallet Town and +; Prof. Oak is below. +; Prof. Oak is already where he needs to be. +.playerOnLeftTile + ld a, $3 + ld [wNPCMovementScriptFunctionNum], a +.done + ld hl, wFlags_D733 + set 1, [hl] + ld a, $fc + ld [wJoyIgnore], a + ret + +PalletMovementScript_PlayerMoveLeft: + ld a, [wd730] + bit 0, a ; is an NPC being moved by a script? + ret nz ; return if Oak is still moving + ld a, [wNumStepsToTake] + ld [wSimulatedJoypadStatesIndex], a + ld [hNPCMovementDirections2Index], a + predef ConvertNPCMovementDirectionsToJoypadMasks + call StartSimulatingJoypadStates + ld a, $2 + ld [wNPCMovementScriptFunctionNum], a + ret + +PalletMovementScript_WaitAndWalkToLab: + ld a, [wSimulatedJoypadStatesIndex] + and a ; is the player done moving left yet? + ret nz + +PalletMovementScript_WalkToLab: + xor a + ld [wOverrideSimulatedJoypadStatesMask], a + ld a, [wSpriteIndex] + swap a + ld [wNPCMovementScriptSpriteOffset], a + xor a + ld [wSpriteStateData2 + $06], a + ld hl, wSimulatedJoypadStatesEnd + ld de, RLEList_PlayerWalkToLab + call DecodeRLEList + dec a + ld [wSimulatedJoypadStatesIndex], a + ld hl, wNPCMovementDirections2 + ld de, RLEList_ProfOakWalkToLab + call DecodeRLEList + ld hl, wd72e + res 7, [hl] + ld hl, wd730 + set 7, [hl] + ld a, $4 + ld [wNPCMovementScriptFunctionNum], a + ret + +RLEList_ProfOakWalkToLab: + db NPC_MOVEMENT_DOWN, $05 + db NPC_MOVEMENT_LEFT, $01 + db NPC_MOVEMENT_DOWN, $05 + db NPC_MOVEMENT_RIGHT, $03 + db NPC_MOVEMENT_UP, $01 + db $E0, $01 ; stand still + db $FF + +RLEList_PlayerWalkToLab: + db D_UP, $02 + db D_RIGHT, $03 + db D_DOWN, $05 + db D_LEFT, $01 + db D_DOWN, $06 + db $FF + +PalletMovementScript_Done: + ld a, [wSimulatedJoypadStatesIndex] + and a + ret nz + ld a, HS_PALLET_TOWN_OAK + ld [wMissableObjectIndex], a + predef HideObject + ld hl, wd730 + res 7, [hl] + ld hl, wd72e + res 7, [hl] + jp EndNPCMovementScript + +PewterMuseumGuyMovementScriptPointerTable:: + dw PewterMovementScript_WalkToMuseum + dw PewterMovementScript_Done + +PewterMovementScript_WalkToMuseum: + ld a, BANK(Music_MuseumGuy) + ld [wAudioROMBank], a + ld [wAudioSavedROMBank], a + ld a, MUSIC_MUSEUM_GUY + ld [wNewSoundID], a + call PlaySound + ld a, [wSpriteIndex] + swap a + ld [wNPCMovementScriptSpriteOffset], a + call StartSimulatingJoypadStates + ld hl, wSimulatedJoypadStatesEnd + ld de, RLEList_PewterMuseumPlayer + call DecodeRLEList + dec a + ld [wSimulatedJoypadStatesIndex], a + xor a + ld [wWhichPewterGuy], a + predef PewterGuys + ld hl, wNPCMovementDirections2 + ld de, RLEList_PewterMuseumGuy + call DecodeRLEList + ld hl, wd72e + res 7, [hl] + ld a, $1 + ld [wNPCMovementScriptFunctionNum], a + ret + +RLEList_PewterMuseumPlayer: + db 0, $01 + db D_UP, $03 + db D_LEFT, $0D + db D_UP, $06 + db $FF + +RLEList_PewterMuseumGuy: + db NPC_MOVEMENT_UP, $06 + db NPC_MOVEMENT_LEFT, $0D + db NPC_MOVEMENT_UP, $03 + db NPC_MOVEMENT_LEFT, $01 + db $FF + +PewterMovementScript_Done: + ld a, [wSimulatedJoypadStatesIndex] + and a + ret nz + ld hl, wd730 + res 7, [hl] + ld hl, wd72e + res 7, [hl] + jp EndNPCMovementScript + +PewterGymGuyMovementScriptPointerTable:: + dw PewterMovementScript_WalkToGym + dw PewterMovementScript_Done + +PewterMovementScript_WalkToGym: + ld a, BANK(Music_MuseumGuy) + ld [wAudioROMBank], a + ld [wAudioSavedROMBank], a + ld a, MUSIC_MUSEUM_GUY + ld [wNewSoundID], a + call PlaySound + ld a, [wSpriteIndex] + swap a + ld [wNPCMovementScriptSpriteOffset], a + xor a + ld [wSpriteStateData2 + $06], a + ld hl, wSimulatedJoypadStatesEnd + ld de, RLEList_PewterGymPlayer + call DecodeRLEList + dec a + ld [wSimulatedJoypadStatesIndex], a + ld a, 1 + ld [wWhichPewterGuy], a + predef PewterGuys + ld hl, wNPCMovementDirections2 + ld de, RLEList_PewterGymGuy + call DecodeRLEList + ld hl, wd72e + res 7, [hl] + ld hl, wd730 + set 7, [hl] + ld a, $1 + ld [wNPCMovementScriptFunctionNum], a + ret + +RLEList_PewterGymPlayer: + db 0, $01 + db D_RIGHT, $02 + db D_DOWN, $05 + db D_LEFT, $0B + db D_UP, $05 + db D_LEFT, $0F + db $FF + +RLEList_PewterGymGuy: + db NPC_MOVEMENT_DOWN, $02 + db NPC_MOVEMENT_LEFT, $0F + db NPC_MOVEMENT_UP, $05 + db NPC_MOVEMENT_LEFT, $0B + db NPC_MOVEMENT_DOWN, $05 + db NPC_MOVEMENT_RIGHT, $03 + db $FF + +FreezeEnemyTrainerSprite:: + ld a, [wCurMap] + cp POKEMON_TOWER_7F + ret z ; the Rockets on Pokemon Tower 7F leave after battling, so don't freeze them + ld hl, RivalIDs + ld a, [wEngagedTrainerClass] + ld b, a +.loop + ld a, [hli] + cp $ff + jr z, .notRival + cp b + ret z ; the rival leaves after battling, so don't freeze him + jr .loop +.notRival + ld a, [wSpriteIndex] + ld [H_SPRITEINDEX], a + jp SetSpriteMovementBytesToFF + +RivalIDs: + db OPP_SONY1 + db OPP_SONY2 + db OPP_SONY3 + db $ff diff --git a/engine/overworld/cable_club_npc.asm b/engine/overworld/cable_club_npc.asm deleted file mode 100755 index bb0f7680..00000000 --- a/engine/overworld/cable_club_npc.asm +++ /dev/null @@ -1,151 +0,0 @@ -CableClubNPC:: - ld hl, CableClubNPCWelcomeText - call PrintText - CheckEvent EVENT_GOT_POKEDEX - jp nz, .receivedPokedex -; if the player hasn't received the pokedex - ld c, 60 - call DelayFrames - ld hl, CableClubNPCMakingPreparationsText - call PrintText - jp .didNotConnect -.receivedPokedex - ld a, $1 - ld [wMenuJoypadPollCount], a - ld a, 90 - ld [wLinkTimeoutCounter], a -.establishConnectionLoop - ld a, [hSerialConnectionStatus] - cp USING_INTERNAL_CLOCK - jr z, .establishedConnection - cp USING_EXTERNAL_CLOCK - jr z, .establishedConnection - ld a, CONNECTION_NOT_ESTABLISHED - ld [hSerialConnectionStatus], a - ld a, ESTABLISH_CONNECTION_WITH_EXTERNAL_CLOCK - ld [rSB], a - xor a - ld [hSerialReceiveData], a - ld a, START_TRANSFER_EXTERNAL_CLOCK - ld [rSC], a - ld a, [wLinkTimeoutCounter] - dec a - ld [wLinkTimeoutCounter], a - jr z, .failedToEstablishConnection - ld a, ESTABLISH_CONNECTION_WITH_INTERNAL_CLOCK - ld [rSB], a - ld a, START_TRANSFER_INTERNAL_CLOCK - ld [rSC], a - call DelayFrame - jr .establishConnectionLoop -.establishedConnection - call Serial_SendZeroByte - call DelayFrame - call Serial_SendZeroByte - ld c, 50 - call DelayFrames - ld hl, CableClubNPCPleaseApplyHereHaveToSaveText - call PrintText - xor a - ld [wMenuJoypadPollCount], a - call YesNoChoice - ld a, $1 - ld [wMenuJoypadPollCount], a - ld a, [wCurrentMenuItem] - and a - jr nz, .choseNo - callab SaveSAVtoSRAM - call WaitForSoundToFinish - ld a, SFX_SAVE - call PlaySoundWaitForCurrent - ld hl, CableClubNPCPleaseWaitText - call PrintText - ld hl, wUnknownSerialCounter - ld a, $3 - ld [hli], a - xor a - ld [hl], a - ld [hSerialReceivedNewData], a - ld [wSerialExchangeNybbleSendData], a - call Serial_SyncAndExchangeNybble - ld hl, wUnknownSerialCounter - ld a, [hli] - inc a - jr nz, .connected - ld a, [hl] - inc a - jr nz, .connected - ld b, 10 -.syncLoop - call DelayFrame - call Serial_SendZeroByte - dec b - jr nz, .syncLoop - call CloseLinkConnection - ld hl, CableClubNPCLinkClosedBecauseOfInactivityText - call PrintText - jr .didNotConnect -.failedToEstablishConnection - ld hl, CableClubNPCAreaReservedFor2FriendsLinkedByCableText - call PrintText - jr .didNotConnect -.choseNo - call CloseLinkConnection - ld hl, CableClubNPCPleaseComeAgainText - call PrintText -.didNotConnect - xor a - ld hl, wUnknownSerialCounter - ld [hli], a - ld [hl], a - ld hl, wd72e - res 6, [hl] - xor a - ld [wMenuJoypadPollCount], a - ret -.connected - xor a - ld [hld], a - ld [hl], a - jpab LinkMenu - -CableClubNPCAreaReservedFor2FriendsLinkedByCableText: - TX_FAR _CableClubNPCAreaReservedFor2FriendsLinkedByCableText - db "@" - -CableClubNPCWelcomeText: - TX_FAR _CableClubNPCWelcomeText - db "@" - -CableClubNPCPleaseApplyHereHaveToSaveText: - TX_FAR _CableClubNPCPleaseApplyHereHaveToSaveText - db "@" - -CableClubNPCPleaseWaitText: - TX_FAR _CableClubNPCPleaseWaitText - TX_DELAY - db "@" - -CableClubNPCLinkClosedBecauseOfInactivityText: - TX_FAR _CableClubNPCLinkClosedBecauseOfInactivityText - db "@" - -CableClubNPCPleaseComeAgainText: - TX_FAR _CableClubNPCPleaseComeAgainText - db "@" - -CableClubNPCMakingPreparationsText: - TX_FAR _CableClubNPCMakingPreparationsText - db "@" - -CloseLinkConnection: - call Delay3 - ld a, CONNECTION_NOT_ESTABLISHED - ld [hSerialConnectionStatus], a - ld a, ESTABLISH_CONNECTION_WITH_EXTERNAL_CLOCK - ld [rSB], a - xor a - ld [hSerialReceiveData], a - ld a, START_TRANSFER_EXTERNAL_CLOCK - ld [rSC], a - ret diff --git a/engine/overworld/card_key.asm b/engine/overworld/card_key.asm deleted file mode 100755 index c77d5fcd..00000000 --- a/engine/overworld/card_key.asm +++ /dev/null @@ -1,112 +0,0 @@ -PrintCardKeyText: - ld hl, SilphCoMapList - ld a, [wCurMap] - ld b, a -.silphCoMapListLoop - ld a, [hli] - cp $ff - ret z - cp b - jr nz, .silphCoMapListLoop - predef GetTileAndCoordsInFrontOfPlayer - ld a, [wTileInFrontOfPlayer] - cp $18 - jr z, .cardKeyDoorInFrontOfPlayer - cp $24 - jr z, .cardKeyDoorInFrontOfPlayer - ld b, a - ld a, [wCurMap] - cp SILPH_CO_11F - ret nz - ld a, b - cp $5e - ret nz -.cardKeyDoorInFrontOfPlayer - ld b, CARD_KEY - call IsItemInBag - jr z, .noCardKey - call GetCoordsInFrontOfPlayer - push de - tx_pre_id CardKeySuccessText - ld [hSpriteIndexOrTextID], a - call PrintPredefTextID - pop de - srl d - ld a, d - ld b, a - ld [wCardKeyDoorY], a - srl e - ld a, e - ld c, a - ld [wCardKeyDoorX], a - ld a, [wCurMap] - cp SILPH_CO_11F - jr nz, .notSilphCo11F - ld a, $3 - jr .replaceCardKeyDoorTileBlock -.notSilphCo11F - ld a, $e -.replaceCardKeyDoorTileBlock - ld [wNewTileBlockID], a - predef ReplaceTileBlock - ld hl, wCurrentMapScriptFlags - set 5, [hl] - ld a, SFX_GO_INSIDE - jp PlaySound -.noCardKey - tx_pre_id CardKeyFailText - ld [hSpriteIndexOrTextID], a - jp PrintPredefTextID - -SilphCoMapList: - db SILPH_CO_2F - db SILPH_CO_3F - db SILPH_CO_4F - db SILPH_CO_5F - db SILPH_CO_6F - db SILPH_CO_7F - db SILPH_CO_8F - db SILPH_CO_9F - db SILPH_CO_10F - db SILPH_CO_11F - db $FF - -CardKeySuccessText:: - TX_FAR _CardKeySuccessText1 - TX_SFX_ITEM_1 - TX_FAR _CardKeySuccessText2 - db "@" - -CardKeyFailText:: - TX_FAR _CardKeyFailText - db "@" - -; d = Y -; e = X -GetCoordsInFrontOfPlayer: - ld a, [wYCoord] - ld d, a - ld a, [wXCoord] - ld e, a - ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction - and a - jr nz, .notFacingDown -; facing down - inc d - ret -.notFacingDown - cp SPRITE_FACING_UP - jr nz, .notFacingUp -; facing up - dec d - ret -.notFacingUp - cp SPRITE_FACING_LEFT - jr nz, .notFacingLeft -; facing left - dec e - ret -.notFacingLeft -; facing right - inc e - ret diff --git a/engine/overworld/cinnabar_lab.asm b/engine/overworld/cinnabar_lab.asm deleted file mode 100755 index e642840d..00000000 --- a/engine/overworld/cinnabar_lab.asm +++ /dev/null @@ -1,123 +0,0 @@ -GiveFossilToCinnabarLab:: - ld hl, wd730 - set 6, [hl] - xor a - ld [wCurrentMenuItem], a - ld a, A_BUTTON | B_BUTTON - ld [wMenuWatchedKeys], a - ld a, [wFilteredBagItemsCount] - dec a - ld [wMaxMenuItem], a - ld a, 2 - ld [wTopMenuItemY], a - ld a, 1 - ld [wTopMenuItemX], a - ld a, [wFilteredBagItemsCount] - dec a - ld bc, 2 - ld hl, 3 - call AddNTimes - dec l - ld b, l - ld c, $d - coord hl, 0, 0 - call TextBoxBorder - call UpdateSprites - call PrintFossilsInBag - ld hl, wd730 - res 6, [hl] - call HandleMenuInput - bit 1, a ; pressed B? - jr nz, .cancelledGivingFossil - ld hl, wFilteredBagItems - ld a, [wCurrentMenuItem] - ld d, 0 - ld e, a - add hl, de - ld a, [hl] - ld [$ffdb], a - cp DOME_FOSSIL - jr z, .choseDomeFossil - cp HELIX_FOSSIL - jr z, .choseHelixFossil - ld b, AERODACTYL - jr .fossilSelected -.choseHelixFossil - ld b, OMANYTE - jr .fossilSelected -.choseDomeFossil - ld b, KABUTO -.fossilSelected - ld [wFossilItem], a - ld a, b - ld [wFossilMon], a - call LoadFossilItemAndMonName - ld hl, LabFossil_610ae - call PrintText - call YesNoChoice - ld a, [wCurrentMenuItem] - and a - jr nz, .cancelledGivingFossil - ld hl, LabFossil_610b3 - call PrintText - ld a, [wFossilItem] - ld [hItemToRemoveID], a - callba RemoveItemByID - ld hl, LabFossil_610b8 - call PrintText - SetEvents EVENT_GAVE_FOSSIL_TO_LAB, EVENT_LAB_STILL_REVIVING_FOSSIL - ret -.cancelledGivingFossil - ld hl, LabFossil_610bd - call PrintText - ret - -LabFossil_610ae: - TX_FAR _Lab4Text_610ae - db "@" - -LabFossil_610b3: - TX_FAR _Lab4Text_610b3 - db "@" - -LabFossil_610b8: - TX_FAR _Lab4Text_610b8 - db "@" - -LabFossil_610bd: - TX_FAR _Lab4Text_610bd - db "@" - -PrintFossilsInBag: -; Prints each fossil in the player's bag on a separate line in the menu. - ld hl, wFilteredBagItems - xor a - ld [hItemCounter], a -.loop - ld a, [hli] - cp $ff - ret z - push hl - ld [wd11e], a - call GetItemName - coord hl, 2, 2 - ld a, [hItemCounter] - ld bc, SCREEN_WIDTH * 2 - call AddNTimes - ld de, wcd6d - call PlaceString - ld hl, hItemCounter - inc [hl] - pop hl - jr .loop - -; loads the names of the fossil item and the resulting mon -LoadFossilItemAndMonName:: - ld a, [wFossilMon] - ld [wd11e], a - call GetMonName - call CopyStringToCF4B - ld a, [wFossilItem] - ld [wd11e], a - call GetItemName - ret diff --git a/engine/overworld/dust_smoke.asm b/engine/overworld/dust_smoke.asm new file mode 100755 index 00000000..6c26b712 --- /dev/null +++ b/engine/overworld/dust_smoke.asm @@ -0,0 +1,93 @@ +AnimateBoulderDust: + ld a, $1 + ld [wWhichAnimationOffsets], a ; select the boulder dust offsets + ld a, [wUpdateSpritesEnabled] + push af + ld a, $ff + ld [wUpdateSpritesEnabled], a + ld a, %11100100 + ld [rOBP1], a + call LoadSmokeTileFourTimes + callba WriteCutOrBoulderDustAnimationOAMBlock + ld c, 8 ; number of steps in animation +.loop + push bc + call GetMoveBoulderDustFunctionPointer + ld bc, .returnAddress + push bc + ld c, 4 + jp hl +.returnAddress + ld a, [rOBP1] + xor %01100100 + ld [rOBP1], a + call Delay3 + pop bc + dec c + jr nz, .loop + pop af + ld [wUpdateSpritesEnabled], a + jp LoadPlayerSpriteGraphics + +GetMoveBoulderDustFunctionPointer: + ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction + ld hl, MoveBoulderDustFunctionPointerTable + ld c, a + ld b, $0 + add hl, bc + ld a, [hli] + ld [wCoordAdjustmentAmount], a + ld a, [hli] + ld e, a + ld a, [hli] + ld h, [hl] + ld l, a + push hl + ld hl, wOAMBuffer + $90 + ld d, $0 + add hl, de + ld e, l + ld d, h + pop hl + ret + +MoveBoulderDustFunctionPointerTable: +; facing down + db $FF,$00 + dw AdjustOAMBlockYPos + +; facing up + db $01,$00 + dw AdjustOAMBlockYPos + +; facing left + db $01,$01 + dw AdjustOAMBlockXPos + +; facing right + db $FF,$01 + dw AdjustOAMBlockXPos + +LoadSmokeTileFourTimes:: + ld hl, vChars1 + $7c0 + ld c, $4 +.loop + push bc + push hl + call LoadSmokeTile + pop hl + ld bc, $10 + add hl, bc + pop bc + dec c + jr nz, .loop + ret + +LoadSmokeTile: + ld de, SSAnneSmokePuffTile + lb bc, BANK(SSAnneSmokePuffTile), (SSAnneSmokePuffTileEnd - SSAnneSmokePuffTile) / $10 + jp CopyVideoData + +SSAnneSmokePuffTile: + INCBIN "gfx/overworld/smoke.2bpp" +SSAnneSmokePuffTileEnd: diff --git a/engine/overworld/hidden_items.asm b/engine/overworld/hidden_items.asm deleted file mode 100755 index e40b0ac7..00000000 --- a/engine/overworld/hidden_items.asm +++ /dev/null @@ -1,161 +0,0 @@ -HiddenItems: - ld hl, HiddenItemCoords - call FindHiddenItemOrCoinsIndex - ld [wHiddenItemOrCoinsIndex], a - ld hl, wObtainedHiddenItemsFlags - ld a, [wHiddenItemOrCoinsIndex] - ld c, a - ld b, FLAG_TEST - predef FlagActionPredef - ld a, c - and a - ret nz - call EnableAutoTextBoxDrawing - ld a, 1 - ld [wDoNotWaitForButtonPressAfterDisplayingText], a - ld a, [wHiddenObjectFunctionArgument] ; item ID - ld [wd11e], a - call GetItemName - tx_pre_jump FoundHiddenItemText - -INCLUDE "data/hidden_item_coords.asm" - -FoundHiddenItemText:: - TX_FAR _FoundHiddenItemText - TX_ASM - ld a, [wHiddenObjectFunctionArgument] ; item ID - ld b, a - ld c, 1 - call GiveItem - jr nc, .bagFull - ld hl, wObtainedHiddenItemsFlags - ld a, [wHiddenItemOrCoinsIndex] - ld c, a - ld b, FLAG_SET - predef FlagActionPredef - ld a, SFX_GET_ITEM_2 - call PlaySoundWaitForCurrent - call WaitForSoundToFinish - jp TextScriptEnd -.bagFull - call WaitForTextScrollButtonPress ; wait for button press - xor a - ld [wDoNotWaitForButtonPressAfterDisplayingText], a - ld hl, HiddenItemBagFullText - call PrintText - jp TextScriptEnd - -HiddenItemBagFullText:: - TX_FAR _HiddenItemBagFullText - db "@" - -HiddenCoins: - ld b, COIN_CASE - predef GetQuantityOfItemInBag - ld a, b - and a - ret z - ld hl, HiddenCoinCoords - call FindHiddenItemOrCoinsIndex - ld [wHiddenItemOrCoinsIndex], a - ld hl, wObtainedHiddenCoinsFlags - ld a, [wHiddenItemOrCoinsIndex] - ld c, a - ld b, FLAG_TEST - predef FlagActionPredef - ld a, c - and a - ret nz - xor a - ld [hUnusedCoinsByte], a - ld [hCoins], a - ld [hCoins + 1], a - ld a, [wHiddenObjectFunctionArgument] - sub COIN - cp 10 - jr z, .bcd10 - cp 20 - jr z, .bcd20 - cp 40 - jr z, .bcd20 ; should be bcd40 - jr .bcd100 -.bcd10 - ld a, $10 - ld [hCoins + 1], a - jr .bcdDone -.bcd20 - ld a, $20 - ld [hCoins + 1], a - jr .bcdDone -.bcd40 ; due to a typo, this is never used - ld a, $40 - ld [hCoins + 1], a - jr .bcdDone -.bcd100 - ld a, $1 - ld [hCoins], a -.bcdDone - ld de, wPlayerCoins + 1 - ld hl, hCoins + 1 - ld c, $2 - predef AddBCDPredef - ld hl, wObtainedHiddenCoinsFlags - ld a, [wHiddenItemOrCoinsIndex] - ld c, a - ld b, FLAG_SET - predef FlagActionPredef - call EnableAutoTextBoxDrawing - ld a, [wPlayerCoins] - cp $99 - jr nz, .roomInCoinCase - ld a, [wPlayerCoins + 1] - cp $99 - jr nz, .roomInCoinCase - tx_pre_id DroppedHiddenCoinsText - jr .done -.roomInCoinCase - tx_pre_id FoundHiddenCoinsText -.done - jp PrintPredefTextID - -INCLUDE "data/hidden_coins.asm" - -FoundHiddenCoinsText:: - TX_FAR _FoundHiddenCoinsText - TX_SFX_ITEM_2 - db "@" - -DroppedHiddenCoinsText:: - TX_FAR _FoundHiddenCoins2Text - TX_SFX_ITEM_2 - TX_FAR _DroppedHiddenCoinsText - db "@" - -FindHiddenItemOrCoinsIndex: - ld a, [wHiddenObjectY] - ld d, a - ld a, [wHiddenObjectX] - ld e, a - ld a, [wCurMap] - ld b, a - ld c, -1 -.loop - inc c - ld a, [hli] - cp $ff ; end of the list? - ret z ; if so, we're done here - cp b - jr nz, .next1 - ld a, [hli] - cp d - jr nz, .next2 - ld a, [hli] - cp e - jr nz, .loop - ld a, c - ret -.next1 - inc hl -.next2 - inc hl - jr .loop diff --git a/engine/overworld/item.asm b/engine/overworld/item.asm deleted file mode 100644 index 9f19100a..00000000 --- a/engine/overworld/item.asm +++ /dev/null @@ -1,54 +0,0 @@ -PickUpItem: - call EnableAutoTextBoxDrawing - - ld a, [hSpriteIndexOrTextID] - ld b, a - ld hl, wMissableObjectList -.missableObjectsListLoop - ld a, [hli] - cp $ff - ret z - cp b - jr z, .isMissable - inc hl - jr .missableObjectsListLoop - -.isMissable - ld a, [hl] - ld [$ffdb], a - - ld hl, wMapSpriteExtraData - ld a, [hSpriteIndexOrTextID] - dec a - add a - ld d, 0 - ld e, a - add hl, de - ld a, [hl] - ld b, a ; item - ld c, 1 ; quantity - call GiveItem - jr nc, .BagFull - - ld a, [$ffdb] - ld [wMissableObjectIndex], a - predef HideObject - ld a, 1 - ld [wDoNotWaitForButtonPressAfterDisplayingText], a - ld hl, FoundItemText - jr .print - -.BagFull - ld hl, NoMoreRoomForItemText -.print - call PrintText - ret - -FoundItemText: - TX_FAR _FoundItemText - TX_SFX_ITEM_1 - db "@" - -NoMoreRoomForItemText: - TX_FAR _NoMoreRoomForItemText - db "@" diff --git a/engine/overworld/map_sprite_functions1.asm b/engine/overworld/map_sprite_functions1.asm deleted file mode 100644 index 0e6b2d06..00000000 --- a/engine/overworld/map_sprite_functions1.asm +++ /dev/null @@ -1,356 +0,0 @@ -_UpdateSprites:: - ld h, $c1 - inc h - ld a, $e ; wSpriteStateData2 + $0e -.spriteLoop - ld l, a - sub $e - ld c, a - ld [H_CURRENTSPRITEOFFSET], a - ld a, [hl] - and a - jr z, .skipSprite ; tests $c2Xe - push hl - push de - push bc - call .updateCurrentSprite - pop bc - pop de - pop hl -.skipSprite - ld a, l - add $10 ; move to next sprite - cp $e ; test for overflow (back at $0e) - jr nz, .spriteLoop - ret -.updateCurrentSprite - cp $1 - jp nz, UpdateNonPlayerSprite - jp UpdatePlayerSprite - -UpdateNonPlayerSprite: - dec a - swap a - ld [$ff93], a ; $10 * sprite# - ld a, [wNPCMovementScriptSpriteOffset] ; some sprite offset? - ld b, a - ld a, [H_CURRENTSPRITEOFFSET] - cp b - jr nz, .unequal - jp DoScriptedNPCMovement -.unequal - jp UpdateNPCSprite - -; This detects if the current sprite (whose offset is at H_CURRENTSPRITEOFFSET) -; is going to collide with another sprite by looping over the other sprites. -; The current sprite's offset will be labelled with i (e.g. $c1i0). -; The loop sprite's offset will labelled with j (e.g. $c1j0). -; -; Note that the Y coordinate of the sprite (in [$c1k4]) is one of the following -; 9 values when the sprite is aligned with the grid: $fc, $0c, $1c, $2c, ..., $7c. -; The reason that 4 is added below to the coordinate is to make it align with a -; multiple of $10 to make comparisons easier. -DetectCollisionBetweenSprites: - nop - - ld h, wSpriteStateData1 / $100 - ld a, [H_CURRENTSPRITEOFFSET] - add wSpriteStateData1 % $100 - ld l, a - - ld a, [hl] ; a = [$c1i0] (picture) (0 if slot is unused) - and a ; is this sprite slot slot used? - ret z ; return if not used - - ld a, l - add 3 - ld l, a - - ld a, [hli] ; a = [$c1i3] (delta Y) (-1, 0, or 1) - call SetSpriteCollisionValues - - ld a, [hli] ; a = [$C1i4] (Y screen coordinate) - add 4 ; align with multiple of $10 - -; The effect of the following 3 lines is to -; add 7 to a if moving south or -; subtract 7 from a if moving north. - add b - and $f0 - or c - - ld [$ff90], a ; store Y coordinate adjusted for direction of movement - - ld a, [hli] ; a = [$c1i5] (delta X) (-1, 0, or 1) - call SetSpriteCollisionValues - ld a, [hl] ; a = [$C1i6] (X screen coordinate) - -; The effect of the following 3 lines is to -; add 7 to a if moving east or -; subtract 7 from a if moving west. - add b - and $f0 - or c - - ld [$ff91], a ; store X coordinate adjusted for direction of movement - - ld a, l - add 7 - ld l, a - - xor a - ld [hld], a ; zero [$c1id] XXX what's [$c1id] for? - ld [hld], a ; zero [$c1ic] (directions in which collisions occurred) - - ld a, [$ff91] - ld [hld], a ; [$c1ib] = adjusted X coordinate - ld a, [$ff90] - ld [hl], a ; [$c1ia] = adjusted Y coordinate - - xor a ; zero the loop counter - -.loop - ld [$ff8f], a ; store loop counter - swap a - ld e, a - ld a, [H_CURRENTSPRITEOFFSET] - cp e ; does the loop sprite match the current sprite? - jp z, .next ; go to the next sprite if they match - - ld d, h - ld a, [de] ; a = [$c1j0] (picture) (0 if slot is unused) - and a ; is this sprite slot slot used? - jp z, .next ; go the next sprite if not used - - inc e - inc e - ld a, [de] ; a = [$c1j2] ($ff means the sprite is offscreen) - inc a - jp z, .next ; go the next sprite if offscreen - - ld a, [H_CURRENTSPRITEOFFSET] - add 10 - ld l, a - - inc e - ld a, [de] ; a = [$c1j3] (delta Y) - call SetSpriteCollisionValues - - inc e - ld a, [de] ; a = [$C1j4] (Y screen coordinate) - add 4 ; align with multiple of $10 - -; The effect of the following 3 lines is to -; add 7 to a if moving south or -; subtract 7 from a if moving north. - add b - and $f0 - or c - - sub [hl] ; subtract the adjusted Y coordinate of sprite i ([$c1ia]) from that of sprite j - -; calculate the absolute value of the difference to get the distance - jr nc, .noCarry1 - cpl - inc a -.noCarry1 - ld [$ff90], a ; store the distance between the two sprites' adjusted Y values - -; Use the carry flag set by the above subtraction to determine which sprite's -; Y coordinate is larger. This information is used later to set [$c1ic], -; which stores which direction the collision occurred in. -; The following 5 lines set the lowest 2 bits of c, which are later shifted left by 2. -; If sprite i's Y is larger, set lowest 2 bits of c to 10. -; If sprite j's Y is larger or both are equal, set lowest 2 bits of c to 01. - push af - rl c - pop af - ccf - rl c - -; If sprite i's delta Y is 0, then b = 7, else b = 9. - ld b, 7 - ld a, [hl] ; a = [$c1ia] (adjusted Y coordinate) - and $f - jr z, .next1 - ld b, 9 - -.next1 - ld a, [$ff90] ; a = distance between adjusted Y coordinates - sub b - ld [$ff92], a ; store distance adjusted using sprite i's direction - ld a, b - ld [$ff90], a ; store 7 or 9 depending on sprite i's delta Y - jr c, .checkXDistance - -; If sprite j's delta Y is 0, then b = 7, else b = 9. - ld b, 7 - dec e - ld a, [de] ; a = [$c1j3] (delta Y) - inc e - and a - jr z, .next2 - ld b, 9 - -.next2 - ld a, [$ff92] ; a = distance adjusted using sprite i's direction - sub b ; adjust distance using sprite j's direction - jr z, .checkXDistance - jr nc, .next ; go to next sprite if distance is still positive after both adjustments - -.checkXDistance - inc e - inc l - ld a, [de] ; a = [$c1j5] (delta X) - - push bc - - call SetSpriteCollisionValues - inc e - ld a, [de] ; a = [$c1j6] (X screen coordinate) - -; The effect of the following 3 lines is to -; add 7 to a if moving east or -; subtract 7 from a if moving west. - add b - and $f0 - or c - - pop bc - - sub [hl] ; subtract the adjusted X coordinate of sprite i ([$c1ib]) from that of sprite j - -; calculate the absolute value of the difference to get the distance - jr nc, .noCarry2 - cpl - inc a -.noCarry2 - ld [$ff91], a ; store the distance between the two sprites' adjusted X values - -; Use the carry flag set by the above subtraction to determine which sprite's -; X coordinate is larger. This information is used later to set [$c1ic], -; which stores which direction the collision occurred in. -; The following 5 lines set the lowest 2 bits of c. -; If sprite i's X is larger, set lowest 2 bits of c to 10. -; If sprite j's X is larger or both are equal, set lowest 2 bits of c to 01. - push af - rl c - pop af - ccf - rl c - -; If sprite i's delta X is 0, then b = 7, else b = 9. - ld b, 7 - ld a, [hl] ; a = [$c1ib] (adjusted X coordinate) - and $f - jr z, .next3 - ld b, 9 - -.next3 - ld a, [$ff91] ; a = distance between adjusted X coordinates - sub b - ld [$ff92], a ; store distance adjusted using sprite i's direction - ld a, b - ld [$ff91], a ; store 7 or 9 depending on sprite i's delta X - jr c, .collision - -; If sprite j's delta X is 0, then b = 7, else b = 9. - ld b, 7 - dec e - ld a, [de] ; a = [$c1j5] (delta X) - inc e - and a - jr z, .next4 - ld b, 9 - -.next4 - ld a, [$ff92] ; a = distance adjusted using sprite i's direction - sub b ; adjust distance using sprite j's direction - jr z, .collision - jr nc, .next ; go to next sprite if distance is still positive after both adjustments - -.collision - ld a, [$ff91] ; a = 7 or 9 depending on sprite i's delta X - ld b, a - ld a, [$ff90] ; a = 7 or 9 depending on sprite i's delta Y - inc l - -; If delta X isn't 0 and delta Y is 0, then b = %0011, else b = %1100. -; (note that normally if delta X isn't 0, then delta Y must be 0 and vice versa) - cp b - jr c, .next5 - ld b, %1100 - jr .next6 -.next5 - ld b, %0011 - -.next6 - ld a, c ; c has 2 bits set (one of bits 0-1 is set for the X axis and one of bits 2-3 for the Y axis) - and b ; we select either the bit in bits 0-1 or bits 2-3 based on the calculation immediately above - or [hl] ; or with existing collision direction bits in [$c1ic] - ld [hl], a ; store new value - ld a, c ; useless code because a is overwritten before being used again - -; set bit in [$c1ie] or [$c1if] to indicate which sprite the collision occurred with - inc l - inc l - ld a, [$ff8f] ; a = loop counter - ld de, SpriteCollisionBitTable - add a - add e - ld e, a - jr nc, .noCarry3 - inc d -.noCarry3 - ld a, [de] - or [hl] - ld [hli], a - inc de - ld a, [de] - or [hl] - ld [hl], a - -.next - ld a, [$ff8f] ; a = loop counter - inc a - cp $10 - jp nz, .loop - ret - -; takes delta X or delta Y in a -; b = delta X/Y -; c = 0 if delta X/Y is 0 -; c = 7 if delta X/Y is 1 -; c = 9 if delta X/Y is -1 -SetSpriteCollisionValues: - and a - ld b, 0 - ld c, 0 - jr z, .done - ld c, 9 - cp -1 - jr z, .ok - ld c, 7 - ld a, 0 -.ok - ld b, a -.done - ret - -SpriteCollisionBitTable: - db %00000000,%00000001 - db %00000000,%00000010 - db %00000000,%00000100 - db %00000000,%00001000 - db %00000000,%00010000 - db %00000000,%00100000 - db %00000000,%01000000 - db %00000000,%10000000 - db %00000001,%00000000 - db %00000010,%00000000 - db %00000100,%00000000 - db %00001000,%00000000 - db %00010000,%00000000 - db %00100000,%00000000 - db %01000000,%00000000 - db %10000000,%00000000 diff --git a/engine/overworld/npc_movement.asm b/engine/overworld/npc_movement.asm deleted file mode 100755 index e478c9ad..00000000 --- a/engine/overworld/npc_movement.asm +++ /dev/null @@ -1,292 +0,0 @@ -PlayerStepOutFromDoor:: - ld hl, wd730 - res 1, [hl] - call IsPlayerStandingOnDoorTile - jr nc, .notStandingOnDoor - ld a, $fc - ld [wJoyIgnore], a - ld hl, wd736 - set 1, [hl] - ld a, $1 - ld [wSimulatedJoypadStatesIndex], a - ld a, D_DOWN - ld [wSimulatedJoypadStatesEnd], a - xor a - ld [wSpriteStateData1 + 2], a - call StartSimulatingJoypadStates - ret -.notStandingOnDoor - xor a - ld [wWastedByteCD3A], a - ld [wSimulatedJoypadStatesIndex], a - ld [wSimulatedJoypadStatesEnd], a - ld hl, wd736 - res 0, [hl] - res 1, [hl] - ld hl, wd730 - res 7, [hl] - ret - -_EndNPCMovementScript:: - ld hl, wd730 - res 7, [hl] - ld hl, wd72e - res 7, [hl] - ld hl, wd736 - res 0, [hl] - res 1, [hl] - xor a - ld [wNPCMovementScriptSpriteOffset], a - ld [wNPCMovementScriptPointerTableNum], a - ld [wNPCMovementScriptFunctionNum], a - ld [wWastedByteCD3A], a - ld [wSimulatedJoypadStatesIndex], a - ld [wSimulatedJoypadStatesEnd], a - ret - -PalletMovementScriptPointerTable:: - dw PalletMovementScript_OakMoveLeft - dw PalletMovementScript_PlayerMoveLeft - dw PalletMovementScript_WaitAndWalkToLab - dw PalletMovementScript_WalkToLab - dw PalletMovementScript_Done - -PalletMovementScript_OakMoveLeft: - ld a, [wXCoord] - sub $a - ld [wNumStepsToTake], a - jr z, .playerOnLeftTile -; The player is on the right tile of the northern path out of Pallet Town and -; Prof. Oak is below. -; Make Prof. Oak step to the left. - ld b, 0 - ld c, a - ld hl, wNPCMovementDirections2 - ld a, NPC_MOVEMENT_LEFT - call FillMemory - ld [hl], $ff - ld a, [wSpriteIndex] - ld [H_SPRITEINDEX], a - ld de, wNPCMovementDirections2 - call MoveSprite - ld a, $1 - ld [wNPCMovementScriptFunctionNum], a - jr .done -; The player is on the left tile of the northern path out of Pallet Town and -; Prof. Oak is below. -; Prof. Oak is already where he needs to be. -.playerOnLeftTile - ld a, $3 - ld [wNPCMovementScriptFunctionNum], a -.done - ld hl, wFlags_D733 - set 1, [hl] - ld a, $fc - ld [wJoyIgnore], a - ret - -PalletMovementScript_PlayerMoveLeft: - ld a, [wd730] - bit 0, a ; is an NPC being moved by a script? - ret nz ; return if Oak is still moving - ld a, [wNumStepsToTake] - ld [wSimulatedJoypadStatesIndex], a - ld [hNPCMovementDirections2Index], a - predef ConvertNPCMovementDirectionsToJoypadMasks - call StartSimulatingJoypadStates - ld a, $2 - ld [wNPCMovementScriptFunctionNum], a - ret - -PalletMovementScript_WaitAndWalkToLab: - ld a, [wSimulatedJoypadStatesIndex] - and a ; is the player done moving left yet? - ret nz - -PalletMovementScript_WalkToLab: - xor a - ld [wOverrideSimulatedJoypadStatesMask], a - ld a, [wSpriteIndex] - swap a - ld [wNPCMovementScriptSpriteOffset], a - xor a - ld [wSpriteStateData2 + $06], a - ld hl, wSimulatedJoypadStatesEnd - ld de, RLEList_PlayerWalkToLab - call DecodeRLEList - dec a - ld [wSimulatedJoypadStatesIndex], a - ld hl, wNPCMovementDirections2 - ld de, RLEList_ProfOakWalkToLab - call DecodeRLEList - ld hl, wd72e - res 7, [hl] - ld hl, wd730 - set 7, [hl] - ld a, $4 - ld [wNPCMovementScriptFunctionNum], a - ret - -RLEList_ProfOakWalkToLab: - db NPC_MOVEMENT_DOWN, $05 - db NPC_MOVEMENT_LEFT, $01 - db NPC_MOVEMENT_DOWN, $05 - db NPC_MOVEMENT_RIGHT, $03 - db NPC_MOVEMENT_UP, $01 - db $E0, $01 ; stand still - db $FF - -RLEList_PlayerWalkToLab: - db D_UP, $02 - db D_RIGHT, $03 - db D_DOWN, $05 - db D_LEFT, $01 - db D_DOWN, $06 - db $FF - -PalletMovementScript_Done: - ld a, [wSimulatedJoypadStatesIndex] - and a - ret nz - ld a, HS_PALLET_TOWN_OAK - ld [wMissableObjectIndex], a - predef HideObject - ld hl, wd730 - res 7, [hl] - ld hl, wd72e - res 7, [hl] - jp EndNPCMovementScript - -PewterMuseumGuyMovementScriptPointerTable:: - dw PewterMovementScript_WalkToMuseum - dw PewterMovementScript_Done - -PewterMovementScript_WalkToMuseum: - ld a, BANK(Music_MuseumGuy) - ld [wAudioROMBank], a - ld [wAudioSavedROMBank], a - ld a, MUSIC_MUSEUM_GUY - ld [wNewSoundID], a - call PlaySound - ld a, [wSpriteIndex] - swap a - ld [wNPCMovementScriptSpriteOffset], a - call StartSimulatingJoypadStates - ld hl, wSimulatedJoypadStatesEnd - ld de, RLEList_PewterMuseumPlayer - call DecodeRLEList - dec a - ld [wSimulatedJoypadStatesIndex], a - xor a - ld [wWhichPewterGuy], a - predef PewterGuys - ld hl, wNPCMovementDirections2 - ld de, RLEList_PewterMuseumGuy - call DecodeRLEList - ld hl, wd72e - res 7, [hl] - ld a, $1 - ld [wNPCMovementScriptFunctionNum], a - ret - -RLEList_PewterMuseumPlayer: - db 0, $01 - db D_UP, $03 - db D_LEFT, $0D - db D_UP, $06 - db $FF - -RLEList_PewterMuseumGuy: - db NPC_MOVEMENT_UP, $06 - db NPC_MOVEMENT_LEFT, $0D - db NPC_MOVEMENT_UP, $03 - db NPC_MOVEMENT_LEFT, $01 - db $FF - -PewterMovementScript_Done: - ld a, [wSimulatedJoypadStatesIndex] - and a - ret nz - ld hl, wd730 - res 7, [hl] - ld hl, wd72e - res 7, [hl] - jp EndNPCMovementScript - -PewterGymGuyMovementScriptPointerTable:: - dw PewterMovementScript_WalkToGym - dw PewterMovementScript_Done - -PewterMovementScript_WalkToGym: - ld a, BANK(Music_MuseumGuy) - ld [wAudioROMBank], a - ld [wAudioSavedROMBank], a - ld a, MUSIC_MUSEUM_GUY - ld [wNewSoundID], a - call PlaySound - ld a, [wSpriteIndex] - swap a - ld [wNPCMovementScriptSpriteOffset], a - xor a - ld [wSpriteStateData2 + $06], a - ld hl, wSimulatedJoypadStatesEnd - ld de, RLEList_PewterGymPlayer - call DecodeRLEList - dec a - ld [wSimulatedJoypadStatesIndex], a - ld a, 1 - ld [wWhichPewterGuy], a - predef PewterGuys - ld hl, wNPCMovementDirections2 - ld de, RLEList_PewterGymGuy - call DecodeRLEList - ld hl, wd72e - res 7, [hl] - ld hl, wd730 - set 7, [hl] - ld a, $1 - ld [wNPCMovementScriptFunctionNum], a - ret - -RLEList_PewterGymPlayer: - db 0, $01 - db D_RIGHT, $02 - db D_DOWN, $05 - db D_LEFT, $0B - db D_UP, $05 - db D_LEFT, $0F - db $FF - -RLEList_PewterGymGuy: - db NPC_MOVEMENT_DOWN, $02 - db NPC_MOVEMENT_LEFT, $0F - db NPC_MOVEMENT_UP, $05 - db NPC_MOVEMENT_LEFT, $0B - db NPC_MOVEMENT_DOWN, $05 - db NPC_MOVEMENT_RIGHT, $03 - db $FF - -FreezeEnemyTrainerSprite:: - ld a, [wCurMap] - cp POKEMON_TOWER_7F - ret z ; the Rockets on Pokemon Tower 7F leave after battling, so don't freeze them - ld hl, RivalIDs - ld a, [wEngagedTrainerClass] - ld b, a -.loop - ld a, [hli] - cp $ff - jr z, .notRival - cp b - ret z ; the rival leaves after battling, so don't freeze him - jr .loop -.notRival - ld a, [wSpriteIndex] - ld [H_SPRITEINDEX], a - jp SetSpriteMovementBytesToFF - -RivalIDs: - db OPP_SONY1 - db OPP_SONY2 - db OPP_SONY3 - db $ff diff --git a/engine/overworld/oaks_aide.asm b/engine/overworld/oaks_aide.asm deleted file mode 100755 index f5068fda..00000000 --- a/engine/overworld/oaks_aide.asm +++ /dev/null @@ -1,71 +0,0 @@ -OaksAideScript: - ld hl, OaksAideHiText - call PrintText - call YesNoChoice - ld a, [wCurrentMenuItem] - and a - jr nz, .choseNo - ld hl, wPokedexOwned - ld b, wPokedexOwnedEnd - wPokedexOwned - call CountSetBits - ld a, [wNumSetBits] - ld [hOaksAideNumMonsOwned], a - ld b, a - ld a, [hOaksAideRequirement] - cp b - jr z, .giveItem - jr nc, .notEnoughOwnedMons -.giveItem - ld hl, OaksAideHereYouGoText - call PrintText - ld a, [hOaksAideRewardItem] - ld b, a - ld c, 1 - call GiveItem - jr nc, .bagFull - ld hl, OaksAideGotItemText - call PrintText - ld a, $1 - jr .done -.bagFull - ld hl, OaksAideNoRoomText - call PrintText - xor a - jr .done -.notEnoughOwnedMons - ld hl, OaksAideUhOhText - call PrintText - ld a, $80 - jr .done -.choseNo - ld hl, OaksAideComeBackText - call PrintText - ld a, $ff -.done - ld [hOaksAideResult], a - ret - -OaksAideHiText: - TX_FAR _OaksAideHiText - db "@" - -OaksAideUhOhText: - TX_FAR _OaksAideUhOhText - db "@" - -OaksAideComeBackText: - TX_FAR _OaksAideComeBackText - db "@" - -OaksAideHereYouGoText: - TX_FAR _OaksAideHereYouGoText - db "@" - -OaksAideGotItemText: - TX_FAR _OaksAideGotItemText - TX_SFX_ITEM_1 - db "@" - -OaksAideNoRoomText: - TX_FAR _OaksAideNoRoomText - db "@" diff --git a/engine/overworld/oam.asm b/engine/overworld/oam.asm deleted file mode 100644 index 68128413..00000000 --- a/engine/overworld/oam.asm +++ /dev/null @@ -1,189 +0,0 @@ -PrepareOAMData:: -; Determine OAM data for currently visible -; sprites and write it to wOAMBuffer. - - ld a, [wUpdateSpritesEnabled] - dec a - jr z, .updateEnabled - - cp -1 - ret nz - ld [wUpdateSpritesEnabled], a - jp HideSprites - -.updateEnabled - xor a - ld [hOAMBufferOffset], a - -.spriteLoop - ld [hSpriteOffset2], a - - ld d, wSpriteStateData1 / $100 - ld a, [hSpriteOffset2] - ld e, a - ld a, [de] ; c1x0 - and a - jp z, .nextSprite - - inc e - inc e - ld a, [de] ; c1x2 (facing/anim) - ld [wd5cd], a - cp $ff ; off-screen (don't draw) - jr nz, .visible - - call GetSpriteScreenXY - jr .nextSprite - -.visible - cp $a0 ; is the sprite unchanging like an item ball or boulder? - jr c, .usefacing - -; unchanging - and $f - add $10 ; skip to the second half of the table which doesn't account for facing direction - jr .next - -.usefacing - and $f - -.next - ld l, a - -; get sprite priority - push de - inc d - ld a, e - add $5 - ld e, a - ld a, [de] ; c2x7 - and $80 - ld [hSpritePriority], a ; temp store sprite priority - pop de - -; read the entry from the table - ld h, 0 - ld bc, SpriteFacingAndAnimationTable - add hl, hl - add hl, hl - add hl, bc - ld a, [hli] - ld c, a - ld a, [hli] - ld b, a - ld a, [hli] - ld h, [hl] - ld l, a - - call GetSpriteScreenXY - - ld a, [hOAMBufferOffset] - ld e, a - ld d, wOAMBuffer / $100 - -.tileLoop - ld a, [hSpriteScreenY] ; temp for sprite Y position - add $10 ; Y=16 is top of screen (Y=0 is invisible) - add [hl] ; add Y offset from table - ld [de], a ; write new sprite OAM Y position - inc hl - ld a, [hSpriteScreenX] ; temp for sprite X position - add $8 ; X=8 is left of screen (X=0 is invisible) - add [hl] ; add X offset from table - inc e - ld [de], a ; write new sprite OAM X position - inc e - ld a, [bc] ; read pattern number offset (accommodates orientation (offset 0,4 or 8) and animation (offset 0 or $80)) - inc bc - push bc - ld b, a - - ld a, [wd5cd] ; temp copy of c1x2 - swap a ; high nybble determines sprite used (0 is always player sprite, next are some npcs) - and $f - - ; Sprites $a and $b have one face (and therefore 4 tiles instead of 12). - ; As a result, sprite $b's tile offset is less than normal. - cp $b - jr nz, .notFourTileSprite - ld a, $a * 12 + 4 - jr .next2 - -.notFourTileSprite - ; a *= 12 - sla a - sla a - ld c, a - sla a - add c - -.next2 - add b ; add the tile offset from the table (based on frame and facing direction) - pop bc - ld [de], a ; tile id - inc hl - inc e - ld a, [hl] - bit 1, a ; is the tile allowed to set the sprite priority bit? - jr z, .skipPriority - ld a, [hSpritePriority] - or [hl] -.skipPriority - inc hl - ld [de], a - inc e - bit 0, a ; OAMFLAG_ENDOFDATA - jr z, .tileLoop - - ld a, e - ld [hOAMBufferOffset], a - -.nextSprite - ld a, [hSpriteOffset2] - add $10 - cp $100 % $100 - jp nz, .spriteLoop - - ; Clear unused OAM. - ld a, [hOAMBufferOffset] - ld l, a - ld h, wOAMBuffer / $100 - ld de, $4 - ld b, $a0 - ld a, [wd736] - bit 6, a ; jumping down ledge or fishing animation? - ld a, $a0 - jr z, .clear - -; Don't clear the last 4 entries because they are used for the shadow in the -; jumping down ledge animation and the rod in the fishing animation. - ld a, $90 - -.clear - cp l - ret z - ld [hl], b - add hl, de - jr .clear - -GetSpriteScreenXY: - inc e - inc e - ld a, [de] ; c1x4 - ld [hSpriteScreenY], a - inc e - inc e - ld a, [de] ; c1x6 - ld [hSpriteScreenX], a - ld a, 4 - add e - ld e, a - ld a, [hSpriteScreenY] - add 4 - and $f0 - ld [de], a ; c1xa (y) - inc e - ld a, [hSpriteScreenX] - and $f0 - ld [de], a ; c1xb (x) - ret diff --git a/engine/overworld/pathfinding.asm b/engine/overworld/pathfinding.asm new file mode 100644 index 00000000..ba052d38 --- /dev/null +++ b/engine/overworld/pathfinding.asm @@ -0,0 +1,201 @@ +FindPathToPlayer: + xor a + ld hl, hFindPathNumSteps + ld [hli], a ; hFindPathNumSteps + ld [hli], a ; hFindPathFlags + ld [hli], a ; hFindPathYProgress + ld [hl], a ; hFindPathXProgress + ld hl, wNPCMovementDirections2 + ld de, $0 +.loop + ld a, [hFindPathYProgress] + ld b, a + ld a, [hNPCPlayerYDistance] ; Y distance in steps + call CalcDifference + ld d, a + and a + jr nz, .asm_f8da + ld a, [hFindPathFlags] + set 0, a ; current end of path matches the player's Y coordinate + ld [hFindPathFlags], a +.asm_f8da + ld a, [hFindPathXProgress] + ld b, a + ld a, [hNPCPlayerXDistance] ; X distance in steps + call CalcDifference + ld e, a + and a + jr nz, .asm_f8ec + ld a, [hFindPathFlags] + set 1, a ; current end of path matches the player's X coordinate + ld [hFindPathFlags], a +.asm_f8ec + ld a, [hFindPathFlags] + cp $3 ; has the end of the path reached the player's position? + jr z, .done +; Compare whether the X distance between the player and the current of the path +; is greater or if the Y distance is. Then, try to reduce whichever is greater. + ld a, e + cp d + jr c, .yDistanceGreater +; x distance is greater + ld a, [hNPCPlayerRelativePosFlags] + bit 1, a + jr nz, .playerIsLeftOfNPC + ld d, NPC_MOVEMENT_RIGHT + jr .next1 +.playerIsLeftOfNPC + ld d, NPC_MOVEMENT_LEFT +.next1 + ld a, [hFindPathXProgress] + add 1 + ld [hFindPathXProgress], a + jr .storeDirection +.yDistanceGreater + ld a, [hNPCPlayerRelativePosFlags] + bit 0, a + jr nz, .playerIsAboveNPC + ld d, NPC_MOVEMENT_DOWN + jr .next2 +.playerIsAboveNPC + ld d, NPC_MOVEMENT_UP +.next2 + ld a, [hFindPathYProgress] + add 1 + ld [hFindPathYProgress], a +.storeDirection + ld a, d + ld [hli], a + ld a, [hFindPathNumSteps] + inc a + ld [hFindPathNumSteps], a + jp .loop +.done + ld [hl], $ff + ret + +CalcPositionOfPlayerRelativeToNPC: + xor a + ld [hNPCPlayerRelativePosFlags], a + ld a, [wSpriteStateData1 + 4] ; player's sprite screen Y position in pixels + ld d, a + ld a, [wSpriteStateData1 + 6] ; player's sprite screen X position in pixels + ld e, a + ld hl, wSpriteStateData1 + ld a, [hNPCSpriteOffset] + add l + add $4 + ld l, a + jr nc, .noCarry + inc h +.noCarry + ld a, d + ld b, a + ld a, [hli] ; NPC sprite screen Y position in pixels + call CalcDifference + jr nc, .NPCSouthOfOrAlignedWithPlayer +.NPCNorthOfPlayer + push hl + ld hl, hNPCPlayerRelativePosFlags + bit 0, [hl] + set 0, [hl] + pop hl + jr .divideYDistance +.NPCSouthOfOrAlignedWithPlayer + push hl + ld hl, hNPCPlayerRelativePosFlags + bit 0, [hl] + res 0, [hl] + pop hl +.divideYDistance + push hl + ld hl, hDividend2 + ld [hli], a + ld a, 16 + ld [hli], a + call DivideBytes ; divide Y absolute distance by 16 + ld a, [hl] ; quotient + ld [hNPCPlayerYDistance], a + pop hl + inc hl + ld b, e + ld a, [hl] ; NPC sprite screen X position in pixels + call CalcDifference + jr nc, .NPCEastOfOrAlignedWithPlayer +.NPCWestOfPlayer + push hl + ld hl, hNPCPlayerRelativePosFlags + bit 1, [hl] + set 1, [hl] + pop hl + jr .divideXDistance +.NPCEastOfOrAlignedWithPlayer + push hl + ld hl, hNPCPlayerRelativePosFlags + bit 1, [hl] + res 1, [hl] + pop hl +.divideXDistance + ld [hDividend2], a + ld a, 16 + ld [hDivisor2], a + call DivideBytes ; divide X absolute distance by 16 + ld a, [hQuotient2] + ld [hNPCPlayerXDistance], a + ld a, [hNPCPlayerRelativePosPerspective] + and a + ret z + ld a, [hNPCPlayerRelativePosFlags] + cpl + and $3 + ld [hNPCPlayerRelativePosFlags], a + ret + +ConvertNPCMovementDirectionsToJoypadMasks: + ld a, [hNPCMovementDirections2Index] + ld [wNPCMovementDirections2Index], a + dec a + ld de, wSimulatedJoypadStatesEnd + ld hl, wNPCMovementDirections2 + add l + ld l, a + jr nc, .loop + inc h +.loop + ld a, [hld] + call ConvertNPCMovementDirectionToJoypadMask + ld [de], a + inc de + ld a, [hNPCMovementDirections2Index] + dec a + ld [hNPCMovementDirections2Index], a + jr nz, .loop + ret + +ConvertNPCMovementDirectionToJoypadMask: + push hl + ld b, a + ld hl, NPCMovementDirectionsToJoypadMasksTable +.loop + ld a, [hli] + cp $ff + jr z, .done + cp b + jr z, .loadJoypadMask + inc hl + jr .loop +.loadJoypadMask + ld a, [hl] +.done + pop hl + ret + +NPCMovementDirectionsToJoypadMasksTable: + db NPC_MOVEMENT_UP, D_UP + db NPC_MOVEMENT_DOWN, D_DOWN + db NPC_MOVEMENT_LEFT, D_LEFT + db NPC_MOVEMENT_RIGHT, D_RIGHT + db $ff + +; unreferenced + ret diff --git a/engine/overworld/pewter_guys.asm b/engine/overworld/pewter_guys.asm deleted file mode 100755 index 532fa4bf..00000000 --- a/engine/overworld/pewter_guys.asm +++ /dev/null @@ -1,102 +0,0 @@ -PewterGuys: - ld hl, wSimulatedJoypadStatesEnd - ld a, [wSimulatedJoypadStatesIndex] - dec a ; this decrement causes it to overwrite the last byte before $FF in the list - ld [wSimulatedJoypadStatesIndex], a - ld d, 0 - ld e, a - add hl, de - ld d, h - ld e, l - ld hl, PointerTable_37ce6 - ld a, [wWhichPewterGuy] - add a - ld b, 0 - ld c, a - add hl, bc - ld a, [hli] - ld h, [hl] - ld l, a - ld a, [wYCoord] - ld b, a - ld a, [wXCoord] - ld c, a -.findMatchingCoordsLoop - ld a, [hli] - cp b - jr nz, .nextEntry1 - ld a, [hli] - cp c - jr nz, .nextEntry2 - ld a, [hli] - ld h, [hl] - ld l, a -.copyMovementDataLoop - ld a, [hli] - cp $ff - ret z - ld [de], a - inc de - ld a, [wSimulatedJoypadStatesIndex] - inc a - ld [wSimulatedJoypadStatesIndex], a - jr .copyMovementDataLoop -.nextEntry1 - inc hl -.nextEntry2 - inc hl - inc hl - jr .findMatchingCoordsLoop - -PointerTable_37ce6: - dw PewterMuseumGuyCoords - dw PewterGymGuyCoords - -; these are the four coordinates of the spaces below, above, to the left and -; to the right of the museum guy, and pointers to different movements for -; the player to make to get positioned before the main movement. -PewterMuseumGuyCoords: - db 18, 27 - dw .down - db 16, 27 - dw .up - db 17, 26 - dw .left - db 17, 28 - dw .right - -.down - db D_UP, D_UP, $ff -.up - db D_RIGHT, D_LEFT, $ff -.left - db D_UP, D_RIGHT, $ff -.right - db D_UP, D_LEFT, $ff - -; these are the five coordinates which trigger the gym guy and pointers to -; different movements for the player to make to get positioned before the -; main movement -; $00 is a pause -PewterGymGuyCoords: - db 16, 34 - dw .one - db 17, 35 - dw .two - db 18, 37 - dw .three - db 19, 37 - dw .four - db 17, 36 - dw .five - -.one - db D_LEFT, D_DOWN, D_DOWN, D_RIGHT, $ff -.two - db D_LEFT, D_DOWN, D_RIGHT, D_LEFT, $ff -.three - db D_LEFT, D_LEFT, D_LEFT, $00, $00, $00, $00, $00, $00, $00, $00, $ff -.four - db D_LEFT, D_LEFT, D_UP, D_LEFT, $ff -.five - db D_LEFT, D_DOWN, D_LEFT, $00, $00, $00, $00, $00, $00, $00, $00, $ff diff --git a/engine/overworld/poison.asm b/engine/overworld/poison.asm deleted file mode 100644 index 5d8eb9fd..00000000 --- a/engine/overworld/poison.asm +++ /dev/null @@ -1,112 +0,0 @@ -ApplyOutOfBattlePoisonDamage: - ld a, [wd730] - add a - jp c, .noBlackOut ; no black out if joypad states are being simulated - ld a, [wPartyCount] - and a - jp z, .noBlackOut - call IncrementDayCareMonExp - ld a, [wStepCounter] - and $3 ; is the counter a multiple of 4? - jp nz, .noBlackOut ; only apply poison damage every fourth step - ld [wWhichPokemon], a - ld hl, wPartyMon1Status - ld de, wPartySpecies -.applyDamageLoop - ld a, [hl] - and (1 << PSN) - jr z, .nextMon2 ; not poisoned - dec hl - dec hl - ld a, [hld] - ld b, a - ld a, [hli] - or b - jr z, .nextMon ; already fainted -; subtract 1 from HP - ld a, [hl] - dec a - ld [hld], a - inc a - jr nz, .noBorrow -; borrow 1 from upper byte of HP - dec [hl] - inc hl - jr .nextMon -.noBorrow - ld a, [hli] - or [hl] - jr nz, .nextMon ; didn't faint from damage -; the mon fainted from the damage - push hl - inc hl - inc hl - ld [hl], a - ld a, [de] - ld [wd11e], a - push de - ld a, [wWhichPokemon] - ld hl, wPartyMonNicks - call GetPartyMonName - xor a - ld [wJoyIgnore], a - call EnableAutoTextBoxDrawing - ld a, TEXT_MON_FAINTED - ld [hSpriteIndexOrTextID], a - call DisplayTextID - pop de - pop hl -.nextMon - inc hl - inc hl -.nextMon2 - inc de - ld a, [de] - inc a - jr z, .applyDamageLoopDone - ld bc, wPartyMon2 - wPartyMon1 - add hl, bc - push hl - ld hl, wWhichPokemon - inc [hl] - pop hl - jr .applyDamageLoop -.applyDamageLoopDone - ld hl, wPartyMon1Status - ld a, [wPartyCount] - ld d, a - ld e, 0 -.countPoisonedLoop - ld a, [hl] - and (1 << PSN) - or e - ld e, a - ld bc, wPartyMon2 - wPartyMon1 - add hl, bc - dec d - jr nz, .countPoisonedLoop - ld a, e - and a ; are any party members poisoned? - jr z, .skipPoisonEffectAndSound - ld b, $2 - predef ChangeBGPalColor0_4Frames ; change BG white to dark grey for 4 frames - ld a, SFX_POISONED - call PlaySound -.skipPoisonEffectAndSound - predef AnyPartyAlive - ld a, d - and a - jr nz, .noBlackOut - call EnableAutoTextBoxDrawing - ld a, TEXT_BLACKED_OUT - ld [hSpriteIndexOrTextID], a - call DisplayTextID - ld hl, wd72e - set 5, [hl] - ld a, $ff - jr .done -.noBlackOut - xor a -.done - ld [wOutOfBattleBlackout], a - ret diff --git a/engine/overworld/pokecenter.asm b/engine/overworld/pokecenter.asm deleted file mode 100755 index f340e06d..00000000 --- a/engine/overworld/pokecenter.asm +++ /dev/null @@ -1,68 +0,0 @@ -DisplayPokemonCenterDialogue_:: - call SaveScreenTilesToBuffer1 ; save screen - ld hl, PokemonCenterWelcomeText - call PrintText - ld hl, wd72e - bit 2, [hl] - set 1, [hl] - set 2, [hl] - jr nz, .skipShallWeHealYourPokemon - ld hl, ShallWeHealYourPokemonText - call PrintText -.skipShallWeHealYourPokemon - call YesNoChoicePokeCenter ; yes/no menu - ld a, [wCurrentMenuItem] - and a - jr nz, .declinedHealing ; if the player chose No - call SetLastBlackoutMap - call LoadScreenTilesFromBuffer1 ; restore screen - ld hl, NeedYourPokemonText - call PrintText - ld a, $18 - ld [wSpriteStateData1 + $12], a ; make the nurse turn to face the machine - call Delay3 - predef HealParty - callba AnimateHealingMachine ; do the healing machine animation - xor a - ld [wAudioFadeOutControl], a - ld a, [wAudioSavedROMBank] - ld [wAudioROMBank], a - ld a, [wMapMusicSoundID] - ld [wLastMusicSoundID], a - ld [wNewSoundID], a - call PlaySound - ld hl, PokemonFightingFitText - call PrintText - ld a, $14 - ld [wSpriteStateData1 + $12], a ; make the nurse bow - ld c, a - call DelayFrames - jr .done -.declinedHealing - call LoadScreenTilesFromBuffer1 ; restore screen -.done - ld hl, PokemonCenterFarewellText - call PrintText - jp UpdateSprites - -PokemonCenterWelcomeText: - TX_FAR _PokemonCenterWelcomeText - db "@" - -ShallWeHealYourPokemonText: - TX_DELAY - TX_FAR _ShallWeHealYourPokemonText - db "@" - -NeedYourPokemonText: - TX_FAR _NeedYourPokemonText - db "@" - -PokemonFightingFitText: - TX_FAR _PokemonFightingFitText - db "@" - -PokemonCenterFarewellText: - TX_DELAY - TX_FAR _PokemonCenterFarewellText - db "@" diff --git a/engine/overworld/pokemart.asm b/engine/overworld/pokemart.asm deleted file mode 100755 index 177e8a09..00000000 --- a/engine/overworld/pokemart.asm +++ /dev/null @@ -1,272 +0,0 @@ -DisplayPokemartDialogue_:: - ld a, [wListScrollOffset] - ld [wSavedListScrollOffset], a - call UpdateSprites - xor a - ld [wBoughtOrSoldItemInMart], a -.loop - xor a - ld [wListScrollOffset], a - ld [wCurrentMenuItem], a - ld [wPlayerMonNumber], a - inc a - ld [wPrintItemPrices], a - ld a, MONEY_BOX - ld [wTextBoxID], a - call DisplayTextBoxID - ld a, BUY_SELL_QUIT_MENU - ld [wTextBoxID], a - call DisplayTextBoxID - -; This code is useless. It copies the address of the pokemart's inventory to hl, -; but the address is never used. - ld hl, wItemListPointer - ld a, [hli] - ld l, [hl] - ld h, a - - ld a, [wMenuExitMethod] - cp CANCELLED_MENU - jp z, .done - ld a, [wChosenMenuItem] - and a ; buying? - jp z, .buyMenu - dec a ; selling? - jp z, .sellMenu - dec a ; quitting? - jp z, .done -.sellMenu - -; the same variables are set again below, so this code has no effect - xor a - ld [wPrintItemPrices], a - ld a, INIT_BAG_ITEM_LIST - ld [wInitListType], a - callab InitList - - ld a, [wNumBagItems] - and a - jp z, .bagEmpty - ld hl, PokemonSellingGreetingText - call PrintText - call SaveScreenTilesToBuffer1 ; save screen -.sellMenuLoop - call LoadScreenTilesFromBuffer1 ; restore saved screen - ld a, MONEY_BOX - ld [wTextBoxID], a - call DisplayTextBoxID ; draw money text box - ld hl, wNumBagItems - ld a, l - ld [wListPointer], a - ld a, h - ld [wListPointer + 1], a - xor a - ld [wPrintItemPrices], a - ld [wCurrentMenuItem], a - ld a, ITEMLISTMENU - ld [wListMenuID], a - call DisplayListMenuID - jp c, .returnToMainPokemartMenu ; if the player closed the menu -.confirmItemSale ; if the player is trying to sell a specific item - call IsKeyItem - ld a, [wIsKeyItem] - and a - jr nz, .unsellableItem - ld a, [wcf91] - call IsItemHM - jr c, .unsellableItem - ld a, PRICEDITEMLISTMENU - ld [wListMenuID], a - ld [hHalveItemPrices], a ; halve prices when selling - call DisplayChooseQuantityMenu - inc a - jr z, .sellMenuLoop ; if the player closed the choose quantity menu with the B button - ld hl, PokemartTellSellPriceText - lb bc, 14, 1 ; location that PrintText always prints to, this is useless - call PrintText - coord hl, 14, 7 - lb bc, 8, 15 - ld a, TWO_OPTION_MENU - ld [wTextBoxID], a - call DisplayTextBoxID ; yes/no menu - ld a, [wMenuExitMethod] - cp CHOSE_SECOND_ITEM - jr z, .sellMenuLoop ; if the player chose No or pressed the B button - -; The following code is supposed to check if the player chose No, but the above -; check already catches it. - ld a, [wChosenMenuItem] - dec a - jr z, .sellMenuLoop - -.sellItem - ld a, [wBoughtOrSoldItemInMart] - and a - jr nz, .skipSettingFlag1 - inc a - ld [wBoughtOrSoldItemInMart], a -.skipSettingFlag1 - call AddAmountSoldToMoney - ld hl, wNumBagItems - call RemoveItemFromInventory - jp .sellMenuLoop -.unsellableItem - ld hl, PokemartUnsellableItemText - call PrintText - jp .returnToMainPokemartMenu -.bagEmpty - ld hl, PokemartItemBagEmptyText - call PrintText - call SaveScreenTilesToBuffer1 - jp .returnToMainPokemartMenu -.buyMenu - -; the same variables are set again below, so this code has no effect - ld a, 1 - ld [wPrintItemPrices], a - ld a, INIT_OTHER_ITEM_LIST - ld [wInitListType], a - callab InitList - - ld hl, PokemartBuyingGreetingText - call PrintText - call SaveScreenTilesToBuffer1 -.buyMenuLoop - call LoadScreenTilesFromBuffer1 - ld a, MONEY_BOX - ld [wTextBoxID], a - call DisplayTextBoxID - ld hl, wItemList - ld a, l - ld [wListPointer], a - ld a, h - ld [wListPointer + 1], a - xor a - ld [wCurrentMenuItem], a - inc a - ld [wPrintItemPrices], a - inc a ; a = 2 (PRICEDITEMLISTMENU) - ld [wListMenuID], a - call DisplayListMenuID - jr c, .returnToMainPokemartMenu ; if the player closed the menu - ld a, 99 - ld [wMaxItemQuantity], a - xor a - ld [hHalveItemPrices], a ; don't halve item prices when buying - call DisplayChooseQuantityMenu - inc a - jr z, .buyMenuLoop ; if the player closed the choose quantity menu with the B button - ld a, [wcf91] ; item ID - ld [wd11e], a ; store item ID for GetItemName - call GetItemName - call CopyStringToCF4B ; copy name to wcf4b - ld hl, PokemartTellBuyPriceText - call PrintText - coord hl, 14, 7 - lb bc, 8, 15 - ld a, TWO_OPTION_MENU - ld [wTextBoxID], a - call DisplayTextBoxID ; yes/no menu - ld a, [wMenuExitMethod] - cp CHOSE_SECOND_ITEM - jp z, .buyMenuLoop ; if the player chose No or pressed the B button - -; The following code is supposed to check if the player chose No, but the above -; check already catches it. - ld a, [wChosenMenuItem] - dec a - jr z, .buyMenuLoop - -.buyItem - call .isThereEnoughMoney - jr c, .notEnoughMoney - ld hl, wNumBagItems - call AddItemToInventory - jr nc, .bagFull - call SubtractAmountPaidFromMoney - ld a, [wBoughtOrSoldItemInMart] - and a - jr nz, .skipSettingFlag2 - ld a, 1 - ld [wBoughtOrSoldItemInMart], a -.skipSettingFlag2 - ld a, SFX_PURCHASE - call PlaySoundWaitForCurrent - call WaitForSoundToFinish - ld hl, PokemartBoughtItemText - call PrintText - jp .buyMenuLoop -.returnToMainPokemartMenu - call LoadScreenTilesFromBuffer1 - ld a, MONEY_BOX - ld [wTextBoxID], a - call DisplayTextBoxID - ld hl, PokemartAnythingElseText - call PrintText - jp .loop -.isThereEnoughMoney - ld de, wPlayerMoney - ld hl, hMoney - ld c, 3 ; length of money in bytes - jp StringCmp -.notEnoughMoney - ld hl, PokemartNotEnoughMoneyText - call PrintText - jr .returnToMainPokemartMenu -.bagFull - ld hl, PokemartItemBagFullText - call PrintText - jr .returnToMainPokemartMenu -.done - ld hl, PokemartThankYouText - call PrintText - ld a, 1 - ld [wUpdateSpritesEnabled], a - call UpdateSprites - ld a, [wSavedListScrollOffset] - ld [wListScrollOffset], a - ret - -PokemartBuyingGreetingText: - TX_FAR _PokemartBuyingGreetingText - db "@" - -PokemartTellBuyPriceText: - TX_FAR _PokemartTellBuyPriceText - db "@" - -PokemartBoughtItemText: - TX_FAR _PokemartBoughtItemText - db "@" - -PokemartNotEnoughMoneyText: - TX_FAR _PokemartNotEnoughMoneyText - db "@" - -PokemartItemBagFullText: - TX_FAR _PokemartItemBagFullText - db "@" - -PokemonSellingGreetingText: - TX_FAR _PokemonSellingGreetingText - db "@" - -PokemartTellSellPriceText: - TX_FAR _PokemartTellSellPriceText - db "@" - -PokemartItemBagEmptyText: - TX_FAR _PokemartItemBagEmptyText - db "@" - -PokemartUnsellableItemText: - TX_FAR _PokemartUnsellableItemText - db "@" - -PokemartThankYouText: - TX_FAR _PokemartThankYouText - db "@" - -PokemartAnythingElseText: - TX_FAR _PokemartAnythingElseText - db "@" diff --git a/engine/overworld/saffron_guards.asm b/engine/overworld/saffron_guards.asm deleted file mode 100755 index 091cfa1a..00000000 --- a/engine/overworld/saffron_guards.asm +++ /dev/null @@ -1,15 +0,0 @@ -RemoveGuardDrink:: - ld hl, GuardDrinksList -.drinkLoop - ld a, [hli] - ld [$ffdb], a - and a - ret z - push hl - ld b, a - call IsItemInBag - pop hl - jr z, .drinkLoop - jpba RemoveItemByID - -INCLUDE "data/guard_drink_items.asm" diff --git a/engine/overworld/set_blackout_map.asm b/engine/overworld/set_blackout_map.asm deleted file mode 100644 index 14f0ba28..00000000 --- a/engine/overworld/set_blackout_map.asm +++ /dev/null @@ -1,25 +0,0 @@ -SetLastBlackoutMap: -; Set the map to return to when -; blacking out or using Teleport or Dig. -; Safari rest houses don't count. - - push hl - ld hl, SafariZoneRestHouses - ld a, [wCurMap] - ld b, a -.loop - ld a, [hli] - cp -1 - jr z, .notresthouse - cp b - jr nz, .loop - jr .done - -.notresthouse - ld a, [wLastMap] - ld [wLastBlackoutMap], a -.done - pop hl - ret - -INCLUDE "data/rest_house_maps.asm" diff --git a/engine/overworld/special_warps.asm b/engine/overworld/special_warps.asm new file mode 100644 index 00000000..eee85402 --- /dev/null +++ b/engine/overworld/special_warps.asm @@ -0,0 +1,149 @@ +SpecialWarpIn:: + call LoadSpecialWarpData + predef LoadTilesetHeader + ld hl, wd732 + bit 2, [hl] ; dungeon warp or fly warp? + res 2, [hl] + jr z, .next +; if dungeon warp or fly warp + ld a, [wDestinationMap] + jr .next2 +.next + bit 1, [hl] + jr z, .next3 + call EmptyFunc +.next3 + ld a, 0 +.next2 + ld b, a + ld a, [wd72d] + and a + jr nz, .next4 + ld a, b +.next4 + ld hl, wd732 + bit 4, [hl] ; dungeon warp? + ret nz +; if not dungeon warp + ld [wLastMap], a + ret + +; gets the map ID, tile block map view pointer, tileset, and coordinates +LoadSpecialWarpData: + ld a, [wd72d] + cp TRADE_CENTER + jr nz, .notTradeCenter + ld hl, TradeCenterSpec1 + ld a, [hSerialConnectionStatus] + cp USING_INTERNAL_CLOCK ; which gameboy is clocking determines who is on the left and who is on the right + jr z, .copyWarpData + ld hl, TradeCenterSpec2 + jr .copyWarpData +.notTradeCenter + cp COLOSSEUM + jr nz, .notColosseum + ld hl, ColosseumSpec1 + ld a, [hSerialConnectionStatus] + cp USING_INTERNAL_CLOCK + jr z, .copyWarpData + ld hl, ColosseumSpec2 + jr .copyWarpData +.notColosseum + ld a, [wd732] + bit 1, a + jr nz, .notFirstMap + bit 2, a + jr nz, .notFirstMap + ld hl, FirstMapSpec +.copyWarpData + ld de, wCurMap + ld c, $7 +.copyWarpDataLoop + ld a, [hli] + ld [de], a + inc de + dec c + jr nz, .copyWarpDataLoop + ld a, [hli] + ld [wCurMapTileset], a + xor a + jr .done +.notFirstMap + ld a, [wLastMap] ; this value is overwritten before it's ever read + ld hl, wd732 + bit 4, [hl] ; used dungeon warp (jumped down hole/waterfall)? + jr nz, .usedDunegonWarp + bit 6, [hl] ; return to last pokemon center (or player's house)? + res 6, [hl] + jr z, .otherDestination +; return to last pokemon center or player's house + ld a, [wLastBlackoutMap] + jr .usedFlyWarp +.usedDunegonWarp + ld hl, wd72d + res 4, [hl] + ld a, [wDungeonWarpDestinationMap] + ld b, a + ld [wCurMap], a + ld a, [wWhichDungeonWarp] + ld c, a + ld hl, DungeonWarpList + ld de, 0 + ld a, 6 + ld [wDungeonWarpDataEntrySize], a +.dungeonWarpListLoop + ld a, [hli] + cp b + jr z, .matchedDungeonWarpDestinationMap + inc hl + jr .nextDungeonWarp +.matchedDungeonWarpDestinationMap + ld a, [hli] + cp c + jr z, .matchedDungeonWarpID +.nextDungeonWarp + ld a, [wDungeonWarpDataEntrySize] + add e + ld e, a + jr .dungeonWarpListLoop +.matchedDungeonWarpID + ld hl, DungeonWarpData + add hl, de + jr .copyWarpData2 +.otherDestination + ld a, [wDestinationMap] +.usedFlyWarp + ld b, a + ld [wCurMap], a + ld hl, FlyWarpDataPtr +.flyWarpDataPtrLoop + ld a, [hli] + inc hl + cp b + jr z, .foundFlyWarpMatch + inc hl + inc hl + jr .flyWarpDataPtrLoop +.foundFlyWarpMatch + ld a, [hli] + ld h, [hl] + ld l, a +.copyWarpData2 + ld de, wCurrentTileBlockMapViewPointer + ld c, $6 +.copyWarpDataLoop2 + ld a, [hli] + ld [de], a + inc de + dec c + jr nz, .copyWarpDataLoop2 + xor a ; OVERWORLD + ld [wCurMapTileset], a +.done + ld [wYOffsetSinceLastSpecialWarp], a + ld [wXOffsetSinceLastSpecialWarp], a + ld a, $ff ; the player's coordinates have already been updated using a special warp, so don't use any of the normal warps + ld [wDestinationWarpID], a + ret + +INCLUDE "data/special_warps.asm" diff --git a/engine/overworld/sprite_collisions.asm b/engine/overworld/sprite_collisions.asm new file mode 100644 index 00000000..0e6b2d06 --- /dev/null +++ b/engine/overworld/sprite_collisions.asm @@ -0,0 +1,356 @@ +_UpdateSprites:: + ld h, $c1 + inc h + ld a, $e ; wSpriteStateData2 + $0e +.spriteLoop + ld l, a + sub $e + ld c, a + ld [H_CURRENTSPRITEOFFSET], a + ld a, [hl] + and a + jr z, .skipSprite ; tests $c2Xe + push hl + push de + push bc + call .updateCurrentSprite + pop bc + pop de + pop hl +.skipSprite + ld a, l + add $10 ; move to next sprite + cp $e ; test for overflow (back at $0e) + jr nz, .spriteLoop + ret +.updateCurrentSprite + cp $1 + jp nz, UpdateNonPlayerSprite + jp UpdatePlayerSprite + +UpdateNonPlayerSprite: + dec a + swap a + ld [$ff93], a ; $10 * sprite# + ld a, [wNPCMovementScriptSpriteOffset] ; some sprite offset? + ld b, a + ld a, [H_CURRENTSPRITEOFFSET] + cp b + jr nz, .unequal + jp DoScriptedNPCMovement +.unequal + jp UpdateNPCSprite + +; This detects if the current sprite (whose offset is at H_CURRENTSPRITEOFFSET) +; is going to collide with another sprite by looping over the other sprites. +; The current sprite's offset will be labelled with i (e.g. $c1i0). +; The loop sprite's offset will labelled with j (e.g. $c1j0). +; +; Note that the Y coordinate of the sprite (in [$c1k4]) is one of the following +; 9 values when the sprite is aligned with the grid: $fc, $0c, $1c, $2c, ..., $7c. +; The reason that 4 is added below to the coordinate is to make it align with a +; multiple of $10 to make comparisons easier. +DetectCollisionBetweenSprites: + nop + + ld h, wSpriteStateData1 / $100 + ld a, [H_CURRENTSPRITEOFFSET] + add wSpriteStateData1 % $100 + ld l, a + + ld a, [hl] ; a = [$c1i0] (picture) (0 if slot is unused) + and a ; is this sprite slot slot used? + ret z ; return if not used + + ld a, l + add 3 + ld l, a + + ld a, [hli] ; a = [$c1i3] (delta Y) (-1, 0, or 1) + call SetSpriteCollisionValues + + ld a, [hli] ; a = [$C1i4] (Y screen coordinate) + add 4 ; align with multiple of $10 + +; The effect of the following 3 lines is to +; add 7 to a if moving south or +; subtract 7 from a if moving north. + add b + and $f0 + or c + + ld [$ff90], a ; store Y coordinate adjusted for direction of movement + + ld a, [hli] ; a = [$c1i5] (delta X) (-1, 0, or 1) + call SetSpriteCollisionValues + ld a, [hl] ; a = [$C1i6] (X screen coordinate) + +; The effect of the following 3 lines is to +; add 7 to a if moving east or +; subtract 7 from a if moving west. + add b + and $f0 + or c + + ld [$ff91], a ; store X coordinate adjusted for direction of movement + + ld a, l + add 7 + ld l, a + + xor a + ld [hld], a ; zero [$c1id] XXX what's [$c1id] for? + ld [hld], a ; zero [$c1ic] (directions in which collisions occurred) + + ld a, [$ff91] + ld [hld], a ; [$c1ib] = adjusted X coordinate + ld a, [$ff90] + ld [hl], a ; [$c1ia] = adjusted Y coordinate + + xor a ; zero the loop counter + +.loop + ld [$ff8f], a ; store loop counter + swap a + ld e, a + ld a, [H_CURRENTSPRITEOFFSET] + cp e ; does the loop sprite match the current sprite? + jp z, .next ; go to the next sprite if they match + + ld d, h + ld a, [de] ; a = [$c1j0] (picture) (0 if slot is unused) + and a ; is this sprite slot slot used? + jp z, .next ; go the next sprite if not used + + inc e + inc e + ld a, [de] ; a = [$c1j2] ($ff means the sprite is offscreen) + inc a + jp z, .next ; go the next sprite if offscreen + + ld a, [H_CURRENTSPRITEOFFSET] + add 10 + ld l, a + + inc e + ld a, [de] ; a = [$c1j3] (delta Y) + call SetSpriteCollisionValues + + inc e + ld a, [de] ; a = [$C1j4] (Y screen coordinate) + add 4 ; align with multiple of $10 + +; The effect of the following 3 lines is to +; add 7 to a if moving south or +; subtract 7 from a if moving north. + add b + and $f0 + or c + + sub [hl] ; subtract the adjusted Y coordinate of sprite i ([$c1ia]) from that of sprite j + +; calculate the absolute value of the difference to get the distance + jr nc, .noCarry1 + cpl + inc a +.noCarry1 + ld [$ff90], a ; store the distance between the two sprites' adjusted Y values + +; Use the carry flag set by the above subtraction to determine which sprite's +; Y coordinate is larger. This information is used later to set [$c1ic], +; which stores which direction the collision occurred in. +; The following 5 lines set the lowest 2 bits of c, which are later shifted left by 2. +; If sprite i's Y is larger, set lowest 2 bits of c to 10. +; If sprite j's Y is larger or both are equal, set lowest 2 bits of c to 01. + push af + rl c + pop af + ccf + rl c + +; If sprite i's delta Y is 0, then b = 7, else b = 9. + ld b, 7 + ld a, [hl] ; a = [$c1ia] (adjusted Y coordinate) + and $f + jr z, .next1 + ld b, 9 + +.next1 + ld a, [$ff90] ; a = distance between adjusted Y coordinates + sub b + ld [$ff92], a ; store distance adjusted using sprite i's direction + ld a, b + ld [$ff90], a ; store 7 or 9 depending on sprite i's delta Y + jr c, .checkXDistance + +; If sprite j's delta Y is 0, then b = 7, else b = 9. + ld b, 7 + dec e + ld a, [de] ; a = [$c1j3] (delta Y) + inc e + and a + jr z, .next2 + ld b, 9 + +.next2 + ld a, [$ff92] ; a = distance adjusted using sprite i's direction + sub b ; adjust distance using sprite j's direction + jr z, .checkXDistance + jr nc, .next ; go to next sprite if distance is still positive after both adjustments + +.checkXDistance + inc e + inc l + ld a, [de] ; a = [$c1j5] (delta X) + + push bc + + call SetSpriteCollisionValues + inc e + ld a, [de] ; a = [$c1j6] (X screen coordinate) + +; The effect of the following 3 lines is to +; add 7 to a if moving east or +; subtract 7 from a if moving west. + add b + and $f0 + or c + + pop bc + + sub [hl] ; subtract the adjusted X coordinate of sprite i ([$c1ib]) from that of sprite j + +; calculate the absolute value of the difference to get the distance + jr nc, .noCarry2 + cpl + inc a +.noCarry2 + ld [$ff91], a ; store the distance between the two sprites' adjusted X values + +; Use the carry flag set by the above subtraction to determine which sprite's +; X coordinate is larger. This information is used later to set [$c1ic], +; which stores which direction the collision occurred in. +; The following 5 lines set the lowest 2 bits of c. +; If sprite i's X is larger, set lowest 2 bits of c to 10. +; If sprite j's X is larger or both are equal, set lowest 2 bits of c to 01. + push af + rl c + pop af + ccf + rl c + +; If sprite i's delta X is 0, then b = 7, else b = 9. + ld b, 7 + ld a, [hl] ; a = [$c1ib] (adjusted X coordinate) + and $f + jr z, .next3 + ld b, 9 + +.next3 + ld a, [$ff91] ; a = distance between adjusted X coordinates + sub b + ld [$ff92], a ; store distance adjusted using sprite i's direction + ld a, b + ld [$ff91], a ; store 7 or 9 depending on sprite i's delta X + jr c, .collision + +; If sprite j's delta X is 0, then b = 7, else b = 9. + ld b, 7 + dec e + ld a, [de] ; a = [$c1j5] (delta X) + inc e + and a + jr z, .next4 + ld b, 9 + +.next4 + ld a, [$ff92] ; a = distance adjusted using sprite i's direction + sub b ; adjust distance using sprite j's direction + jr z, .collision + jr nc, .next ; go to next sprite if distance is still positive after both adjustments + +.collision + ld a, [$ff91] ; a = 7 or 9 depending on sprite i's delta X + ld b, a + ld a, [$ff90] ; a = 7 or 9 depending on sprite i's delta Y + inc l + +; If delta X isn't 0 and delta Y is 0, then b = %0011, else b = %1100. +; (note that normally if delta X isn't 0, then delta Y must be 0 and vice versa) + cp b + jr c, .next5 + ld b, %1100 + jr .next6 +.next5 + ld b, %0011 + +.next6 + ld a, c ; c has 2 bits set (one of bits 0-1 is set for the X axis and one of bits 2-3 for the Y axis) + and b ; we select either the bit in bits 0-1 or bits 2-3 based on the calculation immediately above + or [hl] ; or with existing collision direction bits in [$c1ic] + ld [hl], a ; store new value + ld a, c ; useless code because a is overwritten before being used again + +; set bit in [$c1ie] or [$c1if] to indicate which sprite the collision occurred with + inc l + inc l + ld a, [$ff8f] ; a = loop counter + ld de, SpriteCollisionBitTable + add a + add e + ld e, a + jr nc, .noCarry3 + inc d +.noCarry3 + ld a, [de] + or [hl] + ld [hli], a + inc de + ld a, [de] + or [hl] + ld [hl], a + +.next + ld a, [$ff8f] ; a = loop counter + inc a + cp $10 + jp nz, .loop + ret + +; takes delta X or delta Y in a +; b = delta X/Y +; c = 0 if delta X/Y is 0 +; c = 7 if delta X/Y is 1 +; c = 9 if delta X/Y is -1 +SetSpriteCollisionValues: + and a + ld b, 0 + ld c, 0 + jr z, .done + ld c, 9 + cp -1 + jr z, .ok + ld c, 7 + ld a, 0 +.ok + ld b, a +.done + ret + +SpriteCollisionBitTable: + db %00000000,%00000001 + db %00000000,%00000010 + db %00000000,%00000100 + db %00000000,%00001000 + db %00000000,%00010000 + db %00000000,%00100000 + db %00000000,%01000000 + db %00000000,%10000000 + db %00000001,%00000000 + db %00000010,%00000000 + db %00000100,%00000000 + db %00001000,%00000000 + db %00010000,%00000000 + db %00100000,%00000000 + db %01000000,%00000000 + db %10000000,%00000000 diff --git a/engine/overworld/ssanne.asm b/engine/overworld/ssanne.asm deleted file mode 100755 index 6c26b712..00000000 --- a/engine/overworld/ssanne.asm +++ /dev/null @@ -1,93 +0,0 @@ -AnimateBoulderDust: - ld a, $1 - ld [wWhichAnimationOffsets], a ; select the boulder dust offsets - ld a, [wUpdateSpritesEnabled] - push af - ld a, $ff - ld [wUpdateSpritesEnabled], a - ld a, %11100100 - ld [rOBP1], a - call LoadSmokeTileFourTimes - callba WriteCutOrBoulderDustAnimationOAMBlock - ld c, 8 ; number of steps in animation -.loop - push bc - call GetMoveBoulderDustFunctionPointer - ld bc, .returnAddress - push bc - ld c, 4 - jp hl -.returnAddress - ld a, [rOBP1] - xor %01100100 - ld [rOBP1], a - call Delay3 - pop bc - dec c - jr nz, .loop - pop af - ld [wUpdateSpritesEnabled], a - jp LoadPlayerSpriteGraphics - -GetMoveBoulderDustFunctionPointer: - ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction - ld hl, MoveBoulderDustFunctionPointerTable - ld c, a - ld b, $0 - add hl, bc - ld a, [hli] - ld [wCoordAdjustmentAmount], a - ld a, [hli] - ld e, a - ld a, [hli] - ld h, [hl] - ld l, a - push hl - ld hl, wOAMBuffer + $90 - ld d, $0 - add hl, de - ld e, l - ld d, h - pop hl - ret - -MoveBoulderDustFunctionPointerTable: -; facing down - db $FF,$00 - dw AdjustOAMBlockYPos - -; facing up - db $01,$00 - dw AdjustOAMBlockYPos - -; facing left - db $01,$01 - dw AdjustOAMBlockXPos - -; facing right - db $FF,$01 - dw AdjustOAMBlockXPos - -LoadSmokeTileFourTimes:: - ld hl, vChars1 + $7c0 - ld c, $4 -.loop - push bc - push hl - call LoadSmokeTile - pop hl - ld bc, $10 - add hl, bc - pop bc - dec c - jr nz, .loop - ret - -LoadSmokeTile: - ld de, SSAnneSmokePuffTile - lb bc, BANK(SSAnneSmokePuffTile), (SSAnneSmokePuffTileEnd - SSAnneSmokePuffTile) / $10 - jp CopyVideoData - -SSAnneSmokePuffTile: - INCBIN "gfx/overworld/smoke.2bpp" -SSAnneSmokePuffTileEnd: diff --git a/engine/overworld/tileset_header.asm b/engine/overworld/tileset_header.asm deleted file mode 100644 index 6e33974f..00000000 --- a/engine/overworld/tileset_header.asm +++ /dev/null @@ -1,60 +0,0 @@ -LoadTilesetHeader: - call GetPredefRegisters - push hl - ld d, 0 - ld a, [wCurMapTileset] - add a - add a - ld b, a - add a - add b ; a = tileset * 12 - jr nc, .noCarry - inc d -.noCarry - ld e, a - ld hl, Tilesets - add hl, de - ld de, wTilesetBank - ld c, $b -.copyTilesetHeaderLoop - ld a, [hli] - ld [de], a - inc de - dec c - jr nz, .copyTilesetHeaderLoop - ld a, [hl] - ld [hTilesetType], a - xor a - ld [$ffd8], a - pop hl - ld a, [wCurMapTileset] - push hl - push de - ld hl, DungeonTilesets - ld de, $1 - call IsInArray - pop de - pop hl - jr c, .asm_c797 - ld a, [wCurMapTileset] - ld b, a - ld a, [hPreviousTileset] - cp b - jr z, .done -.asm_c797 - ld a, [wDestinationWarpID] - cp $ff - jr z, .done - call LoadDestinationWarpPosition - ld a, [wYCoord] - and $1 - ld [wYBlockCoord], a - ld a, [wXCoord] - and $1 - ld [wXBlockCoord], a -.done - ret - -INCLUDE "data/dungeon_tilesets.asm" - -INCLUDE "data/tileset_headers.asm" diff --git a/engine/overworld/tilesets.asm b/engine/overworld/tilesets.asm new file mode 100644 index 00000000..6e33974f --- /dev/null +++ b/engine/overworld/tilesets.asm @@ -0,0 +1,60 @@ +LoadTilesetHeader: + call GetPredefRegisters + push hl + ld d, 0 + ld a, [wCurMapTileset] + add a + add a + ld b, a + add a + add b ; a = tileset * 12 + jr nc, .noCarry + inc d +.noCarry + ld e, a + ld hl, Tilesets + add hl, de + ld de, wTilesetBank + ld c, $b +.copyTilesetHeaderLoop + ld a, [hli] + ld [de], a + inc de + dec c + jr nz, .copyTilesetHeaderLoop + ld a, [hl] + ld [hTilesetType], a + xor a + ld [$ffd8], a + pop hl + ld a, [wCurMapTileset] + push hl + push de + ld hl, DungeonTilesets + ld de, $1 + call IsInArray + pop de + pop hl + jr c, .asm_c797 + ld a, [wCurMapTileset] + ld b, a + ld a, [hPreviousTileset] + cp b + jr z, .done +.asm_c797 + ld a, [wDestinationWarpID] + cp $ff + jr z, .done + call LoadDestinationWarpPosition + ld a, [wYCoord] + and $1 + ld [wYBlockCoord], a + ld a, [wXCoord] + and $1 + ld [wXBlockCoord], a +.done + ret + +INCLUDE "data/dungeon_tilesets.asm" + +INCLUDE "data/tileset_headers.asm" diff --git a/engine/overworld/trainer_sight.asm b/engine/overworld/trainer_sight.asm new file mode 100755 index 00000000..5a68b627 --- /dev/null +++ b/engine/overworld/trainer_sight.asm @@ -0,0 +1,349 @@ +_GetSpritePosition1:: + ld hl, wSpriteStateData1 + ld de, $4 + ld a, [wSpriteIndex] + ld [H_SPRITEINDEX], a + call GetSpriteDataPointer + ld a, [hli] ; c1x4 (screen Y pos) + ld [$ffeb], a + inc hl + ld a, [hl] ; c1x6 (screen X pos) + ld [$ffec], a + ld de, (wSpriteStateData2 + $4) - (wSpriteStateData1 + $6) + add hl, de + ld a, [hli] ; c2x4 (map Y pos) + ld [$ffed], a + ld a, [hl] ; c2x5 (map X pos) + ld [$ffee], a + ret + +_GetSpritePosition2:: + ld hl, wSpriteStateData1 + ld de, $4 + ld a, [wSpriteIndex] + ld [H_SPRITEINDEX], a + call GetSpriteDataPointer + ld a, [hli] ; c1x4 (screen Y pos) + ld [wSavedSpriteScreenY], a + inc hl + ld a, [hl] ; c1x6 (screen X pos) + ld [wSavedSpriteScreenX], a + ld de, (wSpriteStateData2 + $4) - (wSpriteStateData1 + $6) + add hl, de + ld a, [hli] ; c2x4 (map Y pos) + ld [wSavedSpriteMapY], a + ld a, [hl] ; c2x5 (map X pos) + ld [wSavedSpriteMapX], a + ret + +_SetSpritePosition1:: + ld hl, wSpriteStateData1 + ld de, $4 + ld a, [wSpriteIndex] + ld [H_SPRITEINDEX], a + call GetSpriteDataPointer + ld a, [$ffeb] ; c1x4 (screen Y pos) + ld [hli], a + inc hl + ld a, [$ffec] ; c1x6 (screen X pos) + ld [hl], a + ld de, (wSpriteStateData2 + $4) - (wSpriteStateData1 + $6) + add hl, de + ld a, [$ffed] ; c2x4 (map Y pos) + ld [hli], a + ld a, [$ffee] ; c2x5 (map X pos) + ld [hl], a + ret + +_SetSpritePosition2:: + ld hl, wSpriteStateData1 + ld de, 4 + ld a, [wSpriteIndex] + ld [H_SPRITEINDEX], a + call GetSpriteDataPointer + ld a, [wSavedSpriteScreenY] + ld [hli], a ; c1x4 (screen Y pos) + inc hl + ld a, [wSavedSpriteScreenX] + ld [hl], a ; c1x6 (screen X pos) + ld de, (wSpriteStateData2 + $4) - (wSpriteStateData1 + $6) + add hl, de + ld a, [wSavedSpriteMapY] + ld [hli], a ; c2x4 (map Y pos) + ld a, [wSavedSpriteMapX] + ld [hl], a ; c2x5 (map X pos) + ret + +TrainerWalkUpToPlayer:: + ld a, [wSpriteIndex] + swap a + ld [wTrainerSpriteOffset], a + call ReadTrainerScreenPosition + ld a, [wTrainerFacingDirection] + and a ; SPRITE_FACING_DOWN + jr z, .facingDown + cp SPRITE_FACING_UP + jr z, .facingUp + cp SPRITE_FACING_LEFT + jr z, .facingLeft + jr .facingRight +.facingDown + ld a, [wTrainerScreenY] + ld b, a + ld a, $3c ; (fixed) player screen Y pos + call CalcDifference + cp $10 ; trainer is right above player + ret z + swap a + dec a + ld c, a ; bc = steps yet to go to reach player + xor a + ld b, a ; a = direction to go to + jr .writeWalkScript +.facingUp + ld a, [wTrainerScreenY] + ld b, a + ld a, $3c ; (fixed) player screen Y pos + call CalcDifference + cp $10 ; trainer is right below player + ret z + swap a + dec a + ld c, a ; bc = steps yet to go to reach player + ld b, $0 + ld a, $40 ; a = direction to go to + jr .writeWalkScript +.facingRight + ld a, [wTrainerScreenX] + ld b, a + ld a, $40 ; (fixed) player screen X pos + call CalcDifference + cp $10 ; trainer is directly left of player + ret z + swap a + dec a + ld c, a ; bc = steps yet to go to reach player + ld b, $0 + ld a, $c0 ; a = direction to go to + jr .writeWalkScript +.facingLeft + ld a, [wTrainerScreenX] + ld b, a + ld a, $40 ; (fixed) player screen X pos + call CalcDifference + cp $10 ; trainer is directly right of player + ret z + swap a + dec a + ld c, a ; bc = steps yet to go to reach player + ld b, $0 + ld a, $80 ; a = direction to go to +.writeWalkScript + ld hl, wNPCMovementDirections2 + ld de, wNPCMovementDirections2 + call FillMemory ; write the necessary steps to reach player + ld [hl], $ff ; write end of list sentinel + ld a, [wSpriteIndex] + ld [H_SPRITEINDEX], a + jp MoveSprite_ + +; input: de = offset within sprite entry +; output: hl = pointer to sprite data +GetSpriteDataPointer: + push de + add hl, de + ld a, [H_SPRITEINDEX] + swap a + ld d, $0 + ld e, a + add hl, de + pop de + ret + +; tests if this trainer is in the right position to engage the player and do so if she is. +TrainerEngage: + push hl + push de + ld a, [wTrainerSpriteOffset] + add $2 + ld d, $0 + ld e, a + ld hl, wSpriteStateData1 + add hl, de + ld a, [hl] ; c1x2: sprite image index + sub $ff + jr nz, .spriteOnScreen ; test if sprite is on screen + jp .noEngage +.spriteOnScreen + ld a, [wTrainerSpriteOffset] + add $9 + ld d, $0 + ld e, a + ld hl, wSpriteStateData1 + add hl, de + ld a, [hl] ; c1x9: facing direction + ld [wTrainerFacingDirection], a + call ReadTrainerScreenPosition + ld a, [wTrainerScreenY] ; sprite screen Y pos + ld b, a + ld a, $3c + cp b + jr z, .linedUpY + ld a, [wTrainerScreenX] ; sprite screen X pos + ld b, a + ld a, $40 + cp b + jr z, .linedUpX + xor a + jp .noEngage +.linedUpY + ld a, [wTrainerScreenX] ; sprite screen X pos + ld b, a + ld a, $40 ; (fixed) player X position + call CalcDifference ; calc distance + jr z, .noEngage ; exact same position as player + call CheckSpriteCanSeePlayer + jr c, .engage + xor a + jr .noEngage +.linedUpX + ld a, [wTrainerScreenY] ; sprite screen Y pos + ld b, a + ld a, $3c ; (fixed) player Y position + call CalcDifference ; calc distance + jr z, .noEngage ; exact same position as player + call CheckSpriteCanSeePlayer + jr c, .engage + xor a + jp .noEngage +.engage + call CheckPlayerIsInFrontOfSprite + ld a, [wTrainerSpriteOffset] + and a + jr z, .noEngage + ld hl, wFlags_0xcd60 + set 0, [hl] + call EngageMapTrainer + ld a, $ff +.noEngage + ld [wTrainerSpriteOffset], a + pop de + pop hl + ret + +; reads trainer's Y position to wTrainerScreenY and X position to wTrainerScreenX +ReadTrainerScreenPosition: + ld a, [wTrainerSpriteOffset] + add $4 + ld d, $0 + ld e, a + ld hl, wSpriteStateData1 + add hl, de + ld a, [hl] ; c1x4 (sprite Y pos) + ld [wTrainerScreenY], a + ld a, [wTrainerSpriteOffset] + add $6 + ld d, $0 + ld e, a + ld hl, wSpriteStateData1 + add hl, de + ld a, [hl] ; c1x6 (sprite X pos) + ld [wTrainerScreenX], a + ret + +; checks if the sprite is properly lined up with the player with respect to the direction it's looking. Also checks the distance between player and sprite +; note that this does not necessarily mean the sprite is seeing the player, he could be behind it's back +; a: distance player to sprite +CheckSpriteCanSeePlayer: + ld b, a + ld a, [wTrainerEngageDistance] ; how far the trainer can see + cp b + jr nc, .checkIfLinedUp + jr .notInLine ; player too far away +.checkIfLinedUp + ld a, [wTrainerFacingDirection] ; sprite facing direction + cp SPRITE_FACING_DOWN + jr z, .checkXCoord + cp SPRITE_FACING_UP + jr z, .checkXCoord + cp SPRITE_FACING_LEFT + jr z, .checkYCoord + cp SPRITE_FACING_RIGHT + jr z, .checkYCoord + jr .notInLine +.checkXCoord + ld a, [wTrainerScreenX] ; sprite screen X position + ld b, a + cp $40 + jr z, .inLine + jr .notInLine +.checkYCoord + ld a, [wTrainerScreenY] ; sprite screen Y position + ld b, a + cp $3c + jr nz, .notInLine +.inLine + scf + ret +.notInLine + and a + ret + +; tests if the player is in front of the sprite (rather than behind it) +CheckPlayerIsInFrontOfSprite: + ld a, [wCurMap] + cp POWER_PLANT + jp z, .engage ; bypass this for power plant to get voltorb fake items to work + ld a, [wTrainerSpriteOffset] + add $4 + ld d, $0 + ld e, a + ld hl, wSpriteStateData1 + add hl, de + ld a, [hl] ; c1x4 (sprite screen Y pos) + cp $fc + jr nz, .notOnTopmostTile ; special case if sprite is on topmost tile (Y = $fc (-4)), make it come down a block + ld a, $c +.notOnTopmostTile + ld [wTrainerScreenY], a + ld a, [wTrainerSpriteOffset] + add $6 + ld d, $0 + ld e, a + ld hl, wSpriteStateData1 + add hl, de + ld a, [hl] ; c1x6 (sprite screen X pos) + ld [wTrainerScreenX], a + ld a, [wTrainerFacingDirection] ; facing direction + cp SPRITE_FACING_DOWN + jr nz, .notFacingDown + ld a, [wTrainerScreenY] ; sprite screen Y pos + cp $3c + jr c, .engage ; sprite above player + jr .noEngage ; sprite below player +.notFacingDown + cp SPRITE_FACING_UP + jr nz, .notFacingUp + ld a, [wTrainerScreenY] ; sprite screen Y pos + cp $3c + jr nc, .engage ; sprite below player + jr .noEngage ; sprite above player +.notFacingUp + cp SPRITE_FACING_LEFT + jr nz, .notFacingLeft + ld a, [wTrainerScreenX] ; sprite screen X pos + cp $40 + jr nc, .engage ; sprite right of player + jr .noEngage ; sprite left of player +.notFacingLeft + ld a, [wTrainerScreenX] ; sprite screen X pos + cp $40 + jr nc, .noEngage ; sprite right of player +.engage + ld a, $ff + jr .done +.noEngage + xor a +.done + ld [wTrainerSpriteOffset], a + ret diff --git a/engine/overworld/trainers.asm b/engine/overworld/trainers.asm deleted file mode 100755 index 5a68b627..00000000 --- a/engine/overworld/trainers.asm +++ /dev/null @@ -1,349 +0,0 @@ -_GetSpritePosition1:: - ld hl, wSpriteStateData1 - ld de, $4 - ld a, [wSpriteIndex] - ld [H_SPRITEINDEX], a - call GetSpriteDataPointer - ld a, [hli] ; c1x4 (screen Y pos) - ld [$ffeb], a - inc hl - ld a, [hl] ; c1x6 (screen X pos) - ld [$ffec], a - ld de, (wSpriteStateData2 + $4) - (wSpriteStateData1 + $6) - add hl, de - ld a, [hli] ; c2x4 (map Y pos) - ld [$ffed], a - ld a, [hl] ; c2x5 (map X pos) - ld [$ffee], a - ret - -_GetSpritePosition2:: - ld hl, wSpriteStateData1 - ld de, $4 - ld a, [wSpriteIndex] - ld [H_SPRITEINDEX], a - call GetSpriteDataPointer - ld a, [hli] ; c1x4 (screen Y pos) - ld [wSavedSpriteScreenY], a - inc hl - ld a, [hl] ; c1x6 (screen X pos) - ld [wSavedSpriteScreenX], a - ld de, (wSpriteStateData2 + $4) - (wSpriteStateData1 + $6) - add hl, de - ld a, [hli] ; c2x4 (map Y pos) - ld [wSavedSpriteMapY], a - ld a, [hl] ; c2x5 (map X pos) - ld [wSavedSpriteMapX], a - ret - -_SetSpritePosition1:: - ld hl, wSpriteStateData1 - ld de, $4 - ld a, [wSpriteIndex] - ld [H_SPRITEINDEX], a - call GetSpriteDataPointer - ld a, [$ffeb] ; c1x4 (screen Y pos) - ld [hli], a - inc hl - ld a, [$ffec] ; c1x6 (screen X pos) - ld [hl], a - ld de, (wSpriteStateData2 + $4) - (wSpriteStateData1 + $6) - add hl, de - ld a, [$ffed] ; c2x4 (map Y pos) - ld [hli], a - ld a, [$ffee] ; c2x5 (map X pos) - ld [hl], a - ret - -_SetSpritePosition2:: - ld hl, wSpriteStateData1 - ld de, 4 - ld a, [wSpriteIndex] - ld [H_SPRITEINDEX], a - call GetSpriteDataPointer - ld a, [wSavedSpriteScreenY] - ld [hli], a ; c1x4 (screen Y pos) - inc hl - ld a, [wSavedSpriteScreenX] - ld [hl], a ; c1x6 (screen X pos) - ld de, (wSpriteStateData2 + $4) - (wSpriteStateData1 + $6) - add hl, de - ld a, [wSavedSpriteMapY] - ld [hli], a ; c2x4 (map Y pos) - ld a, [wSavedSpriteMapX] - ld [hl], a ; c2x5 (map X pos) - ret - -TrainerWalkUpToPlayer:: - ld a, [wSpriteIndex] - swap a - ld [wTrainerSpriteOffset], a - call ReadTrainerScreenPosition - ld a, [wTrainerFacingDirection] - and a ; SPRITE_FACING_DOWN - jr z, .facingDown - cp SPRITE_FACING_UP - jr z, .facingUp - cp SPRITE_FACING_LEFT - jr z, .facingLeft - jr .facingRight -.facingDown - ld a, [wTrainerScreenY] - ld b, a - ld a, $3c ; (fixed) player screen Y pos - call CalcDifference - cp $10 ; trainer is right above player - ret z - swap a - dec a - ld c, a ; bc = steps yet to go to reach player - xor a - ld b, a ; a = direction to go to - jr .writeWalkScript -.facingUp - ld a, [wTrainerScreenY] - ld b, a - ld a, $3c ; (fixed) player screen Y pos - call CalcDifference - cp $10 ; trainer is right below player - ret z - swap a - dec a - ld c, a ; bc = steps yet to go to reach player - ld b, $0 - ld a, $40 ; a = direction to go to - jr .writeWalkScript -.facingRight - ld a, [wTrainerScreenX] - ld b, a - ld a, $40 ; (fixed) player screen X pos - call CalcDifference - cp $10 ; trainer is directly left of player - ret z - swap a - dec a - ld c, a ; bc = steps yet to go to reach player - ld b, $0 - ld a, $c0 ; a = direction to go to - jr .writeWalkScript -.facingLeft - ld a, [wTrainerScreenX] - ld b, a - ld a, $40 ; (fixed) player screen X pos - call CalcDifference - cp $10 ; trainer is directly right of player - ret z - swap a - dec a - ld c, a ; bc = steps yet to go to reach player - ld b, $0 - ld a, $80 ; a = direction to go to -.writeWalkScript - ld hl, wNPCMovementDirections2 - ld de, wNPCMovementDirections2 - call FillMemory ; write the necessary steps to reach player - ld [hl], $ff ; write end of list sentinel - ld a, [wSpriteIndex] - ld [H_SPRITEINDEX], a - jp MoveSprite_ - -; input: de = offset within sprite entry -; output: hl = pointer to sprite data -GetSpriteDataPointer: - push de - add hl, de - ld a, [H_SPRITEINDEX] - swap a - ld d, $0 - ld e, a - add hl, de - pop de - ret - -; tests if this trainer is in the right position to engage the player and do so if she is. -TrainerEngage: - push hl - push de - ld a, [wTrainerSpriteOffset] - add $2 - ld d, $0 - ld e, a - ld hl, wSpriteStateData1 - add hl, de - ld a, [hl] ; c1x2: sprite image index - sub $ff - jr nz, .spriteOnScreen ; test if sprite is on screen - jp .noEngage -.spriteOnScreen - ld a, [wTrainerSpriteOffset] - add $9 - ld d, $0 - ld e, a - ld hl, wSpriteStateData1 - add hl, de - ld a, [hl] ; c1x9: facing direction - ld [wTrainerFacingDirection], a - call ReadTrainerScreenPosition - ld a, [wTrainerScreenY] ; sprite screen Y pos - ld b, a - ld a, $3c - cp b - jr z, .linedUpY - ld a, [wTrainerScreenX] ; sprite screen X pos - ld b, a - ld a, $40 - cp b - jr z, .linedUpX - xor a - jp .noEngage -.linedUpY - ld a, [wTrainerScreenX] ; sprite screen X pos - ld b, a - ld a, $40 ; (fixed) player X position - call CalcDifference ; calc distance - jr z, .noEngage ; exact same position as player - call CheckSpriteCanSeePlayer - jr c, .engage - xor a - jr .noEngage -.linedUpX - ld a, [wTrainerScreenY] ; sprite screen Y pos - ld b, a - ld a, $3c ; (fixed) player Y position - call CalcDifference ; calc distance - jr z, .noEngage ; exact same position as player - call CheckSpriteCanSeePlayer - jr c, .engage - xor a - jp .noEngage -.engage - call CheckPlayerIsInFrontOfSprite - ld a, [wTrainerSpriteOffset] - and a - jr z, .noEngage - ld hl, wFlags_0xcd60 - set 0, [hl] - call EngageMapTrainer - ld a, $ff -.noEngage - ld [wTrainerSpriteOffset], a - pop de - pop hl - ret - -; reads trainer's Y position to wTrainerScreenY and X position to wTrainerScreenX -ReadTrainerScreenPosition: - ld a, [wTrainerSpriteOffset] - add $4 - ld d, $0 - ld e, a - ld hl, wSpriteStateData1 - add hl, de - ld a, [hl] ; c1x4 (sprite Y pos) - ld [wTrainerScreenY], a - ld a, [wTrainerSpriteOffset] - add $6 - ld d, $0 - ld e, a - ld hl, wSpriteStateData1 - add hl, de - ld a, [hl] ; c1x6 (sprite X pos) - ld [wTrainerScreenX], a - ret - -; checks if the sprite is properly lined up with the player with respect to the direction it's looking. Also checks the distance between player and sprite -; note that this does not necessarily mean the sprite is seeing the player, he could be behind it's back -; a: distance player to sprite -CheckSpriteCanSeePlayer: - ld b, a - ld a, [wTrainerEngageDistance] ; how far the trainer can see - cp b - jr nc, .checkIfLinedUp - jr .notInLine ; player too far away -.checkIfLinedUp - ld a, [wTrainerFacingDirection] ; sprite facing direction - cp SPRITE_FACING_DOWN - jr z, .checkXCoord - cp SPRITE_FACING_UP - jr z, .checkXCoord - cp SPRITE_FACING_LEFT - jr z, .checkYCoord - cp SPRITE_FACING_RIGHT - jr z, .checkYCoord - jr .notInLine -.checkXCoord - ld a, [wTrainerScreenX] ; sprite screen X position - ld b, a - cp $40 - jr z, .inLine - jr .notInLine -.checkYCoord - ld a, [wTrainerScreenY] ; sprite screen Y position - ld b, a - cp $3c - jr nz, .notInLine -.inLine - scf - ret -.notInLine - and a - ret - -; tests if the player is in front of the sprite (rather than behind it) -CheckPlayerIsInFrontOfSprite: - ld a, [wCurMap] - cp POWER_PLANT - jp z, .engage ; bypass this for power plant to get voltorb fake items to work - ld a, [wTrainerSpriteOffset] - add $4 - ld d, $0 - ld e, a - ld hl, wSpriteStateData1 - add hl, de - ld a, [hl] ; c1x4 (sprite screen Y pos) - cp $fc - jr nz, .notOnTopmostTile ; special case if sprite is on topmost tile (Y = $fc (-4)), make it come down a block - ld a, $c -.notOnTopmostTile - ld [wTrainerScreenY], a - ld a, [wTrainerSpriteOffset] - add $6 - ld d, $0 - ld e, a - ld hl, wSpriteStateData1 - add hl, de - ld a, [hl] ; c1x6 (sprite screen X pos) - ld [wTrainerScreenX], a - ld a, [wTrainerFacingDirection] ; facing direction - cp SPRITE_FACING_DOWN - jr nz, .notFacingDown - ld a, [wTrainerScreenY] ; sprite screen Y pos - cp $3c - jr c, .engage ; sprite above player - jr .noEngage ; sprite below player -.notFacingDown - cp SPRITE_FACING_UP - jr nz, .notFacingUp - ld a, [wTrainerScreenY] ; sprite screen Y pos - cp $3c - jr nc, .engage ; sprite below player - jr .noEngage ; sprite above player -.notFacingUp - cp SPRITE_FACING_LEFT - jr nz, .notFacingLeft - ld a, [wTrainerScreenX] ; sprite screen X pos - cp $40 - jr nc, .engage ; sprite right of player - jr .noEngage ; sprite left of player -.notFacingLeft - ld a, [wTrainerScreenX] ; sprite screen X pos - cp $40 - jr nc, .noEngage ; sprite right of player -.engage - ld a, $ff - jr .done -.noEngage - xor a -.done - ld [wTrainerSpriteOffset], a - ret diff --git a/engine/overworld/turn_sprite.asm b/engine/overworld/turn_sprite.asm new file mode 100755 index 00000000..c7f7712b --- /dev/null +++ b/engine/overworld/turn_sprite.asm @@ -0,0 +1,25 @@ +UpdateSpriteFacingOffsetAndDelayMovement:: + ld h, $c2 + ld a, [H_CURRENTSPRITEOFFSET] + add $8 + ld l, a + ld a, $7f ; maximum movement delay + ld [hl], a ; c2x8 (movement delay) + dec h + ld a, [H_CURRENTSPRITEOFFSET] + add $9 + ld l, a + ld a, [hld] ; c1x9 (facing direction) + ld b, a + xor a + ld [hld], a + ld [hl], a ; c1x8 (walk animation frame) + ld a, [H_CURRENTSPRITEOFFSET] + add $2 + ld l, a + ld a, [hl] ; c1x2 (facing and animation table offset) + or b ; or in the facing direction + ld [hld], a + ld a, $2 ; delayed movement status + ld [hl], a ; c1x1 (movement status) + ret -- cgit v1.2.3