Skip to content

Commit

Permalink
Add version info to game over screen
Browse files Browse the repository at this point in the history
  • Loading branch information
commandblockguy committed Mar 2, 2020
1 parent ee405ce commit 5b697b5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
23 changes: 21 additions & 2 deletions src/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand All @@ -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++) {
Expand Down
1 change: 1 addition & 0 deletions src/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum {
DINO_BOX_COLOR = 7,
BLACK = 8,
WHITE = 9,
FADE_TEXT = 10
};

void init_graphics(void);
Expand Down
16 changes: 16 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 5b697b5

Please sign in to comment.