feat: add boost, fix: make velocity work
parent
57b27449a4
commit
f136045f58
67
main.asm
67
main.asm
|
@ -79,6 +79,11 @@ WaitVBlank:
|
|||
ld a, $0
|
||||
ld [wMetaspriteVelocity.z + 1], a
|
||||
|
||||
ld hl, wMetaspriteVelocity.boost
|
||||
ld a, $0
|
||||
ld [wMetaspriteVelocity.boost], a
|
||||
ld [wMetaspriteVelocity.boosting], a
|
||||
|
||||
; Copy the tile data
|
||||
ld de, Tiles
|
||||
ld hl, $9000
|
||||
|
@ -179,19 +184,42 @@ HandleInput::
|
|||
ld [wMetaspritePosition.y+1], a
|
||||
.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]
|
||||
bit PADB_A, a
|
||||
jr z, .jumpend
|
||||
jr z, .boostclear
|
||||
|
||||
ld a, [wMetaspriteVelocity.z]
|
||||
sub a, $F0
|
||||
sub a, $20
|
||||
ld b, a
|
||||
ld [wMetaspriteVelocity.z], a
|
||||
ld a, [wMetaspriteVelocity.z+1]
|
||||
sbc a, $00
|
||||
ld c, a
|
||||
ld [wMetaspriteVelocity.z+1], a
|
||||
jr .boostend
|
||||
.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
|
||||
|
||||
HandleRender::
|
||||
|
@ -241,12 +269,24 @@ HandlePhysics::
|
|||
ld b, a
|
||||
ld a, [wMetaspritePosition.z + 1]
|
||||
or a, b
|
||||
cp 0
|
||||
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
|
||||
ld a, [wMetaspriteVelocity.z]
|
||||
add a, $02
|
||||
add a, $04
|
||||
ld [wMetaspriteVelocity.z], a
|
||||
ld a, [wMetaspriteVelocity.z+1]
|
||||
adc a, $00
|
||||
|
@ -259,23 +299,24 @@ HandlePhysics::
|
|||
ld c, a
|
||||
ld a, [wMetaspritePosition.z]
|
||||
add c
|
||||
ld c, a
|
||||
ld a, [wMetaspriteVelocity.z + 1]
|
||||
ld b, a
|
||||
ld a, [wMetaspritePosition.z + 1]
|
||||
adc b
|
||||
ld b, a
|
||||
|
||||
; If z is greater than or equal to 0, pos/vel to 0
|
||||
jr nz, .endLanding1
|
||||
jr nc, .endLanding1
|
||||
jr nz, .endLanding
|
||||
jr nc, .endLanding
|
||||
.startLanding
|
||||
ld a, 0
|
||||
ld [wMetaspritePosition.z], a
|
||||
ld [wMetaspritePosition.z+1], a
|
||||
ld [wMetaspriteVelocity.z], a
|
||||
ld [wMetaspriteVelocity.z+1], a
|
||||
ld c, 0
|
||||
ld b, 0
|
||||
jr .endLanding
|
||||
.endLanding1
|
||||
nop
|
||||
ld b, a
|
||||
ld c, a
|
||||
.endLanding
|
||||
|
||||
; Update z position
|
||||
|
@ -507,6 +548,10 @@ wMetaspriteVelocity::
|
|||
dw
|
||||
.z:
|
||||
dw
|
||||
.boost:
|
||||
db
|
||||
.boosting:
|
||||
db
|
||||
|
||||
SECTION "Joypad Vars", WRAM0
|
||||
wJoypadState:
|
||||
|
|
Loading…
Reference in New Issue