Jump to content

  • Log In with Google      Sign In   
  • Create Account

New Old Things



A C64 Game - Step 80

Posted by , in C64 08 December 2012 - - - - - - · 1,232 views

Did you notice the huge door in the background? It's about time it opens!

Attached Image

That's actually pretty simple. At the jump-to-next level code we add a check. Whether the open door animation is shown depends on a bit in the LEVEL_CONFIG byte.

GoToNextLevel

		  lda LEVEL_CONFIG

		  and #$04

		  beq .NoDoorAnim

		

		  jsr DoorAnim



.NoDoorAnim


The actual animation is straight forward. The door location is hard coded, and we simply copy the characters one step to the outer side and replace the innermost characters with empty space.

Notice that we use a method which is not possible that easy in todays code: We have a local code loop until the door is completely opened.
Since there are no events to be handled, messages to be retrieved or other OS specific code required, we can do that.





;------------------------------------------------------------

;open door animation

;------------------------------------------------------------

!zone DoorAnim

DoorAnim

		  lda #0

		  sta LEVEL_DONE_DELAY



.DoorAnimLoop

		  jsr WaitFrame

		

		  inc LEVEL_DONE_DELAY

		  lda LEVEL_DONE_DELAY

		  and #$07

		  bne .DoorAnimLoop

		

		  ;open door (16,11)

		  lda #11

		  sta PARAM2

		

-		

		  ldy PARAM2

		  lda SCREEN_LINE_OFFSET_TABLE_LO,y

		  sta ZEROPAGE_POINTER_1

		  lda SCREEN_LINE_OFFSET_TABLE_HI,y

		  sta ZEROPAGE_POINTER_1 + 1

		

		  ldy #17

		  lda (ZEROPAGE_POINTER_1),y

		  dey

		  sta (ZEROPAGE_POINTER_1),y

		  ldy #18

		  lda (ZEROPAGE_POINTER_1),y

		  dey

		  sta (ZEROPAGE_POINTER_1),y

		  ldy #19

		  lda (ZEROPAGE_POINTER_1),y

		  dey

		  sta (ZEROPAGE_POINTER_1),y

		  lda #32

		  ldy #19

		  sta (ZEROPAGE_POINTER_1),y

		

		  ldy #22

		  lda (ZEROPAGE_POINTER_1),y

		  iny

		  sta (ZEROPAGE_POINTER_1),y

		  ldy #21

		  lda (ZEROPAGE_POINTER_1),y

		  iny

		  sta (ZEROPAGE_POINTER_1),y

		  ldy #20

		  lda (ZEROPAGE_POINTER_1),y

		  iny

		  sta (ZEROPAGE_POINTER_1),y

		

		  lda #32

		  ldy #20

		  sta (ZEROPAGE_POINTER_1),y

		

		  inc PARAM2

		  lda PARAM2

		  cmp #21

		  bne -

		  ;

		  lda LEVEL_DONE_DELAY

		  lsr

		  lsr

		  lsr

		  cmp #4

		  bne .DoorAnimLoop

		  ;door is fully open now

-

		  jsr WaitFrame

		

		  inc LEVEL_DONE_DELAY

		  lda LEVEL_DONE_DELAY

		  cmp #200

		  bne -

		  rts



Also, since I'm going on vacation this tutorial takes a break until next year. Thanks for your support so far, have fun!


Previous Step Next Step

Attached Files




A C64 Game - Step 79

Posted by , in C64 01 December 2012 - - - - - - · 938 views

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!

Attached Image

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 #$f0
		  cmp 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_COUNT
		  bne -
.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 #$f0
		  bne .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!


Previous Step Next Step

Attached Files







December 2012 »

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526272829
3031     


PARTNERS