A C64 Game - Step 21


Now some more tidbits. A game is not complete without a neat title screen:


For now this is nothing more than a almost empty screen and a separate control loop. The loop simply waits for a button press and then jumps to the game main loop. Once the player lost all lives he is returned to the title loop.

Note that for both cases we also check if the button has been released before allowing to go forward. Nothing's more annyoing than accidental commencing.



Rather unspectacular, the title screen code. First the screen is displayed and then the check button loop entered. Once the button has been pressed the game variables are reset and the code runs into the main game loop.

;------------------------------------------------------------
;the title screen game loop
;------------------------------------------------------------
!zone TitleScreen
TitleScreen
ldx #0
stx BUTTON_PRESSED
stx BUTTON_RELEASED
sta VIC_SPRITE_ENABLE

;clear screen
lda #32
ldy #0
jsr ClearScreen

;display title logo
lda #<‍TEXT_TITLE
sta ZEROPAGE_POINTER_1
lda #>TEXT_TITLE
sta ZEROPAGE_POINTER_1 + 1
lda #0
sta PARAM1
lda #1
sta PARAM2
jsr DisplayText

;display start text
lda #<‍TEXT_FIRE_TO_START
sta ZEROPAGE_POINTER_1
lda #>TEXT_FIRE_TO_START
sta ZEROPAGE_POINTER_1 + 1
lda #11
sta PARAM1
lda #23
sta PARAM2
jsr DisplayText

.TitleLoop
jsr WaitFrame
lda #$10
bit $dc00
bne .ButtonNotPressed

;button pushed
lda BUTTON_RELEASED
bne .Restart
jmp .TitleLoop

.ButtonNotPressed
lda #1
sta BUTTON_RELEASED
jmp .TitleLoop

.Restart
;game start values
lda #3
sta PLAYER_LIVES

;setup level
jsr StartLevel
lda #0
sta LEVEL_NR
jsr BuildScreen
jsr CopyLevelToBackBuffer

;------------------------------------------------------------
;the main game loop
;------------------------------------------------------------



Of course the counter part needs to be added to the DeadControl routine. If the player lost his last life, return to the title screen:

!zone DeadControl
DeadControl
lda SPRITE_ACTIVE
beq .PlayerIsDead
rts

.PlayerIsDead
lda #$10
bit $dc00
bne .ButtonNotPressed

;button pushed
lda BUTTON_RELEASED
bne .Restart
rts

.ButtonNotPressed
lda #1
sta BUTTON_RELEASED
rts

.Restart
;if last live return to title
lda PLAYER_LIVES
bne .RestartLevel
jmp TitleScreen

.RestartLevel




step21.zip