From de8ec5915fc7406d2af5d2ba87aca3326dacdf12 Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Sat, 20 Apr 2024 15:33:59 -0600 Subject: [PATCH] feat: change head facing direction on input Corrects the input handling code to actually skip when the button is not pressed --- main.asm | 150 ++++++++++++++++++++++++++++++++++------------------ sprites.png | Bin 328 -> 326 bytes 2 files changed, 99 insertions(+), 51 deletions(-) diff --git a/main.asm b/main.asm index d85466b..c08e496 100644 --- a/main.asm +++ b/main.asm @@ -36,9 +36,9 @@ WaitVBlank: jp nz, .resetOAM ; Copy cat sprite - ld de, GfxCat + ld de, Sprites ld hl, $8000 - ld bc, GfxCat.end - GfxCat + ld bc, Sprites.end - Sprites call Memcopy ; Reset positions @@ -55,7 +55,7 @@ WaitVBlank: ; Copy the tile data ld de, Tiles ld hl, $9000 - ld bc, TilesEnd - Tiles + ld bc, Tiles.end - Tiles call Memcopy ; Clear the tilemap @@ -105,35 +105,61 @@ Main:: HandleInput:: ld a, [wJoypadState] bit PADB_LEFT, a - jr nz, .leftend + jr z, .leftend + + ld a, PlayerHead.left - PlayerHead + ld [wMetaspritePosition.whichHead], a ld a, [wMetaspritePosition.x] - add a, 16 + sub a, 16 ld b, a ld [wMetaspritePosition.x], a ld a, [wMetaspritePosition.x+1] - adc 0 + sbc 0 ld c, a ld [wMetaspritePosition.x+1], a .leftend: ld a, [wJoypadState] bit PADB_RIGHT, a - jr nz, .rightend + jr z, .rightend + + ld a, PlayerHead.right - PlayerHead + ld [wMetaspritePosition.whichHead], a ld a, [wMetaspritePosition.x] - sub a, 16 + add a, 16 ld b, a ld [wMetaspritePosition.x], a ld a, [wMetaspritePosition.x+1] - sbc 0 + adc 0 ld c, a ld [wMetaspritePosition.x+1], a .rightend: ld a, [wJoypadState] bit PADB_UP, a - jr nz, .upend + jr z, .upend + + ld a, PlayerHead.up - PlayerHead + ld [wMetaspritePosition.whichHead], a + + ld a, [wMetaspritePosition.y] + sub a, 16 + ld b, a + ld [wMetaspritePosition.y], a + ld a, [wMetaspritePosition.y+1] + sbc 0 + ld c, a + ld [wMetaspritePosition.y+1], a +.upend: + + ld a, [wJoypadState] + bit PADB_DOWN, a + jr z, .downend + + ld a, PlayerHead.down - PlayerHead + ld [wMetaspritePosition.whichHead], a ld a, [wMetaspritePosition.y] add a, 16 @@ -143,20 +169,6 @@ HandleInput:: adc 0 ld c, a ld [wMetaspritePosition.y+1], a -.upend: - - ld a, [wJoypadState] - bit PADB_DOWN, a - jr nz, .downend - - ld a, [wMetaspritePosition.y] - sub a, 16 - ld b, a - ld [wMetaspritePosition.y], a - ld a, [wMetaspritePosition.y+1] - sbc 0 - ld c, a - ld [wMetaspritePosition.y+1], a .downend: ; Skip jump code if not on ground @@ -206,14 +218,13 @@ HandleRender:: ld a, [wMetaspritePosition.frame] inc a - cp PlayerMetasprite.framesEnd - PlayerMetasprite.framesStart + cp PlayerTorso.framesEnd - PlayerTorso.framesStart jr nz, .skipAnimReset ld a, 0 .skipAnimReset ld [wMetaspritePosition.frame], a .skipAnim - ; Render the player ; load de ld a, [wMetaspritePosition.x] ld e, a @@ -233,7 +244,7 @@ HandleRender:: ld b, a ; Add frameOffset - ld hl, PlayerMetasprite.framesStart + ld hl, PlayerTorso.framesStart ld a, [wMetaspritePosition.frame] add a, l ld l, a @@ -242,15 +253,43 @@ HandleRender:: .noCarry1 ld a, [hl] - ld hl, PlayerMetasprite + ld hl, PlayerTorso add a, l ld l, a jr nc, .noCarry2 inc h -.noCarry2 - +.noCarry2 call RenderMetasprite + ; Render player head + ; load de + ld a, [wMetaspritePosition.x] + ld e, a + ld a, [wMetaspritePosition.x + 1] + ld d, a + + ; load bc + ld a, [wMetaspritePosition.z] + ld c, a + ld a, [wMetaspritePosition.y] + add a, c + ld c, a + ld a, [wMetaspritePosition.z + 1] + ld b, a + ld a, [wMetaspritePosition.y + 1] + adc a, b + ld b, a + + ; load hl + ld hl, PlayerHead + ld a, [wMetaspritePosition.whichHead] + add a, l + ld l, a + jr nc, .noCarry3 + inc h +.noCarry3 + call RenderMetasprite + ; Render the shadow ; load de ld a, [wMetaspritePosition.x] @@ -341,7 +380,7 @@ UpdateJoypadState:: ld a, [hl] ld a, [hl] ld [hl], P1F_GET_DPAD - cpl ; Inputs are active low - invert so it makes more sense + cpl ; Inputs are active low - inv so it makes more sense and PADF_A | PADF_B | PADF_SELECT | PADF_START ld c, a ; Store lower 4 button bits in c @@ -354,7 +393,7 @@ UpdateJoypadState:: ld [hl], P1F_GET_NONE ; Disable joypad inputs swap a ; Swap the nibbles to store dpad in upper 4 bits - cpl ; invert the bits + cpl ; inv the bits and PADF_RIGHT | PADF_LEFT | PADF_UP | PADF_DOWN or c ld c, a @@ -433,7 +472,7 @@ SECTION "Tile data", ROM0 Tiles: INCBIN "tileset.2bpp" -TilesEnd: +.end: SECTION "Tilemap", ROM0 @@ -443,7 +482,7 @@ TilemapEnd: SECTION "Graphics", ROM0 -GfxCat: +Sprites: INCBIN "sprites.2bpp" .end:: @@ -451,28 +490,35 @@ ShadowMetasprite: db 12, 0, 1, 0 db 128 -PlayerMetasprite: -.vertWalk1: +PlayerHead: +.down: db 0, 0, 2, 0 + db 128 +.right: + db 0, 0, 3, 0 + db 128 +.up: + db 0, 0, 4, 0 + db 128 +.left: + db 0, 0, 3, OAMF_XFLIP + db 128 + +PlayerTorso: +.vWalk1: + db 8, 0, 5, 0 + db 128 +.vWalk2: db 8, 0, 6, 0 db 128 -.vertWalk2: - db 0, 0, 2, 0 - db 8, 0, 7, 0 - db 128 -.vertWalk3: - db 0, 0, 2, 0 - db 8, 0, 6, 0 - db 128 -.vertWalk4: - db 0, 0, 2, 0 - db 8, 0, 8, 0 +.vWalk3: + db 8, 0, 6, OAMF_XFLIP db 128 .framesStart - db .vertWalk1 - PlayerMetasprite - db .vertWalk2 - PlayerMetasprite - db .vertWalk3 - PlayerMetasprite - db .vertWalk4 - PlayerMetasprite + db .vWalk1 - PlayerTorso + db .vWalk2 - PlayerTorso + db .vWalk1 - PlayerTorso + db .vWalk3 - PlayerTorso .framesEnd SECTION "Position Vars", WRAM0 @@ -487,6 +533,8 @@ wMetaspritePosition:: dw .frame: db +.whichHead: + db ; Q4.4 fixed-point velocity wMetaspriteVelocity:: diff --git a/sprites.png b/sprites.png index f6ac8f144683a09946c8e5226ca5a707a36412bd..4c5bdaf9980a7f3d62bab5a245fe68916d865c57 100644 GIT binary patch delta 299 zcmX@Xbc|_&NAN?tPLS+Hv_q^{fRo-Hhj2?_Xv~-OM!S z&MStq3=ALE^Zc&JI9C1Var&O)`D-UH-?eJjhkf?PTTj20e00s~XZ@<+hhO!!zbp2R z6@K#e?F;z>8{61k{6Bm7y{32RDMJ&7Jw4}jUuM6aa#*0ENRGLZ%Qs`Wayuxw|UX$<4ZOtnt|4IIWC_=^A{c unI6ASZ!P{FxIx!3i-`dYR3H?TY}gV%QRU2&mUpS8AQ4YjKbLh*2~7Z0*N-&- delta 301 zcmX@cbb@JuN7qWpj63n%s-xy|&c;