• entries
    104
  • comments
    101
  • views
    255296

A C64 Game - Step 41

Sign in to follow this  
Endurion

1999 views

Finally: A very talented chap volunteered to create imagery for the game. Lots of decent sprites and chars were created.
To celebrate there's also a slew of new enemies:

Wolfman
Eye
Jumping toad
Ghost skeleton

step41.png

Code wise this is mainly add the sprites to the binary include and the new behaviours. As you can see, the ghost skeleton doesn't do anything interesting (yet). The jumping toad however is quite complex. It's movement consists of ducking, jumping and waiting. Still, for now, it's quite predictable.

;------------------------------------------------------------
;ghost skeleton
;------------------------------------------------------------
!zone BehaviourGhostSkeleton
BehaviourGhostSkeleton
          lda DELAYED_GENERIC_COUNTER
          and #$03
          bne .NoAnimUpdate
          
          inc SPRITE_ANIM_POS,x
          lda SPRITE_ANIM_POS,x
          and #$03
          sta SPRITE_ANIM_POS,x
          tay
          lda GHOST_SKELETON_ANIMATION_TABLE,y
          sta SPRITE_POINTER_BASE,x
          
.NoAnimUpdate
.NormalUpdate

          ;does not do anything yet
          rts
          
;------------------------------------------------------------
;jumping toad
;------------------------------------------------------------
!zone BehaviourJumpingToad
BehaviourJumpingToad
          lda SPRITE_HITBACK,x
          beq .NoHitBack
          dec SPRITE_HITBACK,x
          lda SPRITE_HITBACK_DIRECTION,x
          beq .HitBackRight
          
          ;move left
          jsr ObjectMoveLeftBlocking
          rts
          
.HitBackRight
          jsr ObjectMoveRightBlocking
          rts
          
.NoHitBack
          lda SPRITE_STATE,x
          beq .NotDucking
          
          inc SPRITE_ANIM_DELAY,x
          lda SPRITE_ANIM_DELAY,x
          cmp #6
          bne .StillDucking
          lda #0
          sta SPRITE_ANIM_DELAY,x
          ldy SPRITE_ANIM_POS,x
          inc SPRITE_ANIM_POS,x
          lda TOAD_JUMP_ANIMATION_TABLE,y
          sta SPRITE_POINTER_BASE,x
          cmp #SPRITE_JUMPING_TOAD_1
          bne .StillDucking
          
          ;start jump
          lda #0
          sta SPRITE_STATE,x
          inc SPRITE_JUMP_POS,x
          
.StillDucking
          rts
          
.NotDucking
          lda SPRITE_JUMP_POS,x
          beq .FallIfPossible
          
          ;toad is jumping
          lda SPRITE_JUMP_POS,x
          cmp #TOAD_JUMP_TABLE_SIZE
          bne .JumpOn
          
;jump done
          jmp .JumpBlocked
          
.JumpOn
          ldy SPRITE_JUMP_POS,x
          inc SPRITE_JUMP_POS,x
          lda TOAD_JUMP_TABLE,y
          bne .KeepJumping
          
          ;no jump movement needed
          jmp .ToadMove
          
.KeepJumping
          sta PARAM5
          
.JumpContinue
          jsr ObjectMoveUpBlocking
          beq .JumpBlocked
          dec PARAM5
          bne .JumpContinue
          
          jmp .ToadMove

.JumpBlocked
          lda #0
          sta SPRITE_JUMP_POS,x
          jmp .ToadMove
          
.FallIfPossible
          jsr UpdateSpriteFall
          beq .CanJump
          jmp .ToadMove
          
.CanJump
          inc SPRITE_STATE,x
          lda #0
          sta SPRITE_ANIM_DELAY,x
          sta SPRITE_ANIM_POS,x
          lda #SPRITE_JUMPING_TOAD_2
          sta SPRITE_POINTER_BASE,x
          rts
          
          ;simple move left/right
          
.ToadMove
          lda SPRITE_DIRECTION,x
          beq .MoveRight
          jsr ObjectMoveLeftBlocking
          beq .ToggleDirection
          rts
          
.MoveRight
          jsr ObjectMoveRightBlocking
          beq .ToggleDirection
          rts
          
.ToggleDirection
          lda SPRITE_DIRECTION,x
          eor #1
          sta SPRITE_DIRECTION,x
          rts


Then we have the wolfman. Running about the level and randomly jumping. What's worse, the angrier it gets, the faster it runs.

!zone BehaviourWolf
BehaviourWolf
          lda SPRITE_HITBACK,x
          beq .NoHitBack
          dec SPRITE_HITBACK,x
          lda SPRITE_HITBACK_DIRECTION,x
          beq .HitBackRight
          
          ;move left
          jsr ObjectMoveLeftBlocking
          rts
          
.HitBackRight
          jsr ObjectMoveRightBlocking
          rts
          
.NoHitBack
          ;animate wolf
          lda SPRITE_JUMP_POS,x
          bne .NoAnimUpdate
          
          inc SPRITE_ANIM_DELAY,x
          lda SPRITE_ANIM_DELAY,x
          cmp #4
          bne .NoAnimUpdate
          
          lda #0
          sta SPRITE_ANIM_DELAY,x
          inc SPRITE_ANIM_POS,x
          lda SPRITE_ANIM_POS,x
          and #$03
          sta SPRITE_ANIM_POS,x
          tay
          lda SPRITE_DIRECTION,x
          beq .FacingLeft
          
          lda WOLF_ANIMATION_TABLE,y
          sta SPRITE_POINTER_BASE,x
          jmp .NoAnimUpdate
          
.FacingLeft
          lda WOLF_ANIMATION_TABLE,y
          clc
          adc #( SPRITE_WOLF_WALK_R_1 - SPRITE_WOLF_WALK_L_1 )
          sta SPRITE_POINTER_BASE,x
          
.NoAnimUpdate
          lda SPRITE_JUMP_POS,x
          bne .NoFallHandling
          
          jsr UpdateSpriteFall
          sta SPRITE_FALLING,x
          bne .IsFalling
          
          ;neither jumping nor falling
          jsr GenerateRandomNumber
          and #$0f
          cmp SPRITE_ANNOYED,x
          bpl .IsFalling
          
          ;random jump
          jmp .Jumping
          
.IsFalling
.NoFallHandling
          lda SPRITE_ANNOYED,x
          clc
          adc #2
          sta PARAM6
          
.MoveStep
          dec PARAM6
          beq .MoveDone
          
          lda SPRITE_DIRECTION,x
          beq .MoveRight
          
          ;move left
          lda SPRITE_JUMP_POS,x
          ora SPRITE_FALLING,x
          bne .OnlyMoveLeft
          
          jsr ObjectWalkOrJumpLeft
          beq .ToggleDirection
          
          jmp .MoveStep
          
.MoveDone
          lda SPRITE_JUMP_POS,x
          beq .NotJumping
          
.Jumping
          jsr UpdateSpriteJump
          
.NotJumping
          rts
          
.OnlyMoveLeft
          jsr ObjectMoveLeftBlocking
          beq .ToggleDirection
          jmp .MoveStep
          
.MoveRight
          lda SPRITE_JUMP_POS,x
          ora SPRITE_FALLING,x
          bne .OnlyMoveRight
          
          jsr ObjectWalkOrJumpRight
          beq .ToggleDirection
          
          jmp .MoveStep
          
.OnlyMoveRight
          jsr ObjectMoveRightBlocking
          beq .ToggleDirection
          
          jmp .MoveStep
          
.ToggleDirection
          lda SPRITE_DIRECTION,x
          eor #1
          sta SPRITE_DIRECTION,x
          jmp .MoveStep


The eye is rather easy again. It moves diagonally, but stops every now and then to take a look.

!zone BehaviourEye
BehaviourEye
          lda DELAYED_GENERIC_COUNTER
          and #$03
          bne .NoAnimUpdate

          ;inc SPRITE_ANIM_POS,x
          ;lda SPRITE_ANIM_POS,x
          ;and #$03
          ;sta SPRITE_ANIM_POS,x

          ;tay
          ;lda BAT_ANIMATION,y
          ;sta SPRITE_POINTER_BASE,x

.NoAnimUpdate
          lda SPRITE_STATE,x
          beq .Move
          cmp #1
          beq .EyeOpen
          cmp #2
          beq .EyeIsOpen

          ;eye closes
          inc SPRITE_ANIM_DELAY,x
          lda SPRITE_ANIM_DELAY,x
          cmp #3
          bne .NoActionNow
          lda #0
          sta SPRITE_ANIM_DELAY,x

          ;close animation
          dec SPRITE_ANIM_POS,x
          dec SPRITE_POINTER_BASE,x

          ldy SPRITE_ANIM_POS,x
          lda EYE_COLOR_TABLE,y
          sta VIC_SPRITE_COLOR,x

          cpy #0
          bne .NoActionNow

          ;can move again
          lda #0
          sta SPRITE_STATE,x
          rts


.EyeOpen
          inc SPRITE_ANIM_DELAY,x
          lda SPRITE_ANIM_DELAY,x
          cmp #3
          bne .NoActionNow
          lda #0
          sta SPRITE_ANIM_DELAY,x
          ;open animation
          inc SPRITE_ANIM_POS,x
          inc SPRITE_POINTER_BASE,x

          ldy SPRITE_ANIM_POS,x
          lda EYE_COLOR_TABLE,y
          sta VIC_SPRITE_COLOR,x

          cpy #3
          bne .NoActionNow

          ;now wait
          inc SPRITE_STATE,x
          rts

.EyeIsOpen
          inc SPRITE_ANIM_DELAY,x
          lda SPRITE_ANIM_DELAY,x
          cmp #30
          beq .EyeCloseNow

.NoActionNow
          rts

.EyeCloseNow
          lda #3
          sta SPRITE_STATE,x
          lda #0
          sta SPRITE_ANIM_DELAY,x
          rts

.Move
          jsr GenerateRandomNumber
          cmp #7
          bne .MoveNow

          ;start blinking
          lda #1
          sta SPRITE_STATE,x
          rts
.MoveNow
          lda SPRITE_DIRECTION,x
          beq .MoveRight

          ;move left
          jsr ObjectMoveLeftBlocking
          beq .ToggleDirection
          jmp .MoveY

.MoveRight
          jsr ObjectMoveRightBlocking
          beq .ToggleDirection
          jmp .MoveY

.ToggleDirection
          lda SPRITE_DIRECTION,x
          eor #1
          sta SPRITE_DIRECTION,x

.MoveY
          lda SPRITE_DIRECTION_Y,x
          beq .MoveDown

          ;move up
          jsr ObjectMoveUpBlocking
          beq .ToggleDirectionY
          rts

.MoveDown
          jsr ObjectMoveDownBlocking
          beq .ToggleDirectionY
          rts

.ToggleDirectionY
          lda SPRITE_DIRECTION_Y,x
          eor #1
          sta SPRITE_DIRECTION_Y,x
          rts


TL/DR: Have fun!

step41.zip


Previous Step Next Step

Sign in to follow this  


1 Comment


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now