From edaf05d605e39071ec86ff959d7898f885763476 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 7 Oct 2024 18:39:10 +0200 Subject: [PATCH] Added simple game over animation --- src/main.s | 2 +- src/player.s | 34 ++++++++++++++++++++++++++++++++++ src/strings.s | 4 ++++ src/video.s | 10 ++++++++++ src/wram.s | 4 ++++ 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/main.s b/src/main.s index 680a127..bb4d2b2 100644 --- a/src/main.s +++ b/src/main.s @@ -43,9 +43,9 @@ main: jr @forever REL #endif +#include "strings.s" #include "video.s" #include "mem.s" -#include "strings.s" #include "sys.s" #include "input.s" #include "player.s" diff --git a/src/player.s b/src/player.s index 8a96dc2..3a62b2e 100644 --- a/src/player.s +++ b/src/player.s @@ -256,3 +256,37 @@ player_gain_resource: ld [hl], a @skip: ret + + ; sub routine for game over + ; never call outside of blank! +player_game_over: + ; if timer is not set + ; set up game over now + ld a, [game_over_timer] + cp a, 0 + jr nz, @game_over_timer REL + + ld hl, STR_GAME_OVER + ld de, SCRN0 + call puts + + ; set game over timer + ld a, 60 + ld [game_over_timer], a + + ret +@game_over_timer: + ; otherwise timer-- + ; and wait + dec a + ld [game_over_timer], a + ; if timer has reached 1 restart game + cp a, 0 + jr z, @restart REL + + ret +@restart: + ; restart game + ; TODO: maybe just go to title? + ; FIXME: this is not clearing the stack! + jp entry diff --git a/src/strings.s b/src/strings.s index 5bd025a..4080d9d 100644 --- a/src/strings.s +++ b/src/strings.s @@ -17,6 +17,10 @@ STR_HP: .db 0 STR_MP: .str "MP" +.db 0 + +STR_GAME_OVER: +.str "GAME OVER" .db 0 ; print a string 0-terminated to the screen diff --git a/src/video.s b/src/video.s index 6ca5cff..619840c 100644 --- a/src/video.s +++ b/src/video.s @@ -31,8 +31,18 @@ vblank: ld [RBGP], a ret ; return for one more frame @no_damage_taken: + call ui_draw + + ; check for game over animation + ld a, [player+player_hp] + cp a, 0 + jr nz, @not_game_over REL + call player_game_over + ret ; never set frame to be ready during game-over +@not_game_over: + ld a, 1 ld [frame_ready], a ret diff --git a/src/wram.s b/src/wram.s index 8026d8d..76eae6d 100644 --- a/src/wram.s +++ b/src/wram.s @@ -95,3 +95,7 @@ tmp: .adv 16 ; itmp is the same as tmp but ; for use during an interrupt itmp: .adv 16 + + ; timer for game over. when + ; it reaches 0 re-start game +game_over_timer: .adv 1 -- 2.30.2