Browse Source

Cap velocity at 7px/frame

master
Forest Belton 3 years ago
parent
commit
424b80e28c
2 changed files with 24 additions and 1 deletions
  1. +9
    -0
      inc/util.inc
  2. +15
    -1
      src/player.s

+ 9
- 0
inc/util.inc View File

@ -77,3 +77,12 @@ MACRO CP16
cp LOW(\1)
.done\@
ENDM
; A = MIN(A, x)
; \1 Other value
MACRO MIN
cp \1
jr c, .skip\@
ld a, \1
.skip\@:
ENDM

+ 15
- 1
src/player.s View File

@ -32,7 +32,8 @@ DEF TILE_SIZE EQU 16 ; Total length of tile in bytes
DEF GRAVITY EQU (0 << 8) | $2e ; 0.18
DEF INIT_VY EQU (3 << 8) | $99 ; 3.60
DEF INIT_FALL_VY EQU ($ff << 8) | $1a ; a.b
DEF INIT_FALL_VY EQU ($ff << 8) | $1a ; -1.1015625
DEF MAX_VY EQU ($f9 << 8) | $00 ; -7.0
Player_Init::
; Clear player data (X/Y initialized by map engine)
@ -91,6 +92,19 @@ Player_Update::
sbc HIGH(GRAVITY)
ld b, a
; we only need to clamp when moving down
bit 7, b
jr z, .no_clamp
; vy = MIN(MAX_VY, vy)
ld a, b
cp HIGH(MAX_VY)
jr c, .no_clamp
ld b, HIGH(MAX_VY)
ld c, LOW(MAX_VY)
.no_clamp:
ld hl, PLAYER_VY
STORE16 bc

Loading…
Cancel
Save