feat: add animation

main
Louis Pearson 2024-04-20 12:08:07 -06:00
parent 1c7f5f5918
commit e478de9875
2 changed files with 65 additions and 55 deletions

118
main.asm
View File

@ -88,6 +88,7 @@ WaitVBlank:
ldh [rIF], a ldh [rIF], a
; Enable interrupts ; Enable interrupts
ei ei
jp Main
Main:: Main::
call ResetShadowOAM call ResetShadowOAM
@ -197,6 +198,21 @@ HandleInput::
ret ret
HandleRender:: HandleRender::
; Calculate current frame for player
ld a, [hFrameCounter]
and a, %0000_0111
cp a, 0
jr nz, .skipAnim
ld a, [wMetaspritePosition.frame]
inc a
cp PlayerMetasprite.framesEnd - PlayerMetasprite.framesStart
jr nz, .skipAnimReset
ld a, 0
.skipAnimReset
ld [wMetaspritePosition.frame], a
.skipAnim
; Render the player ; Render the player
; load de ; load de
ld a, [wMetaspritePosition.x] ld a, [wMetaspritePosition.x]
@ -216,7 +232,23 @@ HandleRender::
adc a, b adc a, b
ld b, a ld b, a
ld hl, CatMetasprite ; Add frameOffset
ld hl, PlayerMetasprite.framesStart
ld a, [wMetaspritePosition.frame]
add a, l
ld l, a
jr nc, .noCarry1
inc h
.noCarry1
ld a, [hl]
ld hl, PlayerMetasprite
add a, l
ld l, a
jr nc, .noCarry2
inc h
.noCarry2
call RenderMetasprite call RenderMetasprite
; Render the shadow ; Render the shadow
@ -379,11 +411,13 @@ VBlankInterrupt:
SECTION "VBlank Handler", ROM0 SECTION "VBlank Handler", ROM0
VBlankHandler: VBlankHandler:
ldh a, [hFrameCounter]
ld a, HIGH(wShadowOAM) ld a, HIGH(wShadowOAM)
call hOAMDMA call hOAMDMA
ldh a, [hFrameCounter]
inc a
ldh [hFrameCounter], a
; Reset registers to orignal state ; Reset registers to orignal state
pop hl pop hl
pop de pop de
@ -407,68 +441,42 @@ Tilemap:
INCBIN "tileset.tilemap" INCBIN "tileset.tilemap"
TilemapEnd: TilemapEnd:
SECTION "Level data", ROM0
db $03 ; width
db $03 ; height
; Each byte stores whether it is solid or not
; Z = 1
db $01
db $01
db $01
db $01
db $01
db $01
db $01
db $01
db $00
; Z = 2
db $01
db $01
db $01
db $01
db $01
db $01
db $00
db $00
db $00
; Z = 3
db $01
db $00
db $00
db $00
db $00
db $00
db $00
db $00
db $00
SECTION "Graphics", ROM0 SECTION "Graphics", ROM0
GfxCat: GfxCat:
INCBIN "sprites.2bpp" INCBIN "sprites.2bpp"
.end:: .end::
CatMetasprite:
db 0, 0, 2, 0
db 8, 0, 6, 0
db 128
ShadowMetasprite: ShadowMetasprite:
db 12, 0, 1, 0 db 12, 0, 1, 0
db 128 db 128
PlayerMetasprite:
.vertWalk1:
db 0, 0, 2, 0
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
db 128
.framesStart
db .vertWalk1 - PlayerMetasprite
db .vertWalk2 - PlayerMetasprite
db .vertWalk3 - PlayerMetasprite
db .vertWalk4 - PlayerMetasprite
.framesEnd
SECTION "Position Vars", WRAM0 SECTION "Position Vars", WRAM0
wMetaspriteBegin: wMetaspriteBegin:
; Q12.4 fixed-point X posiition ; Q12.4 fixed-point X posiition
wMetaspritePosition:: wMetaspritePosition::
.x: .x:
@ -477,6 +485,8 @@ wMetaspritePosition::
dw dw
.z: .z:
dw dw
.frame:
db
; Q4.4 fixed-point velocity ; Q4.4 fixed-point velocity
wMetaspriteVelocity:: wMetaspriteVelocity::

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 328 B