A C64 Game - Step 37

posted in New Old Things
Published December 31, 2011
Advertisement

Currently the player is simply vanishing when getting killed. Kinda looks odd, doesn't it? We add a nice new animation and then send the player back in.



First we remove the previous player kill code (which removed the sprite and displayed a GET READY message) and replace it with this.
Note that we keep the sprite object but set the state to invincible (>= 128).

.PlayerCollidedWithEnemy
          ;player killed
          ldx PARAM6
          lda #129
          sta SPRITE_STATE,x
          lda #SPRITE_PLAYER_DEAD
          sta SPRITE_POINTER_BASE,x
          lda #0
          sta SPRITE_MOVE_POS,x

On top of the PlayerControl routine we add this part. Note that the routine is jumped into PlayerControl, but .PlayerIsDying is above. The reason for this is the limited range of branch mnemonics. They only allow for -128/127 byte jumps. Just by rearranging the code the branch can be kept.

A different solution would be to replace the branch by a reverse branch with a followup jmp.


.PlayerIsDyinginc SPRITE_MOVE_POS,x
          lda SPRITE_MOVE_POS,x
          cmp #64
          beq .PlayerRespawn
          and #$03
          bne .NoUpMove
          
          jsr MoveSpriteUp
          
.NoUpMove
          rts
          
.PlayerRespawndec PLAYER_LIVES
          jsr DisplayLiveNumber
          
          ;game over?
          lda PLAYER_LIVES
          bne .RestartPlayer
          jmp CheckForHighscore
          
.RestartPlayer
          lda SPRITE_ACTIVE
          
          ;refill shells
          ldy #0
          
.RefillShellImage
          lda #2
          sta SCREEN_COLOR + 23 * 40 + 19,y
          lda #7
          sta SCREEN_COLOR + 24 * 40 + 19,y
          iny
          cpy PLAYER_SHELLS_MAX
          bne .RefillShellImage
          
          lda PLAYER_SHELLS_MAX
          sta PLAYER_SHELLS
          
          ;respawn at correct position
          lda PLAYER_START_POS_X
          sta PARAM1
          lda PLAYER_START_POS_Y
          sta PARAM2
          
          ;PARAM1 and PARAM2 hold x,y already
          jsr CalcSpritePosFromCharPos
          
          ;enable sprite
          lda BIT_TABLE
          ora VIC_SPRITE_ENABLE
          sta VIC_SPRITE_ENABLE
          
          ;initialise enemy values
          lda #SPRITE_PLAYER
          sta SPRITE_POINTER_BASE
          lda #0
          sta PLAYER_FAST_RELOAD
          sta PLAYER_INVINCIBLE
          sta SPRITE_STATE
          
          ;look right per default
          lda #0
          sta SPRITE_DIRECTION
          lda #0
          sta SPRITE_JUMP_POS
          sta SPRITE_FALLING
          rts
          
PlayerControl
          lda SPRITE_STATE,x
          cmp #129
          bne .NotDying
          jmp .PlayerIsDying
          
.NotDying

Now that the whole dying sequence is handled by PlayerControl directly the full routine DeadControl can be removed. This change also helps a lot in the next step

step37.zip

Previous Step Next Step

Previous Entry A C64 Game - Step 36
2 likes 2 comments

Comments

Programming020195BRook
Nice job man! I just played your game for the last hour, and I'm really enjoying concept for this game! A lot of "fancy" games come out every year, but they seem to miss what the classics were known for, game play!

Keep up the great work! I would sooner pay for a final product of this game, then most of the releases from big game studios.

I noticed with the game, I could only loose lives on level 9 and 10. Was this supposed to happen?
January 01, 2012 11:36 AM
Endurion
Actually no, I'll check this. Thanks, glad that you like it :)
January 07, 2012 10:11 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement