pokecrystal/engine/events/celebi.asm

380 lines
5.1 KiB
NASM
Raw Normal View History

2015-11-17 03:29:54 +00:00
Special_CelebiShrineEvent: ; 4989a
call DelayFrame
ld a, [VramState]
push af
xor a
ld [VramState], a
call LoadCelebiGFX
2015-11-18 18:01:55 +00:00
depixel 0, 10, 7, 0
ld a, SPRITE_ANIM_INDEX_CELEBI
2015-11-17 03:29:54 +00:00
call _InitSpriteAnimStruct
2015-12-05 20:38:25 +00:00
ld hl, SPRITEANIMSTRUCT_TILE_ID
2015-11-17 03:29:54 +00:00
add hl, bc
ld [hl], $84
2015-12-05 20:38:25 +00:00
ld hl, SPRITEANIMSTRUCT_ANIM_SEQ_ID
2015-11-17 03:29:54 +00:00
add hl, bc
ld [hl], SPRITE_ANIM_SEQ_CELEBI
2015-12-05 20:38:25 +00:00
ld hl, SPRITEANIMSTRUCT_0F
2015-11-17 03:29:54 +00:00
add hl, bc
ld a, $80
ld [hl], a
2015-12-05 20:38:25 +00:00
ld a, 160 ; frame count
2018-01-11 20:36:11 +00:00
ld [wFrameCounter], a
2015-11-17 03:29:54 +00:00
ld d, $0
.loop
ld a, [wJumptableIndex]
bit 7, a
jr nz, .done
push bc
2015-12-05 20:38:25 +00:00
call GetCelebiSpriteTile
2015-11-17 03:29:54 +00:00
inc d
push de
ld a, $90
2015-12-05 20:38:25 +00:00
ld [wCurrSpriteOAMAddr], a
2017-12-24 17:47:30 +00:00
farcall DoNextFrameForAllSprites
2015-12-05 20:38:25 +00:00
call CelebiEvent_CountDown
2015-11-17 03:29:54 +00:00
ld c, 2
call DelayFrames
pop de
pop bc
jr .loop
2015-12-05 20:38:25 +00:00
2015-11-17 03:29:54 +00:00
.done
pop af
ld [VramState], a
2018-01-10 18:47:57 +00:00
call .RestorePlayerSprite_DespawnLeaves
2015-12-05 20:38:25 +00:00
call CelebiEvent_SetBattleType
2015-11-17 03:29:54 +00:00
ret
2015-12-05 20:38:25 +00:00
2015-11-17 03:29:54 +00:00
; 498f9
2018-01-10 18:47:57 +00:00
.RestorePlayerSprite_DespawnLeaves: ; 498f9
ld hl, Sprite01TileID
2015-11-17 03:29:54 +00:00
xor a
2018-01-10 18:47:57 +00:00
ld c, 4
.OAMloop:
2018-01-10 18:47:57 +00:00
ld [hli], a ; tile id
rept SPRITEOAMSTRUCT_LENGTH +- 1
inc hl
2018-01-10 18:47:57 +00:00
endr
2015-11-17 03:29:54 +00:00
inc a
dec c
2015-12-05 20:38:25 +00:00
jr nz, .OAMloop
2018-01-10 18:47:57 +00:00
ld hl, Sprite05
ld bc, SpritesEnd - Sprite05
2015-11-17 03:29:54 +00:00
xor a
call ByteFill
ret
2015-12-05 20:38:25 +00:00
2015-11-17 03:29:54 +00:00
; 49912
LoadCelebiGFX: ; 49912
2017-12-24 17:47:30 +00:00
farcall ClearSpriteAnims
2015-11-17 03:29:54 +00:00
ld de, SpecialCelebiLeafGFX
2017-12-28 12:32:33 +00:00
ld hl, vTiles1
2015-11-17 03:29:54 +00:00
lb bc, BANK(SpecialCelebiLeafGFX), 4
call Request2bpp
ld de, SpecialCelebiGFX
2017-12-28 12:32:33 +00:00
ld hl, vTiles0 tile $84
2015-11-17 03:29:54 +00:00
lb bc, BANK(SpecialCelebiGFX), $10
call Request2bpp
xor a
ld [wJumptableIndex], a
ret
2015-12-05 20:38:25 +00:00
2015-11-17 03:29:54 +00:00
; 49935
2015-12-05 20:38:25 +00:00
CelebiEvent_CountDown: ; 49935
2018-01-11 20:36:11 +00:00
ld hl, wFrameCounter
2015-11-17 03:29:54 +00:00
ld a, [hl]
and a
2015-12-05 20:38:25 +00:00
jr z, .done
2015-11-17 03:29:54 +00:00
dec [hl]
ret
2015-12-05 20:38:25 +00:00
.done
2015-11-17 03:29:54 +00:00
ld hl, wJumptableIndex
set 7, [hl]
ret
2015-12-05 20:38:25 +00:00
2015-11-17 03:29:54 +00:00
; 49944
2015-12-05 20:38:25 +00:00
CelebiEvent_SpawnLeaf: ; 49944
; unused
2015-11-17 03:29:54 +00:00
ld hl, wcf65
ld a, [hl]
inc [hl]
and $7
ret nz
ld a, [hl]
and $18
sla a
add $40
ld d, a
ld e, $0
2015-12-19 01:07:09 +00:00
ld a, SPRITE_ANIM_INDEX_FLY_LEAF ; fly land
2015-11-17 03:29:54 +00:00
call _InitSpriteAnimStruct
2015-12-05 20:38:25 +00:00
ld hl, SPRITEANIMSTRUCT_TILE_ID
2015-11-17 03:29:54 +00:00
add hl, bc
ld [hl], $80
ret
2015-12-05 20:38:25 +00:00
2015-11-17 03:29:54 +00:00
; 49962
SpecialCelebiLeafGFX: ; 49962
2017-12-16 17:09:16 +00:00
INCBIN "gfx/overworld/cut_grass.2bpp"
2015-11-17 03:29:54 +00:00
SpecialCelebiGFX: ; 499a2
2017-12-16 17:09:16 +00:00
INCBIN "gfx/overworld/celebi/1.2bpp"
INCBIN "gfx/overworld/celebi/2.2bpp"
INCBIN "gfx/overworld/celebi/3.2bpp"
INCBIN "gfx/overworld/celebi/4.2bpp"
2015-11-17 03:29:54 +00:00
2015-12-05 20:38:25 +00:00
UpdateCelebiPosition: ; 49aa2 (12:5aa2)
ld hl, SPRITEANIMSTRUCT_XOFFSET
2015-11-17 03:29:54 +00:00
add hl, bc
ld a, [hl]
push af
2015-12-05 20:38:25 +00:00
ld hl, SPRITEANIMSTRUCT_YCOORD
2015-11-17 03:29:54 +00:00
add hl, bc
ld a, [hl]
2015-12-05 20:38:25 +00:00
cp 8 * 10 + 2
jp nc, .FreezeCelebiPosition
ld hl, SPRITEANIMSTRUCT_YCOORD
2015-11-17 03:29:54 +00:00
add hl, bc
inc [hl]
2015-12-05 20:38:25 +00:00
ld hl, SPRITEANIMSTRUCT_0F
2015-11-17 03:29:54 +00:00
add hl, bc
ld a, [hl]
ld d, a
cp $3a
2015-12-05 20:38:25 +00:00
jr c, .skip
jr z, .skip
2015-11-17 03:29:54 +00:00
sub $3
ld [hl], a
2015-12-05 20:38:25 +00:00
.skip
ld hl, SPRITEANIMSTRUCT_0E
2015-11-17 03:29:54 +00:00
add hl, bc
ld a, [hl]
inc [hl]
call CelebiEvent_Cosine
2015-12-05 20:38:25 +00:00
ld hl, SPRITEANIMSTRUCT_XOFFSET
2015-11-17 03:29:54 +00:00
add hl, bc
ld [hl], a
ld d, a
2015-12-05 20:38:25 +00:00
ld hl, SPRITEANIMSTRUCT_XCOORD
2015-11-17 03:29:54 +00:00
add hl, bc
add [hl]
2015-12-05 20:38:25 +00:00
cp 8 * 11 + 4
jr nc, .ShiftY
cp 8 * 8 + 4
jr nc, .ReinitSpriteAnimFrame
.ShiftY:
2015-11-17 03:29:54 +00:00
pop af
push af
cp d
2015-12-05 20:38:25 +00:00
jr nc, .moving_left
ld hl, SPRITEANIMSTRUCT_XCOORD
2015-11-17 03:29:54 +00:00
add hl, bc
add [hl]
2015-12-05 20:38:25 +00:00
cp 8 * 10
jr c, .float_up
jr .float_down
.moving_left
ld hl, SPRITEANIMSTRUCT_XCOORD
2015-11-17 03:29:54 +00:00
add hl, bc
add [hl]
2015-12-05 20:38:25 +00:00
cp 8 * 10
jr nc, .float_up
.float_down
ld hl, SPRITEANIMSTRUCT_YCOORD
2015-11-17 03:29:54 +00:00
add hl, bc
ld a, [hl]
sub $2
ld [hl], a
2015-12-05 20:38:25 +00:00
jr .ReinitSpriteAnimFrame
.float_up
ld hl, SPRITEANIMSTRUCT_YCOORD
2015-11-17 03:29:54 +00:00
add hl, bc
ld a, [hl]
add $1
ld [hl], a
.ReinitSpriteAnimFrame:
2015-11-17 03:29:54 +00:00
pop af
2015-12-05 20:38:25 +00:00
ld hl, SPRITEANIMSTRUCT_XCOORD
2015-11-17 03:29:54 +00:00
add hl, bc
add [hl]
2015-12-05 20:38:25 +00:00
cp 8 * 10
jr c, .left
cp -(8 * 3 + 2)
jr nc, .left
ld hl, SPRITEANIMSTRUCT_FRAMESET_ID
2015-11-17 03:29:54 +00:00
add hl, bc
ld a, SPRITE_ANIM_FRAMESET_CELEBI_RIGHT
2015-12-05 20:38:25 +00:00
call ReinitSpriteAnimFrame
jr .done
.left
ld hl, SPRITEANIMSTRUCT_FRAMESET_ID
2015-11-17 03:29:54 +00:00
add hl, bc
ld a, SPRITE_ANIM_FRAMESET_CELEBI_LEFT
2015-12-05 20:38:25 +00:00
call ReinitSpriteAnimFrame
.done
2015-11-17 03:29:54 +00:00
ret
2015-12-05 20:38:25 +00:00
.FreezeCelebiPosition: ; 49b30 (12:5b30)
2015-11-17 03:29:54 +00:00
pop af
2015-12-05 20:38:25 +00:00
ld hl, SPRITEANIMSTRUCT_FRAMESET_ID
2015-11-17 03:29:54 +00:00
add hl, bc
ld a, SPRITE_ANIM_FRAMESET_CELEBI_LEFT
2015-12-05 20:38:25 +00:00
call ReinitSpriteAnimFrame
2015-11-17 03:29:54 +00:00
ret
2015-12-05 20:38:25 +00:00
CelebiEvent_Cosine: ; 49b3b (12:5b3b)
2018-01-09 21:39:36 +00:00
; a = d * cos(a * pi/32)
add %010000
and %111111
cp %100000
2015-12-07 03:36:09 +00:00
jr nc, .negative
2018-01-09 21:39:36 +00:00
call .ApplySineWave
2015-11-17 03:29:54 +00:00
ld a, h
ret
2015-12-05 20:38:25 +00:00
2015-12-07 03:36:09 +00:00
.negative
2018-01-09 21:39:36 +00:00
and %011111
call .ApplySineWave
2015-11-17 03:29:54 +00:00
ld a, h
xor $ff
inc a
ret
2018-01-09 21:39:36 +00:00
.ApplySineWave: ; 49b52 (12:5b52)
2015-11-17 03:29:54 +00:00
ld e, a
ld a, d
2018-01-09 21:39:36 +00:00
ld d, 0
ld hl, .sinewave
2015-11-17 03:29:54 +00:00
add hl, de
add hl, de
2015-11-17 03:29:54 +00:00
ld e, [hl]
inc hl
ld d, [hl]
ld hl, 0
.multiply
2015-11-17 03:29:54 +00:00
srl a
jr nc, .even
2015-11-17 03:29:54 +00:00
add hl, de
.even
2015-11-17 03:29:54 +00:00
sla e
rl d
and a
jr nz, .multiply
2015-11-17 03:29:54 +00:00
ret
; 49b6e (12:5b6e)
.sinewave ; 49b6e
2015-11-17 03:29:54 +00:00
sine_wave $100
; 49bae
2015-12-05 20:38:25 +00:00
GetCelebiSpriteTile: ; 49bae
2015-11-17 03:29:54 +00:00
push hl
push bc
push de
ld a, d
ld d, $3
ld e, d
cp $0
2015-12-05 20:38:25 +00:00
jr z, .Frame1
2015-11-17 03:29:54 +00:00
cp d
2015-12-05 20:38:25 +00:00
jr z, .Frame2
call .AddE
2015-11-17 03:29:54 +00:00
cp d
2015-12-05 20:38:25 +00:00
jr z, .Frame3
call .AddE
2015-11-17 03:29:54 +00:00
cp d
2015-12-05 20:38:25 +00:00
jr z, .Frame4
call .AddE
2015-11-17 03:29:54 +00:00
cp d
2015-12-05 20:38:25 +00:00
jr c, .done
jr .restart
2015-11-17 03:29:54 +00:00
.Frame1:
2015-11-17 03:29:54 +00:00
ld a, $84
2015-12-05 20:38:25 +00:00
jr .load_tile
2015-11-17 03:29:54 +00:00
2015-12-05 20:38:25 +00:00
.Frame2:
2015-11-17 03:29:54 +00:00
ld a, $88
2015-12-05 20:38:25 +00:00
jr .load_tile
2015-11-17 03:29:54 +00:00
.Frame3:
2015-11-17 03:29:54 +00:00
ld a, $8c
2015-12-05 20:38:25 +00:00
jr .load_tile
2015-11-17 03:29:54 +00:00
2015-12-05 20:38:25 +00:00
.Frame4:
2015-11-17 03:29:54 +00:00
ld a, $90
2015-12-05 20:38:25 +00:00
.load_tile
ld hl, SPRITEANIMSTRUCT_TILE_ID
2015-11-17 03:29:54 +00:00
add hl, bc
ld [hl], a
2015-12-05 20:38:25 +00:00
jr .done
2015-11-17 03:29:54 +00:00
2015-12-05 20:38:25 +00:00
.restart
2015-11-17 03:29:54 +00:00
pop de
ld d, $ff
push de
2015-12-05 20:38:25 +00:00
.done
2015-11-17 03:29:54 +00:00
pop de
pop bc
pop hl
ret
2015-12-05 20:38:25 +00:00
2015-11-17 03:29:54 +00:00
; 49bed
2015-12-05 20:38:25 +00:00
.AddE: ; 49bed
2015-11-17 03:29:54 +00:00
push af
ld a, d
add e
ld d, a
pop af
ret
2015-12-05 20:38:25 +00:00
2015-11-17 03:29:54 +00:00
; 49bf3
2015-12-05 20:38:25 +00:00
CelebiEvent_SetBattleType: ; 49bf3
2015-11-17 03:29:54 +00:00
ld a, BATTLETYPE_CELEBI
ld [BattleType], a
ret
2015-12-05 20:38:25 +00:00
2015-11-17 03:29:54 +00:00
; 49bf9
2015-11-17 17:29:37 +00:00
CheckCaughtCelebi: ; 49bf9
2015-11-17 03:29:54 +00:00
ld a, [wBattleResult]
bit 6, a
2015-11-17 17:29:37 +00:00
jr z, .false
2015-11-17 03:29:54 +00:00
ld a, $1
ld [ScriptVar], a
2015-11-17 17:29:37 +00:00
jr .done
2015-11-17 03:29:54 +00:00
2015-12-05 20:38:25 +00:00
2015-11-17 17:29:37 +00:00
.false
2015-11-17 03:29:54 +00:00
xor a
ld [ScriptVar], a
2015-11-17 17:29:37 +00:00
.done
2015-11-17 03:29:54 +00:00
ret
2015-12-05 20:38:25 +00:00
2015-11-17 03:29:54 +00:00
; 49c0c