A C64 Game - Step 17


Another rather small step, but visually pleasing. We're enhancing the player sprite with animation and better jump abilities.

All the hard work is added to PlayerControl. On every movement we update the sprite while checking the player states like jumping, recoil, falling, etc. Suddenly things look more interesting ;)

It's basically updating and checking counters during different control parts. SPRITE_ANIM_DELAY is used for controlling animation speed while SPRITE_ANIM_POS is used for the animation frame.



Here are the new parts for walking left:

;animate player
lda SPRITE_FALLING
bne .NoAnimLNeeded

lda PLAYER_JUMP_POS
bne .NoAnimLNeeded

inc SPRITE_ANIM_DELAY
lda SPRITE_ANIM_DELAY
cmp #8
bne .NoAnimLNeeded

lda #0
sta SPRITE_ANIM_DELAY
inc SPRITE_ANIM_POS
lda SPRITE_ANIM_POS
and #$3
sta SPRITE_ANIM_POS

.NoAnimLNeeded



The same for right movement:

          ;animate player
lda SPRITE_FALLING
bne .NoAnimRNeeded
lda PLAYER_JUMP_POS
bne .NoAnimRNeeded

inc SPRITE_ANIM_DELAY
lda SPRITE_ANIM_DELAY
cmp #8
bne .NoAnimRNeeded

lda #0
sta SPRITE_ANIM_DELAY

inc SPRITE_ANIM_POS
lda SPRITE_ANIM_POS
and #$3
sta SPRITE_ANIM_POS

.NoAnimRNeeded



And all the missing animation for jumping, falling, recoil and combined states. Note that the sprites are arranged in right/left pairs, so that adding SPRITE_DIRECTION (0 = facing right, 1 = facing left) to the sprite frame results in the proper sprite.

          ;update player animation
lda SPRITE_FALLING
bne .AnimFalling

lda PLAYER_JUMP_POS
bne .AnimJumping

;is player shooting?
lda PLAYER_SHOT_PAUSE
beq .AnimNoRecoil

;recoil anim
lda SPRITE_ANIM_POS
asl
clc
adc SPRITE_DIRECTION
adc #SPRITE_PLAYER_WALK_R_1
adc #8
sta SPRITE_POINTER_BASE
rts

.AnimNoRecoil
lda SPRITE_ANIM_POS
asl
clc
adc SPRITE_DIRECTION
adc #SPRITE_PLAYER_WALK_R_1
sta SPRITE_POINTER_BASE
rts

.AnimFalling
lda PLAYER_SHOT_PAUSE
bne .AnimFallingNoRecoil
lda #SPRITE_PLAYER_FALL_R
clc
adc SPRITE_DIRECTION
sta SPRITE_POINTER_BASE
rts

.AnimFallingNoRecoil
lda #SPRITE_PLAYER_FALL_RECOIL_R
clc
adc SPRITE_DIRECTION
sta SPRITE_POINTER_BASE
rts

.AnimJumping
lda PLAYER_SHOT_PAUSE
bne .AnimJumpingNoRecoil

lda #SPRITE_PLAYER_JUMP_R
clc
adc SPRITE_DIRECTION
sta SPRITE_POINTER_BASE
rts

.AnimJumpingNoRecoil
lda #SPRITE_PLAYER_JUMP_RECOIL_R
clc
adc SPRITE_DIRECTION
sta SPRITE_POINTER_BASE
rts




step17.zip