feat: add boost, fix: make velocity work

main
Louis Pearson 2024-04-19 15:05:59 -06:00
parent 57b27449a4
commit f136045f58
1 changed files with 56 additions and 11 deletions

View File

@ -79,6 +79,11 @@ WaitVBlank:
ld a, $0 ld a, $0
ld [wMetaspriteVelocity.z + 1], a ld [wMetaspriteVelocity.z + 1], a
ld hl, wMetaspriteVelocity.boost
ld a, $0
ld [wMetaspriteVelocity.boost], a
ld [wMetaspriteVelocity.boosting], a
; Copy the tile data ; Copy the tile data
ld de, Tiles ld de, Tiles
ld hl, $9000 ld hl, $9000
@ -179,19 +184,42 @@ HandleInput::
ld [wMetaspritePosition.y+1], a ld [wMetaspritePosition.y+1], a
.downend: .downend:
; Skip jump code if not on ground
ld a, [wMetaspritePosition.z]
ld b, a
ld a, [wMetaspritePosition.z + 1]
or a, b
jr nz, .jumpend
; While on ground, set boost
ld a, $8
ld [wMetaspriteVelocity.boost], a
ld a, [wJoypadPressed] ld a, [wJoypadPressed]
bit PADB_A, a bit PADB_A, a
jr z, .jumpend jr z, .boostclear
ld a, [wMetaspriteVelocity.z] ld a, [wMetaspriteVelocity.z]
sub a, $F0 sub a, $20
ld b, a ld b, a
ld [wMetaspriteVelocity.z], a ld [wMetaspriteVelocity.z], a
ld a, [wMetaspriteVelocity.z+1] ld a, [wMetaspriteVelocity.z+1]
sbc a, $00 sbc a, $00
ld c, a ld c, a
ld [wMetaspriteVelocity.z+1], a ld [wMetaspriteVelocity.z+1], a
jr .boostend
.jumpend: .jumpend:
ld a, [wJoypadState]
bit PADB_A, a
jr z, .boostclear
ld a, $FF
ld [wMetaspriteVelocity.boosting], a
jr .boostend
.boostclear:
ld a, $00
ld [wMetaspriteVelocity.boosting], a
.boostend:
ret ret
HandleRender:: HandleRender::
@ -241,12 +269,24 @@ HandlePhysics::
ld b, a ld b, a
ld a, [wMetaspritePosition.z + 1] ld a, [wMetaspritePosition.z + 1]
or a, b or a, b
cp 0
jr z, .endGravity jr z, .endGravity
; Skip gravity if boosting
ld a, [wMetaspriteVelocity.boosting]
ld b, a
ld a, [wMetaspriteVelocity.boost]
and a, b
cp 0
jr z, .startGravity
ld a, [wMetaspriteVelocity.boost]
dec a
ld [wMetaspriteVelocity.boost], a
jr .endGravity
.startGravity
; Apply gravity ; Apply gravity
ld a, [wMetaspriteVelocity.z] ld a, [wMetaspriteVelocity.z]
add a, $02 add a, $04
ld [wMetaspriteVelocity.z], a ld [wMetaspriteVelocity.z], a
ld a, [wMetaspriteVelocity.z+1] ld a, [wMetaspriteVelocity.z+1]
adc a, $00 adc a, $00
@ -259,23 +299,24 @@ HandlePhysics::
ld c, a ld c, a
ld a, [wMetaspritePosition.z] ld a, [wMetaspritePosition.z]
add c add c
ld c, a
ld a, [wMetaspriteVelocity.z + 1] ld a, [wMetaspriteVelocity.z + 1]
ld b, a ld b, a
ld a, [wMetaspritePosition.z + 1] ld a, [wMetaspritePosition.z + 1]
adc b adc b
ld b, a
; If z is greater than or equal to 0, pos/vel to 0 ; If z is greater than or equal to 0, pos/vel to 0
jr nz, .endLanding1 jr nz, .endLanding
jr nc, .endLanding1 jr nc, .endLanding
.startLanding .startLanding
ld a, 0 ld a, 0
ld [wMetaspritePosition.z], a
ld [wMetaspritePosition.z+1], a
ld [wMetaspriteVelocity.z], a ld [wMetaspriteVelocity.z], a
ld [wMetaspriteVelocity.z+1], a ld [wMetaspriteVelocity.z+1], a
ld c, 0 ld b, a
ld b, 0 ld c, a
jr .endLanding
.endLanding1
nop
.endLanding .endLanding
; Update z position ; Update z position
@ -507,6 +548,10 @@ wMetaspriteVelocity::
dw dw
.z: .z:
dw dw
.boost:
db
.boosting:
db
SECTION "Joypad Vars", WRAM0 SECTION "Joypad Vars", WRAM0
wJoypadState: wJoypadState: