From 5b697b5727cba5f189b78203ef55c2ed97c6809a Mon Sep 17 00:00:00 2001 From: commandblockguy Date: Mon, 2 Mar 2020 16:32:52 -0600 Subject: [PATCH] Add version info to game over screen --- src/config.h | 9 +++++++-- src/graphics.c | 23 +++++++++++++++++++++-- src/graphics.h | 1 + src/main.c | 16 ++++++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/config.h b/src/config.h index c6e0509..2d265aa 100644 --- a/src/config.h +++ b/src/config.h @@ -12,6 +12,11 @@ #define ONE_SECOND 32768 #define FRAME_TIME (ONE_SECOND / FPS) +#define TEXT_FADE_DELAY (ONE_SECOND * 2) +#define TEXT_FADE_TIME (ONE_SECOND * 2) +#define TEXT_FADE_FINAL_COLOR 128 +#define DO_FADE_TEXT 1 + #ifndef SHOW_FPS #define SHOW_FPS 0 #endif @@ -50,10 +55,10 @@ #define COMMIT (N/A) #endif #ifndef DIFF_STATUS -#define DIFF_STATUS (N/A) +#define DIFF_STATUS 1 #endif #ifndef VERSION -#define VERSION 1.0 +#define VERSION 1.1 #endif diff --git a/src/graphics.c b/src/graphics.c index 7f81473..f721a77 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -244,11 +244,25 @@ void fps_counter(void) { void draw_game_over(void) { const char game_over_text[] = "GAMEOVER"; + const char version_string[] = xstr(VERSION) "-" xstr(COMMIT) +#if DIFF_STATUS + "*" +#endif +#ifdef __clang__ + "L" +#elif __ZILOG__ + "Z" +#endif +#if USE_USB + "U" +#endif +; const uint24_t base_x = (LCD_WIDTH - GAME_OVER_TOTAL_WIDTH) / 2; uint8_t i; gfx_SetDrawScreen(); fontlib_SetColors(FG_COLOR, BG_COLOR); + gfx_palette[FADE_TEXT] = 0x0000; for(i = 0; i < strlen(game_over_text); i++) { uint24_t x = base_x + (GAME_OVER_TEXT_WIDTH + GAME_OVER_TEXT_SPACING) * i; @@ -259,6 +273,11 @@ void draw_game_over(void) { gfx_RLETSprite(restart, (LCD_WIDTH - restart_width) / 2, RESTART_BUTTON_Y); + gfx_SetTextFGColor(FADE_TEXT); + gfx_PrintStringXY("Dino Run CE by commandblockguy", 3, LCD_HEIGHT - 18); + gfx_PrintStringXY("https://discord.gg/DZbmraw", 3, LCD_HEIGHT - 10); + gfx_PrintStringXY(version_string, LCD_WIDTH - gfx_GetStringWidth(version_string) - 3, 2); + gfx_SetDrawBuffer(); } @@ -277,9 +296,9 @@ void invert_palette(bool day) { uint16_t *target_palette; if(day) { - target_palette = gfx_pal; + target_palette = (uint16_t*)gfx_pal; } else { - target_palette = night_pal; + target_palette = (uint16_t*)night_pal; } for(i = DYNAMIC_PALETTE_START; i < DYNAMIC_PALETTE_SIZE + DYNAMIC_PALETTE_START; i++) { diff --git a/src/graphics.h b/src/graphics.h index c2ef0af..bc623a1 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -38,6 +38,7 @@ enum { DINO_BOX_COLOR = 7, BLACK = 8, WHITE = 9, + FADE_TEXT = 10 }; void init_graphics(void); diff --git a/src/main.c b/src/main.c index 612b397..8193023 100644 --- a/src/main.c +++ b/src/main.c @@ -109,12 +109,27 @@ bool play(void) { } bool game_over(void) { + uint32_t initial_time = timer_1_Counter; draw_game_over(); #if USE_SOUND play_sound(&game.sound_player, &sounds[SOUND_DEATH]); #endif while(true) { +#if DO_FADE_TEXT + uint24_t capped_counter; + if(timer_1_Counter - initial_time < TEXT_FADE_DELAY) { + capped_counter = 0; + } else if(timer_1_Counter - initial_time > TEXT_FADE_TIME - 1 + TEXT_FADE_DELAY) { + capped_counter = TEXT_FADE_TIME - 1; + } else { + capped_counter = timer_1_Counter - initial_time - TEXT_FADE_DELAY; + } + + /* Fade in the text */ + gfx_palette[FADE_TEXT] = gfx_Darken(0xFFFF, capped_counter / (TEXT_FADE_TIME / TEXT_FADE_FINAL_COLOR)); +#endif + kb_Scan(); if(kb_IsDown(kb_KeyClear)) return true; @@ -169,6 +184,7 @@ void main(void) { game.next_beep_score = 100; set_dynamic_palette(true); + gfx_palette[FADE_TEXT] = 0; init_obstacles(); init_clouds();