|
@ -15,7 +15,6 @@ PLAYER_DIR:: db |
|
|
|
|
|
|
|
|
PLAYER_JUMPING:: db |
|
|
PLAYER_JUMPING:: db |
|
|
PLAYER_VY:: dw |
|
|
PLAYER_VY:: dw |
|
|
PLAYER_OLD_Y: db |
|
|
|
|
|
|
|
|
|
|
|
Section "Player Code", ROM0 |
|
|
Section "Player Code", ROM0 |
|
|
|
|
|
|
|
@ -26,6 +25,7 @@ DEF SPRITE_OAM_IDX EQU 0 |
|
|
DEF SPRITE_IDX EQU 32 ; tile index, rename later |
|
|
DEF SPRITE_IDX EQU 32 ; tile index, rename later |
|
|
DEF SPRITE_WIDTH EQU 2 |
|
|
DEF SPRITE_WIDTH EQU 2 |
|
|
DEF SPRITE_HEIGHT EQU 2 |
|
|
DEF SPRITE_HEIGHT EQU 2 |
|
|
|
|
|
DEF PLAYER_SPEED EQU 2 |
|
|
|
|
|
|
|
|
DEF GRAVITY EQU (0 << 8) | 8 |
|
|
DEF GRAVITY EQU (0 << 8) | 8 |
|
|
DEF INIT_VY EQU (2 << 8) | 40 |
|
|
DEF INIT_VY EQU (2 << 8) | 40 |
|
@ -63,13 +63,13 @@ Player_Update:: |
|
|
; check for jump |
|
|
; check for jump |
|
|
ld a, b |
|
|
ld a, b |
|
|
and BTN_UP |
|
|
and BTN_UP |
|
|
jr z, .update_jump |
|
|
|
|
|
|
|
|
jr z, .jump_update_check |
|
|
|
|
|
|
|
|
; initialize jump state if not already jumping |
|
|
; initialize jump state if not already jumping |
|
|
ld hl, PLAYER_JUMPING |
|
|
ld hl, PLAYER_JUMPING |
|
|
ld a, [hl] |
|
|
ld a, [hl] |
|
|
or a |
|
|
or a |
|
|
jr nz, .update_jump |
|
|
|
|
|
|
|
|
jr nz, .jump_update |
|
|
|
|
|
|
|
|
ld [hl], 1 |
|
|
ld [hl], 1 |
|
|
|
|
|
|
|
@ -78,12 +78,14 @@ Player_Update:: |
|
|
inc hl |
|
|
inc hl |
|
|
ld [hl], LOW(INIT_VY) |
|
|
ld [hl], LOW(INIT_VY) |
|
|
|
|
|
|
|
|
.update_jump: |
|
|
|
|
|
|
|
|
; todo: deduplicate |
|
|
|
|
|
.jump_update_check: |
|
|
ld hl, PLAYER_JUMPING |
|
|
ld hl, PLAYER_JUMPING |
|
|
ld a, [hl] |
|
|
ld a, [hl] |
|
|
or a |
|
|
or a |
|
|
jr z, .right |
|
|
jr z, .right |
|
|
|
|
|
|
|
|
|
|
|
.jump_update: |
|
|
; load y velocity into bc |
|
|
; load y velocity into bc |
|
|
ld hl, PLAYER_VY |
|
|
ld hl, PLAYER_VY |
|
|
ld b, [hl] |
|
|
ld b, [hl] |
|
@ -101,12 +103,6 @@ Player_Update:: |
|
|
ld hl, PLAYER_VY |
|
|
ld hl, PLAYER_VY |
|
|
STORE16 bc |
|
|
STORE16 bc |
|
|
|
|
|
|
|
|
; old_y = y |
|
|
|
|
|
ld hl, PLAYER_Y |
|
|
|
|
|
ld a, [hl] |
|
|
|
|
|
ld hl, PLAYER_OLD_Y |
|
|
|
|
|
ld [hl], a |
|
|
|
|
|
|
|
|
|
|
|
; y -= floor(vy) |
|
|
; y -= floor(vy) |
|
|
ld hl, PLAYER_Y |
|
|
ld hl, PLAYER_Y |
|
|
ld a, [hl] |
|
|
ld a, [hl] |
|
@ -115,24 +111,39 @@ Player_Update:: |
|
|
|
|
|
|
|
|
; roll back jump if there was a collision |
|
|
; roll back jump if there was a collision |
|
|
call player_bg_collides |
|
|
call player_bg_collides |
|
|
jr nz, .update_jump_oam |
|
|
|
|
|
|
|
|
jr z, .jump_update_oam |
|
|
|
|
|
|
|
|
|
|
|
.jump_rollback: |
|
|
|
|
|
ld hl, PLAYER_VY |
|
|
|
|
|
bit 7, [hl] |
|
|
|
|
|
|
|
|
ld hl, PLAYER_OLD_Y |
|
|
|
|
|
ld a, [hl] |
|
|
|
|
|
ld hl, PLAYER_Y |
|
|
ld hl, PLAYER_Y |
|
|
ld b, [hl] |
|
|
|
|
|
|
|
|
jr z, .jump_rollback_down |
|
|
|
|
|
dec [hl] |
|
|
|
|
|
jr .jump_rollback_check |
|
|
|
|
|
|
|
|
|
|
|
.jump_rollback_down: |
|
|
|
|
|
inc [hl] |
|
|
|
|
|
|
|
|
|
|
|
.jump_rollback_check: |
|
|
|
|
|
call player_bg_collides |
|
|
|
|
|
jr nz, .jump_rollback |
|
|
|
|
|
|
|
|
|
|
|
; set PLAYER_JUMPING = 0 if VY < 0 (fell into ground) |
|
|
ld hl, PLAYER_VY |
|
|
ld hl, PLAYER_VY |
|
|
|
|
|
bit 7, [hl] |
|
|
|
|
|
|
|
|
|
|
|
; either way, set VY = 0 |
|
|
|
|
|
ld [hl], 0 |
|
|
|
|
|
ld hl, PLAYER_VY + 1 |
|
|
ld [hl], 0 |
|
|
ld [hl], 0 |
|
|
|
|
|
|
|
|
; if colliding below, stop jump state |
|
|
|
|
|
cp b |
|
|
|
|
|
jr nc, .right |
|
|
|
|
|
|
|
|
jr z, .jump_update_oam |
|
|
|
|
|
|
|
|
ld hl, PLAYER_JUMPING |
|
|
ld hl, PLAYER_JUMPING |
|
|
ld [hl], 0 |
|
|
ld [hl], 0 |
|
|
|
|
|
|
|
|
.update_jump_oam: |
|
|
|
|
|
|
|
|
.jump_update_oam: |
|
|
call update_oam |
|
|
call update_oam |
|
|
|
|
|
|
|
|
; check for move right |
|
|
; check for move right |
|
@ -153,7 +164,7 @@ Player_Update:: |
|
|
inc [hl] |
|
|
inc [hl] |
|
|
|
|
|
|
|
|
call player_bg_collides |
|
|
call player_bg_collides |
|
|
jr z, .right_rollback |
|
|
|
|
|
|
|
|
jr nz, .right_rollback |
|
|
|
|
|
|
|
|
ld hl, PLAYER_DIR |
|
|
ld hl, PLAYER_DIR |
|
|
ld [hl], 0 |
|
|
ld [hl], 0 |
|
@ -180,11 +191,11 @@ Player_Update:: |
|
|
or a |
|
|
or a |
|
|
ret z |
|
|
ret z |
|
|
|
|
|
|
|
|
dec [hl] |
|
|
|
|
|
dec [hl] |
|
|
|
|
|
|
|
|
sub PLAYER_SPEED |
|
|
|
|
|
ld [hl], a |
|
|
|
|
|
|
|
|
call player_bg_collides |
|
|
call player_bg_collides |
|
|
jr z, .left_rollback |
|
|
|
|
|
|
|
|
jr nz, .left_rollback |
|
|
|
|
|
|
|
|
ld hl, PLAYER_DIR |
|
|
ld hl, PLAYER_DIR |
|
|
ld [hl], $ff |
|
|
ld [hl], $ff |
|
@ -194,7 +205,7 @@ Player_Update:: |
|
|
|
|
|
|
|
|
.left_rollback: |
|
|
.left_rollback: |
|
|
ld hl, PLAYER_X |
|
|
ld hl, PLAYER_X |
|
|
dec [hl] |
|
|
|
|
|
|
|
|
inc [hl] |
|
|
inc [hl] |
|
|
inc [hl] |
|
|
ret |
|
|
ret |
|
|
|
|
|
|
|
|