Skip to content

Commit

Permalink
Indicate modes when loading in to gameplay
Browse files Browse the repository at this point in the history
If you load in to gameplay with invincibility mode, glitchrunner mode,
Flip Mode, or slowdown enabled, then there will be text displayed on
screen for a few seconds that says so.

This is to serve as a useful reminder. A common pitfall with using
invincibility is forgetting to turn it off when you don't want it
anymore. What usually happens is that players forget that they have it
on until they encounter a hazard. Now, they can realize it as soon as
they load in.

See #1091.
  • Loading branch information
InfoTeddy committed Jan 8, 2024
1 parent 6e43688 commit 8301760
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 1 deletion.
3 changes: 3 additions & 0 deletions desktop_version/src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ void Game::init(void)
old_skip_message_timer = 0;
skip_message_timer = 0;

old_mode_indicator_timer = 0;
mode_indicator_timer = 0;

setdefaultcontrollerbuttons();
}

Expand Down
3 changes: 3 additions & 0 deletions desktop_version/src/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,9 @@ class Game

int old_skip_message_timer;
int skip_message_timer;

int old_mode_indicator_timer;
int mode_indicator_timer;
};

#ifndef GAME_DEFINITION
Expand Down
98 changes: 97 additions & 1 deletion desktop_version/src/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,91 @@ static const char* interact_prompt(
return buffer;
}

static void mode_indicator_text(const int alpha)
{
const int flags = PR_BRIGHTNESS(alpha) | PR_BOR;
const int r = 220 - help.glow;
const int g = 220 - help.glow;
const int b = 255 - help.glow/2;
const int x = 5;
const int spacing = font::height(flags) + 2;
int y = 5;
if (game.advancetext)
{
/* Prevent clashing */
y += 15;
}

/* FIXME: Some strings have not yet been translated. In order to not have
* English text in other languages, they are substituted with existing
* ones. Remove all substitute text when they're fully translated. */

if (map.invincibility)
{
const char* english = "Invincibility mode enabled";
const char* text = loc::gettext(english);
if (loc::lang != "en" && SDL_strcmp(english, text) == 0)
{
/* Substitute text */
text = loc::gettext("Invincibility");
}
font::print(flags, x, y, text, r, g, b);
y += spacing;
}

enum GlitchrunnerMode mode = GlitchrunnerMode_get();
if (mode != GlitchrunnerNone)
{
char buffer[SCREEN_WIDTH_CHARS + 1];
const char* english = "Glitchrunner mode enabled ({version})";
const char* text = loc::gettext(english);
if (loc::lang != "en" && SDL_strcmp(english, text) == 0)
{
/* Substitute text */
SDL_strlcpy(buffer, loc::gettext("Glitchrunner Mode"), sizeof(buffer));
}
else
{
const char* mode_string = loc::gettext(GlitchrunnerMode_enum_to_string(mode));
vformat_buf(
buffer, sizeof(buffer),
loc::gettext("Glitchrunner mode is {version}"),
"version:str", mode_string
);
}
font::print(flags, x, y, buffer, r, g, b);
y += spacing;
}

if (graphics.flipmode)
{
const char* english = "Flip Mode enabled";
const char* text = loc::gettext(english);
if (loc::lang != "en" && SDL_strcmp(english, text) == 0)
{
/* Substitute text */
text = loc::gettext("Flip Mode");
}
font::print(flags, x, y, text, r, g, b);
y += spacing;
}

switch (game.slowdown)
{
case 24:
font::print(flags, x, y, loc::gettext("Game speed is at 80%"), r, g, b);
y += spacing;
break;
case 18:
font::print(flags, x, y, loc::gettext("Game speed is at 60%"), r, g, b);
y += spacing;
break;
case 12:
font::print(flags, x, y, loc::gettext("Game speed is at 40%"), r, g, b);
y += spacing;
}
}

void gamerender(void)
{
graphics.set_render_target(graphics.gameplayTexture);
Expand Down Expand Up @@ -2215,14 +2300,20 @@ void gamerender(void)
draw_return_editor_text = return_editor_alpha > 100;
}

int mode_indicator_alpha = graphics.lerp(
game.old_mode_indicator_timer, game.mode_indicator_timer
);
bool draw_mode_indicator_text = mode_indicator_alpha > 100;

if (graphics.fademode == FADE_NONE
&& !game.intimetrial
&& !game.isingamecompletescreen()
&& (!game.swnmode || game.swngame != SWN_SUPERGRAVITRON)
&& game.showingametimer
&& !roomname_translator::enabled
&& (!game.swnmode || game.swngame != SWN_START_GRAVITRON_STEP_3)
&& !draw_return_editor_text)
&& !draw_return_editor_text
&& !draw_mode_indicator_text)
{
const char* tempstring = loc::gettext("TIME:");
int label_len = font::len(0, tempstring);
Expand Down Expand Up @@ -2285,6 +2376,11 @@ void gamerender(void)

graphics.drawgui();

if (draw_mode_indicator_text && !draw_return_editor_text)
{
mode_indicator_text(mode_indicator_alpha);
}

graphics.set_render_target(graphics.gameTexture);

graphics.copy_texture(graphics.gameplayTexture, NULL, NULL);
Expand Down
6 changes: 6 additions & 0 deletions desktop_version/src/RenderFixed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ void gamerenderfixed(void)
ed.return_message_timer -= 15;
}

game.old_mode_indicator_timer = game.mode_indicator_timer;
if (game.mode_indicator_timer > 0)
{
game.mode_indicator_timer -= 15;
}

// Editor ghosts!
if (game.ghostsenabled)
{
Expand Down
15 changes: 15 additions & 0 deletions desktop_version/src/Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,21 @@ void scriptclass::startgamemode(const enum StartMode mode)
font::set_level_font_interface();
}

/* Indicate invincibility, glitchrunner, etc. for all modes except these */
switch (mode)
{
case Start_EDITOR:
case Start_CUTSCENETEST:
break;
case Start_QUIT:
VVV_unreachable();

default:
/* If there's editor return text, make this show up after it */
game.mode_indicator_timer = ed.return_message_timer + 2000;
game.old_mode_indicator_timer = game.mode_indicator_timer;
}

game.jumpheld = true;

switch (mode)
Expand Down

0 comments on commit 8301760

Please sign in to comment.