feat: change head facing direction on input
Corrects the input handling code to actually skip when the button is not pressedmain
parent
e478de9875
commit
de8ec5915f
146
main.asm
146
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,13 +253,41 @@ HandleRender::
|
|||
.noCarry1
|
||||
ld a, [hl]
|
||||
|
||||
ld hl, PlayerMetasprite
|
||||
ld hl, PlayerTorso
|
||||
add a, l
|
||||
ld l, a
|
||||
jr nc, .noCarry2
|
||||
inc h
|
||||
.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
|
||||
|
@ -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::
|
||||
|
|
BIN
sprites.png
BIN
sprites.png
Binary file not shown.
Before Width: | Height: | Size: 328 B After Width: | Height: | Size: 326 B |
Loading…
Reference in New Issue