pokered/engine/overworld/cut.asm

252 lines
5.1 KiB
NASM
Raw Normal View History

2016-06-12 00:24:04 +00:00
UsedCut:
2014-05-22 22:13:20 +00:00
xor a
2015-07-15 06:16:06 +00:00
ld [wActionResultOrTookBattleTurn], a ; initialise to failure value
2015-08-31 02:38:41 +00:00
ld a, [wCurMapTileset]
2014-05-22 22:13:20 +00:00
and a ; OVERWORLD
2015-07-24 21:39:45 +00:00
jr z, .overworld
2014-05-22 22:13:20 +00:00
cp GYM
2015-07-24 21:39:45 +00:00
jr nz, .nothingToCut
2014-09-13 07:50:56 +00:00
ld a, [wTileInFrontOfPlayer]
2014-05-22 22:13:20 +00:00
cp $50 ; gym cut tree
2015-07-24 21:39:45 +00:00
jr nz, .nothingToCut
jr .canCut
.overworld
2014-05-22 22:13:20 +00:00
dec a
2014-09-13 07:50:56 +00:00
ld a, [wTileInFrontOfPlayer]
2014-05-22 22:13:20 +00:00
cp $3d ; cut tree
2015-07-24 21:39:45 +00:00
jr z, .canCut
2014-05-22 22:13:20 +00:00
cp $52 ; grass
2015-07-24 21:39:45 +00:00
jr z, .canCut
.nothingToCut
ld hl, .NothingToCutText
2014-05-22 22:13:20 +00:00
jp PrintText
.NothingToCutText
2014-05-22 22:13:20 +00:00
TX_FAR _NothingToCutText
db "@"
2015-07-24 21:39:45 +00:00
.canCut
2015-07-15 02:46:52 +00:00
ld [wCutTile], a
2015-07-24 21:39:45 +00:00
ld a, 1
2015-07-15 06:16:06 +00:00
ld [wActionResultOrTookBattleTurn], a ; used cut
ld a, [wWhichPokemon]
ld hl, wPartyMonNicks
2014-05-22 22:13:20 +00:00
call GetPartyMonName
ld hl, wd730
2014-05-22 22:13:20 +00:00
set 6, [hl]
call GBPalWhiteOutWithDelay3
2014-05-23 22:34:35 +00:00
call ClearSprites
call RestoreScreenTilesAndReloadTilePatterns
2015-07-24 21:39:45 +00:00
ld a, SCREEN_HEIGHT_PIXELS
2014-09-23 22:02:03 +00:00
ld [hWY], a
2014-05-22 22:13:20 +00:00
call Delay3
call LoadGBPal
call LoadCurrentMapView
call SaveScreenTilesToBuffer2
call Delay3
xor a
2014-09-23 22:02:03 +00:00
ld [hWY], a
2014-05-22 22:13:20 +00:00
ld hl, UsedCutText
call PrintText
call LoadScreenTilesFromBuffer2
ld hl, wd730
2014-05-22 22:13:20 +00:00
res 6, [hl]
ld a, $ff
2014-09-13 07:50:56 +00:00
ld [wUpdateSpritesEnabled], a
2015-07-24 21:39:45 +00:00
call InitCutAnimOAM
ld de, CutTreeBlockSwaps
2015-07-24 21:39:45 +00:00
call ReplaceTreeTileBlock
2014-09-14 18:29:18 +00:00
call RedrawMapView
2015-07-24 21:39:45 +00:00
callba AnimCut
2014-05-22 22:13:20 +00:00
ld a, $1
2014-09-13 07:50:56 +00:00
ld [wUpdateSpritesEnabled], a
2015-07-19 08:46:12 +00:00
ld a, SFX_CUT
2014-05-22 22:13:20 +00:00
call PlaySound
ld a, $90
2014-09-23 22:02:03 +00:00
ld [hWY], a
2014-05-22 22:13:20 +00:00
call UpdateSprites
2014-09-14 18:29:18 +00:00
jp RedrawMapView
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
UsedCutText:
2014-05-22 22:13:20 +00:00
TX_FAR _UsedCutText
db "@"
2016-06-12 00:24:04 +00:00
InitCutAnimOAM:
2014-05-22 22:13:20 +00:00
xor a
ld [wWhichAnimationOffsets], a
2016-06-12 04:30:05 +00:00
ld a, %11100100
ld [rOBP1], a
2015-07-15 02:46:52 +00:00
ld a, [wCutTile]
2014-05-22 22:13:20 +00:00
cp $52
2015-07-24 21:39:45 +00:00
jr z, .grass
; tree
ld de, Overworld_GFX + $2d0 ; cuttable tree sprite top row
2014-05-29 08:31:46 +00:00
ld hl, vChars1 + $7c0
2015-08-05 21:20:29 +00:00
lb bc, BANK(Overworld_GFX), $02
2014-05-22 22:13:20 +00:00
call CopyVideoData
ld de, Overworld_GFX + $3d0 ; cuttable tree sprite bottom row
2014-05-29 08:31:46 +00:00
ld hl, vChars1 + $7e0
2015-08-05 21:20:29 +00:00
lb bc, BANK(Overworld_GFX), $02
2014-05-22 22:13:20 +00:00
call CopyVideoData
2015-07-24 21:39:45 +00:00
jr WriteCutOrBoulderDustAnimationOAMBlock
.grass
2014-05-29 08:31:46 +00:00
ld hl, vChars1 + $7c0
2015-07-24 21:39:45 +00:00
call LoadCutGrassAnimationTilePattern
2014-05-29 08:31:46 +00:00
ld hl, vChars1 + $7d0
2015-07-24 21:39:45 +00:00
call LoadCutGrassAnimationTilePattern
2014-05-29 08:31:46 +00:00
ld hl, vChars1 + $7e0
2015-07-24 21:39:45 +00:00
call LoadCutGrassAnimationTilePattern
2014-05-29 08:31:46 +00:00
ld hl, vChars1 + $7f0
2015-07-24 21:39:45 +00:00
call LoadCutGrassAnimationTilePattern
call WriteCutOrBoulderDustAnimationOAMBlock
ld hl, wOAMBuffer + $93
2015-07-24 21:39:45 +00:00
ld de, 4
2014-05-22 22:13:20 +00:00
ld a, $30
ld c, e
2015-07-24 21:39:45 +00:00
.loop
2014-05-22 22:13:20 +00:00
ld [hl], a
add hl, de
xor $60
dec c
2015-07-24 21:39:45 +00:00
jr nz, .loop
2014-05-22 22:13:20 +00:00
ret
2016-06-12 00:24:04 +00:00
LoadCutGrassAnimationTilePattern:
ld de, AnimationTileset2 + $60 ; tile depicting a leaf
2015-08-05 21:20:29 +00:00
lb bc, BANK(AnimationTileset2), $01
2014-05-22 22:13:20 +00:00
jp CopyVideoData
2016-06-12 00:24:04 +00:00
WriteCutOrBoulderDustAnimationOAMBlock:
2015-07-24 21:39:45 +00:00
call GetCutOrBoulderDustAnimationOffsets
2014-05-22 22:13:20 +00:00
ld a, $9
2015-07-24 21:39:45 +00:00
ld de, CutOrBoulderDustAnimationTilesAndAttributes
2014-05-22 22:13:20 +00:00
jp WriteOAMBlock
2016-06-12 00:24:04 +00:00
CutOrBoulderDustAnimationTilesAndAttributes:
2014-05-22 22:13:20 +00:00
db $FC,$10,$FD,$10
db $FE,$10,$FF,$10
2016-06-12 00:24:04 +00:00
GetCutOrBoulderDustAnimationOffsets:
ld hl, wSpriteStateData1 + 4
ld a, [hli] ; player's sprite screen Y position
2014-05-22 22:13:20 +00:00
ld b, a
inc hl
ld a, [hli] ; player's sprite screen X position
2014-05-22 22:13:20 +00:00
ld c, a ; bc holds ypos/xpos of player's sprite
inc hl
inc hl
ld a, [hl] ; a holds direction of player (00: down, 04: up, 08: left, 0C: right)
srl a
ld e, a
ld d, $0 ; de holds direction (00: down, 02: up, 04: left, 06: right)
ld a, [wWhichAnimationOffsets]
2014-05-22 22:13:20 +00:00
and a
2015-07-24 21:39:45 +00:00
ld hl, CutAnimationOffsets
jr z, .next
ld hl, BoulderDustAnimationOffsets
2015-07-24 21:39:45 +00:00
.next
2014-05-22 22:13:20 +00:00
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
ld a, b
add d
ld b, a
ld a, c
add e
ld c, a
ret
2016-06-12 00:24:04 +00:00
CutAnimationOffsets:
2014-05-22 22:13:20 +00:00
; Each pair represents the x and y pixels offsets from the player of where the cut tree animation should be drawn
db 8, 36 ; player is facing down
db 8, 4 ; player is facing up
db -8, 20 ; player is facing left
db 24, 20 ; player is facing right
2016-06-12 00:24:04 +00:00
BoulderDustAnimationOffsets:
2014-05-22 22:13:20 +00:00
; Each pair represents the x and y pixels offsets from the player of where the cut tree animation should be drawn
; These offsets represent 2 blocks away from the player
db 8, 52 ; player is facing down
db 8, -12 ; player is facing up
db -24, 20 ; player is facing left
db 40, 20 ; player is facing right
2016-06-12 00:24:04 +00:00
ReplaceTreeTileBlock:
2015-07-24 21:39:45 +00:00
; Determine the address of the tile block that contains the tile in front of the
; player (i.e. where the tree is) and replace it with the corresponding tile
; block that doesn't have the tree.
2014-05-22 22:13:20 +00:00
push de
2015-08-31 02:38:41 +00:00
ld a, [wCurMapWidth]
2015-07-24 21:39:45 +00:00
add 6
2014-05-22 22:13:20 +00:00
ld c, a
2015-07-24 21:39:45 +00:00
ld b, 0
ld d, 0
2014-09-13 07:50:56 +00:00
ld hl, wCurrentTileBlockMapViewPointer
2014-05-22 22:13:20 +00:00
ld a, [hli]
ld h, [hl]
ld l, a
add hl, bc
2015-07-24 21:39:45 +00:00
ld a, [wSpriteStateData1 + 9] ; player sprite's facing direction
2014-05-22 22:13:20 +00:00
and a
jr z, .down
cp SPRITE_FACING_UP
jr z, .up
cp SPRITE_FACING_LEFT
jr z, .left
2015-07-24 21:39:45 +00:00
; right
2015-08-31 02:38:41 +00:00
ld a, [wXBlockCoord]
2014-05-22 22:13:20 +00:00
and a
2015-07-24 21:39:45 +00:00
jr z, .centerTileBlock
jr .rightOfCenter
.down
2015-08-31 02:38:41 +00:00
ld a, [wYBlockCoord]
2014-05-22 22:13:20 +00:00
and a
2015-07-24 21:39:45 +00:00
jr z, .centerTileBlock
jr .belowCenter
.up
2015-08-31 02:38:41 +00:00
ld a, [wYBlockCoord]
2014-05-22 22:13:20 +00:00
and a
2015-07-24 21:39:45 +00:00
jr z, .aboveCenter
jr .centerTileBlock
.left
2015-08-31 02:38:41 +00:00
ld a, [wXBlockCoord]
2014-05-22 22:13:20 +00:00
and a
2015-07-24 21:39:45 +00:00
jr z, .leftOfCenter
jr .centerTileBlock
.belowCenter
2014-05-22 22:13:20 +00:00
add hl, bc
2015-07-24 21:39:45 +00:00
.centerTileBlock
2014-05-22 22:13:20 +00:00
add hl, bc
2015-07-24 21:39:45 +00:00
.aboveCenter
2014-05-22 22:13:20 +00:00
ld e, $2
add hl, de
2015-07-24 21:39:45 +00:00
jr .next
.leftOfCenter
2014-05-22 22:13:20 +00:00
ld e, $1
add hl, bc
add hl, de
2015-07-24 21:39:45 +00:00
jr .next
.rightOfCenter
2014-05-22 22:13:20 +00:00
ld e, $3
add hl, bc
add hl, de
2015-07-24 21:39:45 +00:00
.next
2014-05-22 22:13:20 +00:00
pop de
ld a, [hl]
ld c, a
2015-07-24 21:39:45 +00:00
.loop ; find the matching tile block in the array
2014-05-22 22:13:20 +00:00
ld a, [de]
inc de
inc de
cp $ff
ret z
cp c
2015-07-24 21:39:45 +00:00
jr nz, .loop
2014-05-22 22:13:20 +00:00
dec de
2015-07-24 21:39:45 +00:00
ld a, [de] ; replacement tile block from matching array entry
2014-05-22 22:13:20 +00:00
ld [hl], a
ret
INCLUDE "data/tilesets/cut_tree_blocks.asm"