level change + score management

This commit is contained in:
giomba 2020-04-08 10:54:54 +02:00
parent cd1820d834
commit 4498d045de
10 changed files with 68 additions and 50 deletions

View File

@ -46,3 +46,7 @@ levelN:
delayStatus: delayStatus:
BYTE BYTE
; Total score of the game
score:
WORD

View File

@ -203,9 +203,24 @@ overEndCheck:
beq foodEaten ; if memory does contain food, then perform foodEaten actions, beq foodEaten ; if memory does contain food, then perform foodEaten actions,
jmp checkSelfEat ; else just loooong jump to test if I ate myself jmp checkSelfEat ; else just loooong jump to test if I ate myself
foodEaten: foodEaten:
ldx length ; else, increment snake length, ldx length ; else, increment snake length
inx inx
stx length stx length
cpx #$10 ; check if level is finished
bne genFood ; if not, skip
clc
lda score ; else increment total score
adc length
sta score
lda score + 1
adc #$0
sta score + 1
jsr levelresetvar ; reset vars and go to next level
lda #ST_LEVEL_TITLE
sta status
rts
genFood: genFood:
ldx random ldx random
inx inx
@ -241,10 +256,10 @@ genFoodY: ; calculate `random` modulo 22 (22 = SCREEN_H - 1)
foodOK: foodOK:
#if DEBUG = 1 #if DEBUG = 1
; print choosen X,Y for food ; print choosen X,Y for food
ldy #$18 ldy #14
lda calcTileX lda calcTileX
jsr printByte jsr printByte
ldy #$1b ldy #17
lda calcTileY lda calcTileY
jsr printByte jsr printByte
#endif #endif
@ -264,8 +279,8 @@ foodOK:
lda FOOD_COLOR lda FOOD_COLOR
sta (tileMem),y sta (tileMem),y
; print score at $10th column ; print partial
ldy #$10 ldy #36
lda length lda length
jsr printByte jsr printByte

View File

@ -2,10 +2,15 @@
; ---------------------------------------------------------------------- ; ----------------------------------------------------------------------
gameover: gameover:
lda #<gameoverString lda #<gameoverString
sta printStatusString sta printIntroString
lda #>gameoverString lda #>gameoverString
sta printStatusString + 1 sta printIntroString + 1
jsr printStatus
lda #$00
sta introScreenStart
lda #$04
sta introScreenStart + 1
jsr printIntro
; Set gameover and outro status ; Set gameover and outro status
lda #$ff lda #$ff

View File

@ -84,7 +84,7 @@ levelIntroString:
colorshade: ; a gradient of dark-bright-dark (40 columns) colorshade: ; a gradient of dark-bright-dark (40 columns)
HEX 0b 0b 0b 0b 0b 0c 0c 0c 0c 0c 05 05 05 0d 0d 0d 0d 07 07 07 07 07 07 0d 0d 0d 0d 05 05 05 0c 0c 0c 0c 0c 0b 0b 0b 0b 0b HEX 0b 0b 0b 0b 0b 0c 0c 0c 0c 0c 05 05 05 0d 0d 0d 0d 07 07 07 07 07 07 0d 0d 0d 0d 05 05 05 0c 0c 0c 0c 0c 0b 0b 0b 0b 0b
scoreString: scoreString:
BYTE "POINTS" BYTE "SCORE PART"
BYTE #0 BYTE #0
; Levels ; Levels

View File

@ -1,6 +1,6 @@
; Full game reset ; Reset variables for a new level
; ---------------------------------------------------------------------- ; ----------------------------------------------------------------------
gamereset: levelresetvar:
; Turn MultiColor mode on ; Turn MultiColor mode on
jsr multicolorOn jsr multicolorOn
@ -30,11 +30,5 @@ clearListLoop:
cpx #$00 cpx #$00
bne clearListLoop bne clearListLoop
; Set current level pointer to list start
lda #<levelsList
sta levelPointer
lda #>levelsList
sta levelPointer + 1
rts rts

View File

@ -2,7 +2,6 @@
statusLevelTitle SUBROUTINE statusLevelTitle SUBROUTINE
jsr clearScreen jsr clearScreen
.back:
; Print "Next Level" ; Print "Next Level"
lda #<levelIntroString lda #<levelIntroString
sta printIntroString sta printIntroString
@ -45,21 +44,33 @@ statusLevelTitle SUBROUTINE
statusLevelLoad SUBROUTINE statusLevelLoad SUBROUTINE
; Upper bar -- fill with spaces, color yellow ; Upper bar -- fill with spaces, color yellow
ldx #39 ldx #39
upperbarLoop: .loop:
lda #$0 lda #$0
sta $400,x sta $400,x
lda #7 lda #7
sta $d800,x sta $d800,x
dex dex
cpx #$ff cpx #$ff
bne upperbarLoop bne .loop
; Set upper bar text ; Set upper bar score/part text
lda #<scoreString lda #<scoreString
sta printStatusString sta printIntroString
lda #>scoreString lda #>scoreString
sta printStatusString + 1 sta printIntroString + 1
jsr printStatus lda #$14
sta introScreenStart
lda #$04
sta introScreenStart + 1
jsr printIntro
; Set score
ldy #26
lda score + 1
jsr printByte
ldy #28
lda score
jsr printByte
; initialize video pointer with first video memory address ; initialize video pointer with first video memory address
; (skip first line, used for the status bar) ; (skip first line, used for the status bar)

View File

@ -57,7 +57,7 @@ tggsFont:
INCLUDE "game.asm" INCLUDE "game.asm"
INCLUDE "gameover.asm" INCLUDE "gameover.asm"
INCLUDE "gamereset.asm" INCLUDE "levelreset.asm"
INCLUDE "introreset.asm" INCLUDE "introreset.asm"
INCLUDE "intro1.asm" INCLUDE "intro1.asm"
INCLUDE "multicolor.asm" INCLUDE "multicolor.asm"

View File

@ -69,8 +69,19 @@ intro0running: ; Cycle here until SPACE or `Q` is pressed
; Intro is finished, now it's time to start the proper game ; Intro is finished, now it's time to start the proper game
intro0end: intro0end:
; Set init variables of the game ; Set current level pointer to list start
jsr gamereset lda #<levelsList
sta levelPointer
lda #>levelsList
sta levelPointer + 1
; clear score
lda #$00
sta score
sta score + 1
; Set init variables of the level
jsr levelresetvar
; Set status as level select ; Set status as level select
; (then it will enter in status play) ; (then it will enter in status play)

View File

@ -87,25 +87,6 @@ printByte SUBROUTINE
rts rts
; Print null-terminated string on status bar
; address of string is given in input using memory location printStatusString
printStatus SUBROUTINE
ldy #0
printStatusLoop:
lda (printStatusString),y
beq printStatusEnd
cmp #$20
bne printStatusSkipSpace
lda #$40 ; space + $40
printStatusSkipSpace:
sec
sbc #$40 ; convert from standard ASCII to Commodore screen code
sta $413,y
iny
jmp printStatusLoop
printStatusEnd:
rts
printIntro SUBROUTINE printIntro SUBROUTINE
; Print string for intro ; Print string for intro
; Input parameters: ; Input parameters:

View File

@ -4,10 +4,7 @@
; using pointer at tileMem,tileMem+1 ; using pointer at tileMem,tileMem+1
tileMem DS 2 tileMem DS 2
; Pointer to status string ; Pointer to string
printStatusString DS 2
; Pointer to intro string
printIntroString DS 2 printIntroString DS 2
; Pointer to screen position where to print intro string ; Pointer to screen position where to print intro string
introScreenStart DS 2 introScreenStart DS 2