baardbi
Well-known member
This will write the text "GAME OVER" in the middle of the screen when myHealth is 0. It is important to understand that this does nothing else. It just writes that text on the screen. So you need to include other mechanics to warp to the start screen or whatever you want to happen when it's game over.
I have tested this in the MetroVania module, but it should at least work perfectly well in the platformer module as well.
PS! Backup your asm files before you make changes to them.
0.
You need to have the letters G A M E O V E R as sprite tiles in your gameObjects graphics file. You also need to make a note of what tile each letter is in, So if for example the letter "G" was in the first tile of the game objects, then that's tile number 0. If the letter A is in the second sprite tile in gameObjects, then that's sprite tile 1, and so on.
1.
Put this at the bottom of the file ExtraTables_PlatformerBase.asm :
Make sure that the numbers after .db correspond with the number of the sprite tiles for each letter (in the gameObjects graphics file).gameOverText:
.db 10 ; G
.db 11 ; A
.db 12 ; M
.db 13 ; E
.db 0 ; END TEXT: "GAME"
.db 14 ; O
.db 15 ; V
.db 13 ; E
.db 47 ; R
.db 0 ; END TEXT: "OVER"
2.
Put this in the file doSpritePreDraw.asm right below .include SCR_DRAW_SPRITE_HUD :
;;;;;;;;;;;;;;;;;;;;;;;; GAME OVER TEXT ;;;;;;;;;;;;;;;;;;;;;;;;
GAME_OVER_TEXT_X = 112
GAME_OVER_TEXT_Y = 111
LDA gameState ;;;; Only do this check on gameplay screens
BEQ +checkIfGameOver
JMP +doneGameOver
+checkIfGameOver:
LDA myHealth ;;;; If health is zero we draw the Game Over text
BEQ +gameOver
JMP +doneGameOver
+gameOver:
LDA #GAME_OVER_TEXT_X
STA tempA
LDA #GAME_OVER_TEXT_Y
STA tempB
LDY #0
gameOverTextLoop1:
LDA gameOverText,y
BEQ +doneTextGame ;; Done writing text: "GAME"
STA temp
DrawSprite tempA, tempB, temp, #%00000001
LDA tempA
CLC
ADC #8
STA tempA
INY
JMP gameOverTextLoop1
+doneTextGame:
INY ; Go to next text character
; Set X position back to start for the next line of text
LDA #GAME_OVER_TEXT_X
STA tempA
;; One line down (+ 1 pixel offset)
LDA tempB
CLC
ADC #9
STA tempB
gameOverTextLoop2:
LDA gameOverText,y
BEQ +doneTextOver ;; Done writing text: "OVER"
STA temp
DrawSprite tempA, tempB, temp, #%00000001
LDA tempA
CLC
ADC #8
STA tempA
INY
JMP gameOverTextLoop2
+doneTextOver:
+doneGameOver:
3.
Make sure you save the files and test your game. You should now see the text "GAME OVER" in the middle of the screen when myHealth is 0.
That's it!