A C64 Game - Step 79

posted in New Old Things
Published December 01, 2012
Advertisement

Almost a new feature: For the final level range the enemies spawn in waves. In this level, after beating the wolfmen two more waves of other enemies come in. And all without any more memory in the level data!



The key is in the previously used SPAWN_SPOT_SPAWN_COUNT. We use the upper 4 bits to contain the wave the spawn spots is part of. This limits us to 15 enemies per spawn spot which we were never even close to.

We add a new counter named NUMBER_DELAYED_SPAWN_SPOTS_ALIVE. This contains the number of spawn spots that are currently not active (future waves). SPAWN_SPOT_LEVEL holds the wave number (in the upper for bits, that's why we add 16)

The ProcessSpawnSpots routine is enhanced thusly:

          lda NUMBER_ENEMIES_ALIVE
          ora NUMBER_SPAWN_SPOTS_ALIVE
          bne .NoDelayedSpawnSpots

          lda NUMBER_DELAYED_SPAWN_SPOTS_ALIVE
          beq .NoDelayedSpawnSpots

          ;undelay them now
          lda SPAWN_SPOT_LEVEL
          clc
          adc #16
          sta SPAWN_SPOT_LEVEL

          ;check all spots
          ldx #0
-
          lda SPAWN_SPOT_ACTIVE,x
          beq +

          lda SPAWN_SPOT_SPAWN_COUNT,x
          and #$f0cmp SPAWN_SPOT_LEVEL
          bne +

          ;undelay now
          lda SPAWN_SPOT_SPAWN_COUNT,x
          and #$0f
          sta SPAWN_SPOT_SPAWN_COUNT,x

          dec NUMBER_DELAYED_SPAWN_SPOTS_ALIVE
          inc NUMBER_SPAWN_SPOTS_ALIVE

+
          inx
          cpx #SPAWN_SPOT_COUNTbne -
.NoDelayedSpawnSpots

Obviously in the spawn spot update loop we need to skip any spawn spots where the upper four bits are set:


          lda SPAWN_SPOT_SPAWN_COUNT,x
          and #$f0bne .NextSpawnSpot

Also, during level buildup we need to increment the correct counter depending on the upper four bits again:


          ;count
          iny
          lda (ZEROPAGE_POINTER_1),y
          sta SPAWN_SPOT_SPAWN_COUNT,x

          ;upper 4 bits set? then it's a delayed spawn spot!and #$f0
          bne +
          inc NUMBER_SPAWN_SPOTS_ALIVE
          jmp ++
          
+
          inc NUMBER_DELAYED_SPAWN_SPOTS_ALIVE
++

Have fun surviving!

step79.zip

Previous Step Next Step

Previous Entry A C64 Game - Step 78
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement