-
-
Notifications
You must be signed in to change notification settings - Fork 476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tux emits bubbles while being underwater #3014
Open
bruhmoent
wants to merge
12
commits into
SuperTux:master
Choose a base branch
from
bruhmoent:bubbles
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f5eea9b
Add bubbles while being underwater
bruhmoent cc9dbbb
Leftovers
bruhmoent a7f5358
Add bubble particles made by @RustyBox [ci skip]
bruhmoent 369742a
Fix a bug + Add a chance for multiple bubbles to spawn
bruhmoent 6605fa6
Code style
bruhmoent d324f56
Bug fixes + suggestions
bruhmoent ec30ddb
Fix builds
bruhmoent 913b087
Adjustments
bruhmoent bf3104b
Use .sprite + code style fixes
bruhmoent 2dd2afa
Fix builds
bruhmoent 32e9108
Consistency
bruhmoent 292959e
Unnecessary include
bruhmoent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
(supertux-sprite | ||
(action | ||
(name "normal") | ||
(fps 15) | ||
(loops 1) | ||
(images "air_bubble-0.png" | ||
"air_bubble-1.png" | ||
"air_bubble-2.png" | ||
"air_bubble-3.png" | ||
"air_bubble-4.png" | ||
) | ||
) | ||
(action | ||
(name "small") | ||
(fps 15) | ||
(loops 1) | ||
(images "air_bubble-0.png" | ||
"air_bubble-1.png" | ||
"air_bubble-2.png" | ||
"air_bubble-3.png" | ||
) | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,6 +226,7 @@ Player::Player(PlayerStatus& player_status, const std::string& name_, int player | |
m_swimming_accel_modifier(100.f), | ||
m_water_jump(false), | ||
m_airarrow(Surface::from_file("images/engine/hud/airarrow.png")), | ||
m_bubbles_sprite(SpriteManager::current()->create("images/particles/air_bubble.sprite")), | ||
m_floor_normal(0.0f, 0.0f), | ||
m_ghost_mode(false), | ||
m_unduck_hurt_timer(), | ||
|
@@ -254,6 +255,8 @@ Player::Player(PlayerStatus& player_status, const std::string& name_, int player | |
SoundManager::current()->preload("sounds/invincible_start.ogg"); | ||
SoundManager::current()->preload("sounds/splash.wav"); | ||
SoundManager::current()->preload("sounds/grow.wav"); | ||
m_bubble_timer.start(3.0f + graphicsRandom.randf(2)); | ||
|
||
m_col.set_size(TUX_WIDTH, is_big() ? BIG_TUX_HEIGHT : SMALL_TUX_HEIGHT); | ||
|
||
m_sprite->set_angle(0.0f); | ||
|
@@ -412,6 +415,22 @@ Player::update(float dt_sec) | |
} | ||
} | ||
|
||
if (!m_active_bubbles.empty()) | ||
{ | ||
for (auto& bubble : m_active_bubbles) | ||
{ | ||
bubble.second.y -= dt_sec * 40.0f; | ||
bubble.second.x += std::sin(bubble.second.y * 0.1f) * dt_sec * 5.0f; | ||
} | ||
|
||
m_active_bubbles.remove_if([&](const std::pair<SurfacePtr, Vector>& bubble) | ||
{ | ||
Rectf bubble_box(bubble.second.x, bubble.second.y, bubble.second.x + 16.f, bubble.second.y + 16.f); | ||
bool is_out_of_water = Sector::get().is_free_of_tiles(bubble_box, true, Tile::WATER); | ||
return is_out_of_water; | ||
}); | ||
} | ||
|
||
// Skip if in multiplayer respawn | ||
if (is_dead() && m_target && Sector::get().get_object_count<Player>([this](const Player& p) { return !p.is_dead() && !p.is_dying() && !p.is_winning() && &p != this; })) | ||
{ | ||
|
@@ -514,6 +533,72 @@ Player::update(float dt_sec) | |
if (m_physic.get_velocity_y() > -350.f && m_controller->hold(Control::UP)) | ||
m_physic.set_velocity_y(-350.f); | ||
} | ||
|
||
if (m_bubble_timer.check()) | ||
{ | ||
Vector beak_local_offset(30.f, 0.0f); | ||
float big_offset_x = is_big() ? 4.0f : 0.0f; | ||
|
||
// Calculate the offsets based on the sprite angle | ||
float offset_x = std::cos(m_swimming_angle) * 10.0f; | ||
float offset_y = std::sin(m_swimming_angle) * 10.0f; | ||
|
||
// Rotate the beak offset based on the sprite's angle | ||
float rotated_beak_offset_x = beak_local_offset.x * std::cos(m_swimming_angle) - beak_local_offset.y * std::sin(m_swimming_angle); | ||
float rotated_beak_offset_y = beak_local_offset.x * std::sin(m_swimming_angle) + beak_local_offset.y * std::cos(m_swimming_angle); | ||
|
||
Vector player_center = m_col.m_bbox.get_middle(); | ||
Vector beak_position; | ||
|
||
// Determine direction based on the radians | ||
if (std::abs(m_swimming_angle) > static_cast<float>(math::PI_2)) // Facing left | ||
{ | ||
beak_position = player_center + Vector(rotated_beak_offset_x - big_offset_x * 2, rotated_beak_offset_y); | ||
} | ||
else // Facing right (including straight up or down) | ||
{ | ||
beak_position = player_center + Vector(rotated_beak_offset_x - 4.0f + big_offset_x, rotated_beak_offset_y); | ||
} | ||
|
||
int num_bubbles = graphicsRandom.rand(1, 3); | ||
|
||
std::optional<std::vector<SurfacePtr>> bubble_surfaces = m_bubbles_sprite->get_action_surfaces("normal"); | ||
|
||
if (bubble_surfaces) | ||
{ | ||
const std::vector<SurfacePtr>& surfaces = bubble_surfaces.value(); | ||
int surfaces_size = static_cast<int>(surfaces.size()); | ||
|
||
for (int i = 0; i < num_bubbles; ++i) | ||
{ | ||
int random_index = graphicsRandom.rand(1, surfaces_size - 1); | ||
SurfacePtr bubble_surface = surfaces.at(random_index); | ||
|
||
Vector bubble_pos(0.f, 0.f); | ||
if (std::abs(m_swimming_angle) > static_cast<float>(math::PI_2)) // Facing left | ||
{ | ||
bubble_pos = beak_position + Vector(offset_x - big_offset_x * 2, offset_y); | ||
} | ||
else // Facing right (including straight up or down) | ||
{ | ||
bubble_pos = beak_position + Vector(offset_x - 4.0f + big_offset_x, offset_y); | ||
} | ||
|
||
if (num_bubbles > 1) | ||
{ | ||
float burst_offset_x = graphicsRandom.randf(-5.0f, 5.0f); | ||
float burst_offset_y = graphicsRandom.randf(-5.0f, 5.0f); | ||
bubble_pos.x += burst_offset_x; | ||
bubble_pos.y += burst_offset_y; | ||
} | ||
|
||
m_active_bubbles.push_back({ bubble_surface, bubble_pos }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} | ||
|
||
// Restart the timer for the next wave of bubbles | ||
m_bubble_timer.start(0.8f + graphicsRandom.randf(0.0f, 0.6f)); | ||
} | ||
} | ||
else | ||
{ | ||
|
@@ -2245,10 +2330,13 @@ Player::draw(DrawingContext& context) | |
get_bonus() == EARTH_BONUS ? Color(1.f, 0.9f, 0.6f) : | ||
Color(1.f, 1.f, 1.f)); | ||
|
||
for (auto bubble_sprite : m_active_bubbles) | ||
{ | ||
context.color().draw_surface(bubble_sprite.first, bubble_sprite.second, LAYER_TILES - 5); | ||
} | ||
m_sprite->set_color(m_stone ? Color(1.f, 1.f, 1.f) : power_color); | ||
} | ||
|
||
|
||
void | ||
Player::collision_tile(uint32_t tile_attributes) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure the bubble pops when hitting solid tiles.