feat: change head facing direction on input

Corrects the input handling code to actually skip when the button is not
pressed
main
Louis Pearson 2024-04-20 15:33:59 -06:00
parent e478de9875
commit de8ec5915f
2 changed files with 99 additions and 51 deletions

146
main.asm
View File

@ -36,9 +36,9 @@ WaitVBlank:
jp nz, .resetOAM jp nz, .resetOAM
; Copy cat sprite ; Copy cat sprite
ld de, GfxCat ld de, Sprites
ld hl, $8000 ld hl, $8000
ld bc, GfxCat.end - GfxCat ld bc, Sprites.end - Sprites
call Memcopy call Memcopy
; Reset positions ; Reset positions
@ -55,7 +55,7 @@ WaitVBlank:
; Copy the tile data ; Copy the tile data
ld de, Tiles ld de, Tiles
ld hl, $9000 ld hl, $9000
ld bc, TilesEnd - Tiles ld bc, Tiles.end - Tiles
call Memcopy call Memcopy
; Clear the tilemap ; Clear the tilemap
@ -105,35 +105,61 @@ Main::
HandleInput:: HandleInput::
ld a, [wJoypadState] ld a, [wJoypadState]
bit PADB_LEFT, a bit PADB_LEFT, a
jr nz, .leftend jr z, .leftend
ld a, PlayerHead.left - PlayerHead
ld [wMetaspritePosition.whichHead], a
ld a, [wMetaspritePosition.x] ld a, [wMetaspritePosition.x]
add a, 16 sub a, 16
ld b, a ld b, a
ld [wMetaspritePosition.x], a ld [wMetaspritePosition.x], a
ld a, [wMetaspritePosition.x+1] ld a, [wMetaspritePosition.x+1]
adc 0 sbc 0
ld c, a ld c, a
ld [wMetaspritePosition.x+1], a ld [wMetaspritePosition.x+1], a
.leftend: .leftend:
ld a, [wJoypadState] ld a, [wJoypadState]
bit PADB_RIGHT, a bit PADB_RIGHT, a
jr nz, .rightend jr z, .rightend
ld a, PlayerHead.right - PlayerHead
ld [wMetaspritePosition.whichHead], a
ld a, [wMetaspritePosition.x] ld a, [wMetaspritePosition.x]
sub a, 16 add a, 16
ld b, a ld b, a
ld [wMetaspritePosition.x], a ld [wMetaspritePosition.x], a
ld a, [wMetaspritePosition.x+1] ld a, [wMetaspritePosition.x+1]
sbc 0 adc 0
ld c, a ld c, a
ld [wMetaspritePosition.x+1], a ld [wMetaspritePosition.x+1], a
.rightend: .rightend:
ld a, [wJoypadState] ld a, [wJoypadState]
bit PADB_UP, a 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] ld a, [wMetaspritePosition.y]
add a, 16 add a, 16
@ -143,20 +169,6 @@ HandleInput::
adc 0 adc 0
ld c, a ld c, a
ld [wMetaspritePosition.y+1], 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: .downend:
; Skip jump code if not on ground ; Skip jump code if not on ground
@ -206,14 +218,13 @@ HandleRender::
ld a, [wMetaspritePosition.frame] ld a, [wMetaspritePosition.frame]
inc a inc a
cp PlayerMetasprite.framesEnd - PlayerMetasprite.framesStart cp PlayerTorso.framesEnd - PlayerTorso.framesStart
jr nz, .skipAnimReset jr nz, .skipAnimReset
ld a, 0 ld a, 0
.skipAnimReset .skipAnimReset
ld [wMetaspritePosition.frame], a ld [wMetaspritePosition.frame], a
.skipAnim .skipAnim
; Render the player
; load de ; load de
ld a, [wMetaspritePosition.x] ld a, [wMetaspritePosition.x]
ld e, a ld e, a
@ -233,7 +244,7 @@ HandleRender::
ld b, a ld b, a
; Add frameOffset ; Add frameOffset
ld hl, PlayerMetasprite.framesStart ld hl, PlayerTorso.framesStart
ld a, [wMetaspritePosition.frame] ld a, [wMetaspritePosition.frame]
add a, l add a, l
ld l, a ld l, a
@ -242,13 +253,41 @@ HandleRender::
.noCarry1 .noCarry1
ld a, [hl] ld a, [hl]
ld hl, PlayerMetasprite ld hl, PlayerTorso
add a, l add a, l
ld l, a ld l, a
jr nc, .noCarry2 jr nc, .noCarry2
inc h 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 call RenderMetasprite
; Render the shadow ; Render the shadow
@ -341,7 +380,7 @@ UpdateJoypadState::
ld a, [hl] ld a, [hl]
ld a, [hl] ld a, [hl]
ld [hl], P1F_GET_DPAD 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 and PADF_A | PADF_B | PADF_SELECT | PADF_START
ld c, a ; Store lower 4 button bits in c ld c, a ; Store lower 4 button bits in c
@ -354,7 +393,7 @@ UpdateJoypadState::
ld [hl], P1F_GET_NONE ; Disable joypad inputs ld [hl], P1F_GET_NONE ; Disable joypad inputs
swap a ; Swap the nibbles to store dpad in upper 4 bits 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 and PADF_RIGHT | PADF_LEFT | PADF_UP | PADF_DOWN
or c or c
ld c, a ld c, a
@ -433,7 +472,7 @@ SECTION "Tile data", ROM0
Tiles: Tiles:
INCBIN "tileset.2bpp" INCBIN "tileset.2bpp"
TilesEnd: .end:
SECTION "Tilemap", ROM0 SECTION "Tilemap", ROM0
@ -443,7 +482,7 @@ TilemapEnd:
SECTION "Graphics", ROM0 SECTION "Graphics", ROM0
GfxCat: Sprites:
INCBIN "sprites.2bpp" INCBIN "sprites.2bpp"
.end:: .end::
@ -451,28 +490,35 @@ ShadowMetasprite:
db 12, 0, 1, 0 db 12, 0, 1, 0
db 128 db 128
PlayerMetasprite: PlayerHead:
.vertWalk1: .down:
db 0, 0, 2, 0 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 8, 0, 6, 0
db 128 db 128
.vertWalk2: .vWalk3:
db 0, 0, 2, 0 db 8, 0, 6, OAMF_XFLIP
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
db 128 db 128
.framesStart .framesStart
db .vertWalk1 - PlayerMetasprite db .vWalk1 - PlayerTorso
db .vertWalk2 - PlayerMetasprite db .vWalk2 - PlayerTorso
db .vertWalk3 - PlayerMetasprite db .vWalk1 - PlayerTorso
db .vertWalk4 - PlayerMetasprite db .vWalk3 - PlayerTorso
.framesEnd .framesEnd
SECTION "Position Vars", WRAM0 SECTION "Position Vars", WRAM0
@ -487,6 +533,8 @@ wMetaspritePosition::
dw dw
.frame: .frame:
db db
.whichHead:
db
; Q4.4 fixed-point velocity ; Q4.4 fixed-point velocity
wMetaspriteVelocity:: wMetaspriteVelocity::

Binary file not shown.

Before

Width:  |  Height:  |  Size: 328 B

After

Width:  |  Height:  |  Size: 326 B