Browse Source

Re-enable player code

master
Forest Belton 3 years ago
parent
commit
5a161acb60
2 changed files with 29 additions and 64 deletions
  1. +5
    -43
      src/main.s
  2. +24
    -21
      src/player.s

+ 5
- 43
src/main.s View File

@ -30,13 +30,13 @@ start:
ld hl, rIE ld hl, rIE
ld [hl], IEF_VBLANK ld [hl], IEF_VBLANK
call OAM_Init
; call Keys_Init
; call Player_Init
ld hl, intro_Data ld hl, intro_Data
call Map_Load call Map_Load
call OAM_Init
call Keys_Init
call Player_Init
; set palette ; set palette
ld a, %11100100 ld a, %11100100
ld hl, rOBP0 ld hl, rOBP0
@ -55,8 +55,7 @@ start:
inc [hl] inc [hl]
call Keys_Update call Keys_Update
call scroll_update
call Player_Update
; wait for vblank ; wait for vblank
halt halt
@ -68,40 +67,3 @@ start:
call DMA_Start call DMA_Start
jp .loop jp .loop
; TODO: Move into player movement routine
scroll_update:
; scroll map with arrow keys
ld a, [keys]
and PADF_UP
jr z, .down
ld d, 1
call Map_ScrollUp
ret
.down:
ld a, [keys]
and PADF_DOWN
jr z, .right
ld d, 1
call Map_ScrollDown
ret
.right:
ld a, [keys]
and PADF_RIGHT
jr z, .left
ld d, 1
call Map_ScrollRight
ret
.left:
ld a, [keys]
and PADF_LEFT
ret z
ld d, 1
call Map_ScrollLeft

+ 24
- 21
src/player.s View File

@ -4,9 +4,6 @@ INCLUDE "util.inc"
Section "Player Data", WRAM0 Section "Player Data", WRAM0
playerWorldX: dw
playerWorldY: dw
; player data ; player data
PLAYER_X:: db PLAYER_X:: db
PLAYER_Y:: dw PLAYER_Y:: dw
@ -35,18 +32,12 @@ 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 ; a.b
Player_Init:: Player_Init::
; Clear player data
ld hl, PLAYER_X
ld [hl], 0
inc hl
ld [hl], SCRN_Y - SPRITE_HEIGHT * (SCRN_Y - SPRITE_HEIGHT * TILE_HEIGHT)
inc hl
; Clear player data (X/Y initialized by map engine)
ld hl, PLAYER_DIR
xor a xor a
ld [hl+], a
ld [hl+], a
ld [hl+], a
ld [hl+], a
ld [hl+], a
REPT 7
ld [hl+], a
ENDR
; Copy sprite to VRAM ; Copy sprite to VRAM
ld bc, _VRAM8000 + SPRITE_IDX * TILE_SIZE ld bc, _VRAM8000 + SPRITE_IDX * TILE_SIZE
@ -111,7 +102,11 @@ 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 z, .jump_Player_UpdateOAM
jr nz, .jump_rollback
; TODO: Enable once scroll zones are implemented
; ld a, [PLAYER_VY]
; check if VY < 0 and call Map_ScrollUp / Map_ScrollDown
.jump_rollback: .jump_rollback:
ld hl, PLAYER_VY ld hl, PLAYER_VY
@ -160,13 +155,17 @@ Player_Update::
jr nc, .left jr nc, .left
.move_right: .move_right:
ld hl, PLAYER_X
inc [hl]
inc [hl]
ld a, [PLAYER_X]
add PLAYER_SPEED
ld [PLAYER_X], a
call player_bg_collides call player_bg_collides
jr nz, .right_rollback jr nz, .right_rollback
; TODO: Enable once scroll zones are implemented
; ld d, PLAYER_SPEED
; call Map_ScrollRight
xor a xor a
ld [PLAYER_DIR], a ld [PLAYER_DIR], a
@ -174,9 +173,9 @@ Player_Update::
ret ret
.right_rollback: .right_rollback:
ld hl, PLAYER_X
dec [hl]
dec [hl]
ld a, [PLAYER_X]
sub PLAYER_SPEED
ld [PLAYER_X], a
ret ret
.left: .left:
@ -197,6 +196,10 @@ Player_Update::
call player_bg_collides call player_bg_collides
jr nz, .left_rollback jr nz, .left_rollback
; TODO: Enable once scroll zones are implemented
; ld d, PLAYER_SPEED
; call Map_ScrollLeft
ld a, $ff ld a, $ff
ld [PLAYER_DIR], a ld [PLAYER_DIR], a

Loading…
Cancel
Save