; MewUnderTruck: da81 ; RetPointer: dc0e ; MewBattleTextPointers: dc0f ; MewBattleText: dc11 ; AfterMewBattle: dc38 ; TruckOAM: dc61 ; MewBlankTile: dc81 ; CopyTruckTilesToVRAM: dc91 ; CopyTruckTileToVRAM: dc98 ; VermillionCityScriptHijack: d8ca _MewUnderTruck: ld a, [wd728] bit 0, a ; used strength? ret z predef GetTileAndCoordsInFrontOfPlayer ld a, [wYCoord] and a ret nz ; return if not at ycoord $00 ld a, e cp $15 ; are we at the right of the truck? lb de, PLAYER_DIR_LEFT, $3c ; facing and tile jr z, .correctCoords cp $14 ; are we at the left of the truck? ret nz lb de, PLAYER_DIR_RIGHT, $58 .correctCoords ld a, e cp c ; wTileInFrontOfPlayer ret nz ; return if we're not actually facing the truck ld a, [wPlayerMovingDirection] and a ret z ; return if we haven't moved cp d ret nz ; return if we're not facing the correct direction push af ; save direction for later ; truck tiles are: ; $48 $49 $4a $4b ; $58 $59 $3c $4c ; upper row ld hl, vTileset + $480 ld de, vNPCSprites + $780 ; use unused slot ld c, $4 push hl call CopyTruckTilesToVRAM ; bottom left pop hl set 0, h ; get vTileset + $580 ld c, $2 call CopyTruckTilesToVRAM ; bottom right ld hl, vTileset + $3c0 call CopyTruckTileToVRAM ld hl, vTileset + $4c0 call CopyTruckTileToVRAM ; write sprite stuff ld a, [wPlayerMovingDirection] cp PLAYER_DIR_RIGHT ld a, $d jr z, .rightAnimation ld a, $9 .rightAnimation ld [wSpriteStateData1 + $2], a ; walking frame call DelayFrame ld a, $ff ld [wUpdateSpritesEnabled], a ld hl, TruckOAM ld de, wOAMBuffer + 4 * 4 ld bc, TruckOAMEnd - TruckOAM push hl push bc call CopyData pop bc pop hl call CopyData ; copy tiles again so that white isn't seethrough ld hl, MewBlankTile ld de, vNPCSprites2 + $400 ld c, $1 call CopyTruckTileToVRAM ld hl, wOAMBuffer + 12 * 4 + 2 ; id, 8th entry ld de, $3 lb bc, $0, 8 ld a, $c0 .writeBlankTileLoop ld [hli], a ld [hl], b add hl, de dec c jr nz, .writeBlankTileLoop pop af cp PLAYER_DIR_LEFT jr z, .coordsAlreadyCorrect ; fix the coordinates so that they're relative to the player if facing right ld hl, wOAMBuffer + 4 * 4 + 1 ; x ld de, $4 lb bc, $30, 16 .shiftOffsetLoop ld a, b add [hl] ld [hl], a add hl, de dec c jr nz, .shiftOffsetLoop .coordsAlreadyCorrect ld a, [rOBP1] push af ld a, %11100100 ld [rOBP1], a callab ReplaceTreeTileBlock ; get address of tile in front of player ld [hl], $c ; replace block push hl ; save address for later callab RedrawMapView ld a, SFX_PUSH_BOULDER call PlaySound call DelayFrame ld a, [wPlayerMovingDirection] cp PLAYER_DIR_RIGHT ld b, $1 jr z, .continue ld b, -$1 .continue ld c, 16 ; 16 sprites ld hl, wOAMBuffer + 4 * 4 + 1 ld de, $4 ld a, $20 .moveTruckLoop push af push hl push bc .shiftTruck ld a, b add [hl] ld [hl], a add hl, de dec c jr nz, .shiftTruck pop bc pop hl call DelayFrame call DelayFrame pop af dec a jr nz, .moveTruckLoop pop hl ; restore address of truck ld a, [wPlayerMovingDirection] cp PLAYER_DIR_RIGHT ld [wSavedSpriteMapX+3], a ; unused wram inc hl jr z, .moveTruckToRight dec hl dec hl .moveTruckToRight ld [hl], $3 ; truck blocks ld a, l ld [wSavedSpriteMapX+1], a ; unused wram ld a, h ld [wSavedSpriteMapX+2], a callab RedrawMapView ld a, $1 ld [wUpdateSpritesEnabled], a ld [wNumSprites], a ld hl, wOAMBuffer + 4 * 4 lb bc, $a0, 16 ld de, $4 .hideSpritesLoop ld [hl], b add hl, de dec c jr nz, .hideSpritesLoop .waitForLYLoop ld a, [rLY] cp 72 jr c, .waitForLYLoop ; copy generic mon sprite to 4-tile portion ld hl, vNPCSprites + $400 ld de, vNPCSprites + $780 ld c, $4 call CopyTruckTilesToVRAM ; sprite pic ld a, $3d ; four tile sprite ld [wSpriteStateData1 + $10], a ld hl, wSpriteStateData2 + $14 ; coords ld a, $4 ld [hli], a ld a, $19 ld [hli], a ; movement byte ld [hl], $ff ; no moving ; sprite slot ld a, $b ld [wSpriteStateData2 + $1e], a pop af ld [rOBP1], a call DelayFrame ld a, [wUpdateSpritesEnabled] push af ld a, $ff ld [wUpdateSpritesEnabled], a ld a, [wSpriteStateData1 + $6] ; absolute x push af add $10 ld b, a ld a, [wPlayerMovingDirection] cp PLAYER_DIR_RIGHT ld a, b jr z, .adjustedOffset sub $10 + $10 .adjustedOffset ld [wSpriteStateData1 + $6], a callab AnimateBoulderDust pop af ld [wSpriteStateData1 + $6], a pop af ld [wUpdateSpritesEnabled], a ; change map text pointer ld hl, wMapTextPtr ld a, MewBattleTextPointers & $ff ld [hli], a ld a, MewBattleTextPointers / $100 ld [hli], a ; change map script pointer ld a, RetPointer & $ff ld [hli], a ld [hl], RetPointer / $100 RetPointer: ret MewBattleTextPointers: dw MewBattleText MewBattleText: text "Mew!@" TX_ASM ld a, MEW ld [wCurOpponent], a call PlayCry call WaitForSoundToFinish ld a, $5 ld [wCurEnemyLVL], a ld hl, wMapScriptPtr ld a, AfterMewBattle & $ff ld [hli], a ld [hl], AfterMewBattle / $100 ld hl, wCurMapTileset set 7, [hl] ; don't reload map script jp TextScriptEnd AfterMewBattle: xor a ld [wSpriteStateData1 + $10], a ; clear mew sprite ld hl, wSavedSpriteMapX + 3 ; saved walking direction ld a, [hld] ld b, a ld a, [hld] ld l, [hl] ld h, a ld [hl], $3 ; rewrite truck block ld a, b cp PLAYER_DIR_RIGHT dec hl jr z, .facingRight inc hl inc hl .facingRight ld [hl], $c callab RedrawMapView ld hl, wMapScriptPtr ld a, VermilionDockScript & $ff ld [hli], a ld [hl], VermilionDockScript / $100 ret TruckOAM: ; y, x, id, flags db $50,$28,$78,%10000 ; OBP1 db $50,$30,$79,%10000 db $50,$38,$7a,%10000 db $50,$40,$7b,%10000 db $58,$28,$7c,%10000 ; OBP1 db $58,$30,$7d,%10000 db $58,$38,$7e,%10000 db $58,$40,$7f,%10000 TruckOAMEnd: MewBlankTile: rept 8 db %11111111 db %00000000 endr CopyTruckTilesToVRAM: .copyTruckTilesloop call CopyTruckTileToVRAM dec c jr nz, .copyTruckTilesloop ret CopyTruckTileToVRAM: push bc lb bc, %11, $8 .waitForNonHBlank ld a, [rSTAT] and b jr z, .waitForNonHBlank .waitForHBlank ld a, [rSTAT] and b jr nz, .waitForHBlank ld a, [hli] ld [de], a inc de ld a, [hli] ld [de], a inc de dec c jr nz, .waitForNonHBlank pop bc ret _MewUnderTruckEnd: VermillionCityScriptHijack: ld a, [wWalkBikeSurfState] cp $2 jr nz, .keepMapHeightAndTilesetType ld a, $80 ld [wCurMapTileset], a ; allow hijacking boat mapscriptptr ld a, $10 ld [wCurMapHeight], a ; fix warps after .keepMapHeightAndTilesetType ld a, [wCurMap] cp VERMILION_DOCK jp nz, VermilionCityScript ld a, $ff ld [wJoyIgnore], a ld [rBGP], a ld [rOBP0], a ld [rOBP1], a pop hl ; return address for RunMapScript pop hl ; return address for JoypadOverworld call LoadMapData ld a, wBoxSpecies & $ff ld [wMapScriptPtr], a ld a, wBoxSpecies / $100 ld [wMapScriptPtr + 1], a jp $3ae ; EnterMap + $8 VermillionCityScriptHijackEnd: