Skip to content

Commit

Permalink
Merge pull request #26 from DanZC/master
Browse files Browse the repository at this point in the history
Adding multiple spikes layers
  • Loading branch information
SoupPotato authored Jul 25, 2024
2 parents 9aefb90 + 2265508 commit ad9cab2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
40 changes: 38 additions & 2 deletions engine/battle/core.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,7 @@ GetTwoThirdsMaxHP:
ld [hDivisor], a
ld b, 2
call Divide
GetTwoThirdsMaxHP_end:
ld a, [hQuotient + 2]
ld b, a
ld a, [hQuotient + 3]
Expand All @@ -1993,6 +1994,19 @@ GetTwoThirdsMaxHP:
.ok
ret

GetOneSixthMaxHP:
call GetMaxHP

ld a, b
ld [hDividend + 0], a
ld a, c
ld [hDividend + 1], a
ld a, 6
ld [hDivisor], a
ld b, 2
call Divide
jr GetTwoThirdsMaxHP_end

GetMaxHP:
; output: bc, wHPBuffer1

Expand Down Expand Up @@ -4242,6 +4256,22 @@ BreakAttraction:
res SUBSTATUS_IN_LOVE, [hl]
ret

GetSpikesDamage:
dec a
jr z, .one ; one spikes set
dec a
jr z, .two ; two spikes set
; assume three spikes set
.three
call GetQuarterMaxHP
ret
.two
call GetOneSixthMaxHP
ret
.one
call GetEighthMaxHP
ret

SpikesDamage:
ld hl, wPlayerScreens
ld de, wBattleMonType
Expand All @@ -4254,7 +4284,9 @@ SpikesDamage:
ld bc, UpdateEnemyHUD
.ok

bit SCREENS_SPIKES, [hl]
ld a, [hl]
and 3
; return if zero spikes set
ret z

; Flying-types aren't affected by Spikes.
Expand All @@ -4267,11 +4299,15 @@ SpikesDamage:
ret z

push bc
push hl

ld hl, BattleText_UserHurtBySpikes ; "hurt by SPIKES!"
call StdBattleTextbox

call GetEighthMaxHP
pop hl
ld a, [hl]
and 3
call GetSpikesDamage
call SubtractHPFromTarget

pop hl
Expand Down
7 changes: 5 additions & 2 deletions engine/battle/move_effects/rapid_spin.asm
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ BattleCommand_ClearHazards:
ld hl, wEnemyScreens
ld de, wEnemyWrapCount
.got_screens_wrap
bit SCREENS_SPIKES, [hl]
ld a, [hl]
and 3
jr z, .no_spikes
res SCREENS_SPIKES, [hl]
ld a, [hl]
and $fc ; Clear spike bits
ld [hl], a
ld hl, BlewSpikesText
push de
call StdBattleTextbox
Expand Down
15 changes: 12 additions & 3 deletions engine/battle/move_effects/spikes.asm
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@ BattleCommand_Spikes:

; Fails if spikes are already down!

bit SCREENS_SPIKES, [hl]
jr nz, .failed
ld a, [hl]
and 3
cp 3
jr nc, .failed

; Nothing else stops it from working.

set SCREENS_SPIKES, [hl]
push bc
inc a
ld b, a
ld a, [hl]
and $fc
or b
ld [hl], a
pop bc

call AnimateCurrentMove

Expand Down

0 comments on commit ad9cab2

Please sign in to comment.