Browse Source

Generalize player state

master
Forest Belton 2 years ago
parent
commit
a9f73eb8f8
2 changed files with 16 additions and 13 deletions
  1. +2
    -0
      inc/player.inc
  2. +14
    -13
      src/player.s

+ 2
- 0
inc/player.inc View File

@ -0,0 +1,2 @@
DEF PLAYER_STATEF_WALK EQU 0
DEF PLAYER_STATEF_JUMP EQU 1

+ 14
- 13
src/player.s View File

@ -1,5 +1,6 @@
INCLUDE "hardware.inc"
INCLUDE "oam.inc"
INCLUDE "player.inc"
INCLUDE "util.inc"
Section "Player Data", WRAM0
@ -9,7 +10,7 @@ PLAYER_X:: db
PLAYER_Y:: dw
PLAYER_DIR:: db
PLAYER_JUMPING:: db
PLAYER_STATE:: db
PLAYER_VY:: dw
Section "Player Code", ROM0
@ -57,20 +58,20 @@ Player_Update::
jr z, .jump_update_check
; initialize jump state if not already jumping
ld a, [PLAYER_JUMPING]
or a
ld a, [PLAYER_STATE]
cp PLAYER_STATEF_JUMP
jr nz, .jump_update
ld a, 1
ld [PLAYER_JUMPING], a
ld a, PLAYER_STATEF_JUMP
ld [PLAYER_STATE], a
ld hl, PLAYER_VY
STORE16 INIT_VY
; todo: deduplicate
.jump_update_check:
ld a, [PLAYER_JUMPING]
or a
ld a, [PLAYER_STATE]
cp PLAYER_STATEF_JUMP
jr z, .right
.jump_update:
@ -124,7 +125,7 @@ Player_Update::
call player_bg_collides
jr nz, .jump_rollback
; set PLAYER_JUMPING = 0 if VY < 0 (fell into ground)
; set PLAYER_STATE = PLAYER_STATEF_WALK if VY < 0 (fell into ground)
ld hl, PLAYER_VY
bit 7, [hl]
@ -136,8 +137,8 @@ Player_Update::
jr z, .jump_Player_UpdateOAM
xor a
ld [PLAYER_JUMPING], a
ld a, PLAYER_STATEF_WALK
ld [PLAYER_STATE], a
.jump_Player_UpdateOAM:
call Player_UpdateOAM
@ -216,12 +217,12 @@ Player_Update::
ret nz
; only set jump state if not already jumping
ld hl, PLAYER_JUMPING
ld hl, PLAYER_STATE
ld a, [hl]
or a
or PLAYER_STATEF_JUMP
ret nz
ld [hl], 1
ld [hl], PLAYER_STATEF_JUMP
ld hl, PLAYER_VY
STORE16 INIT_FALL_VY

Loading…
Cancel
Save