Skip to content

Commit

Permalink
Merge branch 'SuperTux:master' into yeti-confetti
Browse files Browse the repository at this point in the history
  • Loading branch information
weluvgoatz authored Jul 9, 2024
2 parents ac0000a + bc06d8c commit 79c9b7b
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/badguy/badguy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ BadGuy::update(float dt_sec)
}

// Deactivate badguy, if off-screen and not falling down.
if (m_is_active_flag && is_offscreen() && m_physic.get_velocity_y() <= 0.f)
if (m_is_active_flag && is_offscreen() && m_physic.get_velocity_y() <= 0.f && !always_active())
{
deactivate();
set_state(STATE_INACTIVE);
Expand Down
2 changes: 2 additions & 0 deletions src/badguy/badguy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class BadGuy : public MovingSprite,
Returns false if enemy is spiky or too large */
virtual bool is_snipable() const { return false; }

virtual bool always_active() const { return false; }

bool is_frozen() const;

bool is_in_water() const;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/dispenser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Dispenser final : public BadGuy
virtual void unfreeze(bool melt = true) override;
virtual bool is_freezable() const override;
virtual bool is_flammable() const override;
virtual bool always_active() const override { return true; }
virtual bool is_portable() const override;

static std::string class_name() { return "dispenser"; }
Expand Down
15 changes: 13 additions & 2 deletions src/object/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2379,7 +2379,7 @@ Player::on_flip(float height)
{
Vector pos = get_pos();
pos.y = height - pos.y - get_bbox().get_height();
set_pos(pos);
set_pos_reset(pos);
}

void
Expand Down Expand Up @@ -2492,6 +2492,17 @@ Player::set_pos(const Vector& vector)
{
MovingObject::set_pos(vector);

// Make sure objects following Tux move directly with him
position_grabbed_object(true);
for (Key* key : m_collected_keys)
key->update_pos();
}

void
Player::set_pos_reset(const Vector& vector)
{
m_col.set_pos(vector);

// Reset size to get correct hitbox if Tux was eg. ducked before moving
if (is_big())
m_col.set_size(TUX_WIDTH, BIG_TUX_HEIGHT);
Expand Down Expand Up @@ -3002,7 +3013,7 @@ Player::multiplayer_respawn()
set_group(COLGROUP_MOVING);
m_physic.reset();

set_pos(target->get_pos());
set_pos_reset(target->get_pos());
m_target.reset();
}

Expand Down
3 changes: 3 additions & 0 deletions src/object/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ class Player final : public MovingObject
void handle_horizontal_input();
void handle_vertical_input();

/** Set Tux's position, reset state and velocity. */
void set_pos_reset(const Vector& vector);

void do_jump_apex();
void early_jump_apex();

Expand Down
1 change: 1 addition & 0 deletions src/object/thunderstorm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Thunderstorm::update(float )
return;
}

alpha *= static_cast<float>(g_config->flash_intensity) / 100.0f;
m_flash_color = Color(alpha, alpha, alpha, 1.0);
}

Expand Down
5 changes: 4 additions & 1 deletion src/supertux/gameconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Config::Config() :
music_enabled(true),
sound_volume(100),
music_volume(50),
flash_intensity(50),
random_seed(0), // Set by time(), by default (unless in config).
enable_script_debugger(false),
tux_spawn_pos(),
Expand Down Expand Up @@ -143,6 +144,7 @@ Config::load()
auto config_mapping = root.get_mapping();
config_mapping.get("profile", profile);

config_mapping.get("flash_intensity", flash_intensity);
config_mapping.get("frame_prediction", frame_prediction);
config_mapping.get("show_fps", show_fps);
config_mapping.get("show_player_pos", show_player_pos);
Expand Down Expand Up @@ -441,6 +443,8 @@ Config::save()
writer.write("aspect_width", aspect_size.width);
writer.write("aspect_height", aspect_size.height);

writer.write("flash_intensity", flash_intensity);

#ifdef __EMSCRIPTEN__
// Forcibly set autofit to true
// TODO: Remove the autofit parameter entirely - it should always be true
Expand Down Expand Up @@ -508,7 +512,6 @@ Config::check_values()
camera_peek_multiplier = math::clamp(camera_peek_multiplier, 0.f, 1.f);
}


bool
Config::is_christmas() const
{
Expand Down
1 change: 1 addition & 0 deletions src/supertux/gameconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Config final
bool music_enabled;
int sound_volume;
int music_volume;
int flash_intensity;

/** initial random seed. 0 ==> set from time() */
int random_seed;
Expand Down
49 changes: 46 additions & 3 deletions src/supertux/menu/options_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ OptionsMenu::less_than_volume(const std::string& lhs, const std::string& rhs)
return false;
}


OptionsMenu::OptionsMenu(Type type, bool complete) :
m_magnifications(),
m_aspect_ratios(),
Expand All @@ -64,6 +63,7 @@ OptionsMenu::OptionsMenu(Type type, bool complete) :
m_vsyncs(),
m_sound_volumes(),
m_music_volumes(),
m_flash_intensity_values(),
m_mobile_control_scales()
{
switch (type) // Insert label and menu items, appropriate for the chosen OptionsMenu type
Expand Down Expand Up @@ -113,6 +113,8 @@ OptionsMenu::OptionsMenu(Type type, bool complete) :
add_toggle(MNID_FRAME_PREDICTION, _("Frame prediction"), &g_config->frame_prediction)
.set_help(_("Smooth camera motion, generating intermediate frames. This has a noticeable effect on monitors at >> 60Hz. Moving objects may be blurry."));

add_flash_intensity();

#if !defined(HIDE_NONMOBILE_OPTIONS) && !defined(__EMSCRIPTEN__)
add_aspect_ratio();
#endif
Expand Down Expand Up @@ -511,6 +513,42 @@ OptionsMenu::add_music_volume()
.set_help(_("Adjust music volume"));
}

void
OptionsMenu::add_flash_intensity()
{
m_flash_intensity_values.list = { "0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%" };

std::ostringstream flash_intensity_value_stream;
flash_intensity_value_stream << g_config->flash_intensity << "%";
std::string flash_intensity_string = flash_intensity_value_stream.str();

if (std::find(m_flash_intensity_values.list.begin(),
m_flash_intensity_values.list.end(), flash_intensity_string) == m_flash_intensity_values.list.end())
{
m_flash_intensity_values.list.push_back(flash_intensity_string);
}

std::sort(m_flash_intensity_values.list.begin(), m_flash_intensity_values.list.end(), less_than_volume);

std::ostringstream out;
out << g_config->flash_intensity << "%";
std::string flash_intensity_value = out.str();
int count = 0;
for (const auto& value : m_flash_intensity_values.list)
{
if (value == flash_intensity_value)
{
flash_intensity_value.clear();
m_flash_intensity_values.next = count;
break;
}
++count;
}

add_string_select(MNID_FLASH_INTENSITY, _("Flash Intensity"), &m_flash_intensity_values.next, m_flash_intensity_values.list)
.set_help(_("Adjust the intensity of the flash produced by the thunderstorm"));
}

void
OptionsMenu::add_mobile_control_scales()
{
Expand All @@ -524,15 +562,13 @@ OptionsMenu::add_mobile_control_scales()
add_string_select(MNID_MOBILE_CONTROLS_SCALE, _("On-screen controls scale"), &m_mobile_control_scales.next, m_mobile_control_scales.list);
}


void
OptionsMenu::on_window_resize()
{
set_center_pos(static_cast<float>(SCREEN_WIDTH) / 2.0f,
static_cast<float>(SCREEN_HEIGHT) / 2.0f + 15.0f);
}


void
OptionsMenu::menu_action(MenuItem& item)
{
Expand Down Expand Up @@ -709,6 +745,13 @@ OptionsMenu::menu_action(MenuItem& item)
}
break;

case MNID_FLASH_INTENSITY:
if (sscanf(m_flash_intensity_values.list[m_flash_intensity_values.next].c_str(), "%i", &g_config->flash_intensity) == 1)
{
g_config->save();
}
break;

case MNID_CUSTOM_TITLE_LEVELS:
TitleScreen::current()->refresh_level();
break;
Expand Down
3 changes: 3 additions & 0 deletions src/supertux/menu/options_menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class OptionsMenu final : public Menu
void add_vsync();
void add_sound_volume();
void add_music_volume();
void add_flash_intensity();
void add_mobile_control_scales();

private:
Expand All @@ -70,6 +71,7 @@ class OptionsMenu final : public Menu
MNID_MUSIC,
MNID_SOUND_VOLUME,
MNID_MUSIC_VOLUME,
MNID_FLASH_INTENSITY,
MNID_RUMBLING,
MNID_DEVELOPER_MODE,
MNID_CHRISTMAS_MODE,
Expand Down Expand Up @@ -97,6 +99,7 @@ class OptionsMenu final : public Menu
StringOption m_vsyncs;
StringOption m_sound_volumes;
StringOption m_music_volumes;
StringOption m_flash_intensity_values;
StringOption m_mobile_control_scales;

private:
Expand Down

0 comments on commit 79c9b7b

Please sign in to comment.