diff --git a/src/main.s b/src/main.s index e311841..006a401 100644 --- a/src/main.s +++ b/src/main.s @@ -30,13 +30,13 @@ start: ld hl, rIE ld [hl], IEF_VBLANK - call OAM_Init - ; call Keys_Init - ; call Player_Init - ld hl, intro_Data call Map_Load + call OAM_Init + call Keys_Init + call Player_Init + ; set palette ld a, %11100100 ld hl, rOBP0 @@ -55,8 +55,7 @@ start: inc [hl] call Keys_Update - - call scroll_update + call Player_Update ; wait for vblank halt @@ -68,40 +67,3 @@ start: call DMA_Start 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 diff --git a/src/player.s b/src/player.s index 443e06d..ec60a91 100644 --- a/src/player.s +++ b/src/player.s @@ -4,9 +4,6 @@ INCLUDE "util.inc" Section "Player Data", WRAM0 -playerWorldX: dw -playerWorldY: dw - ; player data PLAYER_X:: db 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 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 - 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 ld bc, _VRAM8000 + SPRITE_IDX * TILE_SIZE @@ -111,7 +102,11 @@ Player_Update:: ; roll back jump if there was a collision 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: ld hl, PLAYER_VY @@ -160,13 +155,17 @@ Player_Update:: jr nc, .left .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 jr nz, .right_rollback + ; TODO: Enable once scroll zones are implemented + ; ld d, PLAYER_SPEED + ; call Map_ScrollRight + xor a ld [PLAYER_DIR], a @@ -174,9 +173,9 @@ Player_Update:: ret .right_rollback: - ld hl, PLAYER_X - dec [hl] - dec [hl] + ld a, [PLAYER_X] + sub PLAYER_SPEED + ld [PLAYER_X], a ret .left: @@ -197,6 +196,10 @@ Player_Update:: call player_bg_collides jr nz, .left_rollback + ; TODO: Enable once scroll zones are implemented + ; ld d, PLAYER_SPEED + ; call Map_ScrollLeft + ld a, $ff ld [PLAYER_DIR], a