new: ja es pot començar el joc els dos jugador a l'hora

new: feedback visual per a saber qui ha pulsat start en la pantalla de titol
Player: afegit estat RESPAWNING per no tindre que estar fent cabrioles amb la invulnerabilitat al crear als jugadors
This commit is contained in:
2025-07-14 11:41:12 +02:00
parent e14336bad9
commit 31910b8a74
9 changed files with 309 additions and 112 deletions

View File

@@ -102,10 +102,7 @@ void Credits::update()
balloon_manager_->update();
updateTextureDstRects();
throwBalloons();
for (auto &player : players_)
{
player->update();
}
updatePlayers();
updateAllFades();
++counter_;
}
@@ -254,10 +251,7 @@ void Credits::fillCanvas()
// Dibuja el fondo, los globos y los jugadores
tiled_bg_->render();
balloon_manager_->render();
for (auto const &player : players_)
{
player->render();
}
renderPlayers();
// Dibuja los titulos de credito
SDL_RenderTexture(Screen::get()->getRenderer(), text_texture_, &credits_rect_src_, &credits_rect_dst_);
@@ -381,19 +375,17 @@ void Credits::initPlayers()
}
// Crea los dos jugadores
constexpr int player_width = 30;
const int y = play_area_.y + play_area_.h - player_width;
constexpr bool demo = false;
constexpr int away_distance = 700;
players_.emplace_back(std::make_unique<Player>(1, play_area_.x - away_distance - player_width, y, demo, play_area_, player_textures.at(0), player_animations));
constexpr int PLAYER_WIDTH = 32;
const int Y = play_area_.y + play_area_.h - PLAYER_WIDTH;
constexpr bool DEMO = false;
constexpr int AWAY_DISTANCE = 700;
players_.emplace_back(std::make_unique<Player>(1, play_area_.x - AWAY_DISTANCE - PLAYER_WIDTH, Y, DEMO, play_area_, player_textures.at(0), player_animations));
players_.back()->setWalkingState(PlayerState::WALKING_RIGHT);
players_.back()->setPlayingState(PlayerState::CREDITS);
players_.back()->setInvulnerable(false);
players_.emplace_back(std::make_unique<Player>(2, play_area_.x + play_area_.w + away_distance, y, demo, play_area_, player_textures.at(1), player_animations));
players_.emplace_back(std::make_unique<Player>(2, play_area_.x + play_area_.w + AWAY_DISTANCE, Y, DEMO, play_area_, player_textures.at(1), player_animations));
players_.back()->setWalkingState(PlayerState::WALKING_LEFT);
players_.back()->setPlayingState(PlayerState::CREDITS);
players_.back()->setInvulnerable(false);
}
// Actualiza los rectangulos negros
@@ -532,3 +524,21 @@ void Credits::cycleColors()
// Aplicar el color, redondeando a enteros antes de usar
tiled_bg_->setColor(Color(static_cast<int>(r), static_cast<int>(g), static_cast<int>(b)));
}
// Actualza los jugadores
void Credits::updatePlayers()
{
for (auto &player : players_)
{
player->update();
}
}
// Renderiza los jugadores
void Credits::renderPlayers()
{
for (auto const &player : players_)
{
player->render();
}
}