Ja es por canviar el jugador que maneja el teclat "en calent" desde el service menu
This commit is contained in:
@@ -72,6 +72,9 @@ Credits::~Credits() {
|
||||
SDL_DestroyTexture(canvas_);
|
||||
resetVolume();
|
||||
Audio::get()->stopMusic();
|
||||
|
||||
// Desregistra los jugadores de Options
|
||||
Options::keyboard.clearPlayers();
|
||||
}
|
||||
|
||||
// Bucle principal
|
||||
@@ -326,36 +329,29 @@ void Credits::initPlayers() {
|
||||
std::vector<std::vector<std::string>> player_animations; // Vector con las animaciones del jugador
|
||||
|
||||
// Texturas - Player1
|
||||
{
|
||||
std::vector<std::shared_ptr<Texture>> player_texture;
|
||||
player_texture.emplace_back(Resource::get()->getTexture("player1.gif"));
|
||||
player_texture.emplace_back(Resource::get()->getTexture("player1_power.png"));
|
||||
player_textures.push_back(player_texture);
|
||||
}
|
||||
std::vector<std::shared_ptr<Texture>> player1_textures;
|
||||
player1_textures.emplace_back(Resource::get()->getTexture("player1.gif"));
|
||||
player1_textures.emplace_back(Resource::get()->getTexture("player1_power.png"));
|
||||
player_textures.push_back(player1_textures);
|
||||
|
||||
// Texturas - Player2
|
||||
{
|
||||
std::vector<std::shared_ptr<Texture>> player_texture;
|
||||
player_texture.emplace_back(Resource::get()->getTexture("player2.gif"));
|
||||
player_texture.emplace_back(Resource::get()->getTexture("player2_power.png"));
|
||||
player_textures.push_back(player_texture);
|
||||
}
|
||||
std::vector<std::shared_ptr<Texture>> player2_textures;
|
||||
player2_textures.emplace_back(Resource::get()->getTexture("player2.gif"));
|
||||
player2_textures.emplace_back(Resource::get()->getTexture("player2_power.png"));
|
||||
player_textures.push_back(player2_textures);
|
||||
|
||||
// Animaciones -- Jugador
|
||||
{
|
||||
player_animations.emplace_back(Resource::get()->getAnimation("player.ani"));
|
||||
player_animations.emplace_back(Resource::get()->getAnimation("player_power.ani"));
|
||||
}
|
||||
player_animations.emplace_back(Resource::get()->getAnimation("player.ani"));
|
||||
player_animations.emplace_back(Resource::get()->getAnimation("player_power.ani"));
|
||||
|
||||
// Crea los dos jugadores
|
||||
constexpr int PLAYER_WIDTH = 32;
|
||||
const int Y = play_area_.y + play_area_.h - PLAYER_WIDTH;
|
||||
const int Y = play_area_.y + play_area_.h - Player::WIDTH;
|
||||
constexpr bool DEMO = false;
|
||||
constexpr int AWAY_DISTANCE = 700;
|
||||
|
||||
Player::Config config_player1;
|
||||
config_player1.id = Player::Id::PLAYER1;
|
||||
config_player1.x = play_area_.x - AWAY_DISTANCE - PLAYER_WIDTH;
|
||||
config_player1.x = play_area_.x - AWAY_DISTANCE - Player::WIDTH;
|
||||
config_player1.y = Y;
|
||||
config_player1.demo = DEMO;
|
||||
config_player1.play_area = &play_area_;
|
||||
@@ -380,6 +376,10 @@ void Credits::initPlayers() {
|
||||
players_.emplace_back(std::make_unique<Player>(config_player2));
|
||||
players_.back()->setWalkingState(Player::State::WALKING_LEFT);
|
||||
players_.back()->setPlayingState(Player::State::CREDITS);
|
||||
|
||||
// Registra los jugadores en Options
|
||||
Options::keyboard.addPlayer(players_.at(0));
|
||||
Options::keyboard.addPlayer(players_.at(1));
|
||||
}
|
||||
|
||||
// Actualiza los rectangulos negros
|
||||
|
||||
@@ -121,6 +121,9 @@ Game::~Game() {
|
||||
|
||||
Scoreboard::destroy();
|
||||
SDL_DestroyTexture(canvas_);
|
||||
|
||||
// Desregistra los jugadores de Options
|
||||
Options::keyboard.clearPlayers();
|
||||
}
|
||||
|
||||
// Asigna texturas y animaciones
|
||||
@@ -1637,6 +1640,10 @@ void Game::initPlayers(Player::Id player_id) {
|
||||
player->setPlayingState(demo_.enabled ? Player::State::PLAYING : Player::State::ENTERING_SCREEN);
|
||||
sendPlayerToTheFront(player);
|
||||
}
|
||||
|
||||
// Registra los jugadores en Options
|
||||
Options::keyboard.addPlayer(players_.at(0));
|
||||
Options::keyboard.addPlayer(players_.at(1));
|
||||
}
|
||||
|
||||
// Hace sonar la música
|
||||
|
||||
@@ -72,6 +72,9 @@ Title::~Title() {
|
||||
if (Section::name == Section::Name::LOGO) {
|
||||
Audio::get()->fadeOutMusic(300);
|
||||
}
|
||||
|
||||
// Desregistra los jugadores de Options
|
||||
Options::keyboard.clearPlayers();
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
@@ -208,11 +211,36 @@ void Title::checkInput() {
|
||||
|
||||
if (!ServiceMenu::get()->isEnabled()) {
|
||||
processControllerInputs();
|
||||
processKeyboardStart();
|
||||
}
|
||||
|
||||
GlobalInputs::check();
|
||||
}
|
||||
|
||||
void Title::processKeyboardStart() {
|
||||
if (!canProcessStartButton()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const bool START_PRESSED = Input::get()->checkAction(
|
||||
Input::Action::START,
|
||||
Input::DO_NOT_ALLOW_REPEAT,
|
||||
Input::CHECK_KEYBOARD);
|
||||
|
||||
if (START_PRESSED) {
|
||||
switch (Options::keyboard.player_id) {
|
||||
case Player::Id::PLAYER1:
|
||||
processPlayer1Start();
|
||||
break;
|
||||
case Player::Id::PLAYER2:
|
||||
processPlayer2Start();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Title::processControllerInputs() {
|
||||
for (const auto& controller : Options::gamepad_manager) {
|
||||
if (isStartButtonPressed(&controller)) {
|
||||
@@ -225,7 +253,7 @@ auto Title::isStartButtonPressed(const Options::Gamepad* controller) -> bool {
|
||||
return Input::get()->checkAction(
|
||||
Input::Action::START,
|
||||
Input::DO_NOT_ALLOW_REPEAT,
|
||||
Input::CHECK_KEYBOARD,
|
||||
Input::DO_NOT_CHECK_KEYBOARD,
|
||||
controller->instance);
|
||||
}
|
||||
|
||||
@@ -458,36 +486,28 @@ void Title::initPlayers() {
|
||||
std::vector<std::vector<std::string>> player_animations; // Vector con las animaciones del jugador
|
||||
|
||||
// Texturas - Player1
|
||||
{
|
||||
std::vector<std::shared_ptr<Texture>> player_texture;
|
||||
player_texture.emplace_back(Resource::get()->getTexture("player1.gif"));
|
||||
player_texture.emplace_back(Resource::get()->getTexture("player1_power.png"));
|
||||
player_textures.push_back(player_texture);
|
||||
}
|
||||
std::vector<std::shared_ptr<Texture>> player1_textures;
|
||||
player1_textures.emplace_back(Resource::get()->getTexture("player1.gif"));
|
||||
player1_textures.emplace_back(Resource::get()->getTexture("player1_power.png"));
|
||||
player_textures.push_back(player1_textures);
|
||||
|
||||
// Texturas - Player2
|
||||
{
|
||||
std::vector<std::shared_ptr<Texture>> player_texture;
|
||||
player_texture.emplace_back(Resource::get()->getTexture("player2.gif"));
|
||||
player_texture.emplace_back(Resource::get()->getTexture("player2_power.png"));
|
||||
player_textures.push_back(player_texture);
|
||||
}
|
||||
std::vector<std::shared_ptr<Texture>> player2_textures;
|
||||
player2_textures.emplace_back(Resource::get()->getTexture("player2.gif"));
|
||||
player2_textures.emplace_back(Resource::get()->getTexture("player2_power.png"));
|
||||
player_textures.push_back(player2_textures);
|
||||
|
||||
// Animaciones -- Jugador
|
||||
{
|
||||
player_animations.emplace_back(Resource::get()->getAnimation("player.ani"));
|
||||
player_animations.emplace_back(Resource::get()->getAnimation("player_power.ani"));
|
||||
}
|
||||
player_animations.emplace_back(Resource::get()->getAnimation("player.ani"));
|
||||
player_animations.emplace_back(Resource::get()->getAnimation("player_power.ani"));
|
||||
|
||||
// Crea los dos jugadores
|
||||
constexpr int PLAYER_WIDTH = 32;
|
||||
constexpr int PLAYER_HEIGHT = 32;
|
||||
const int Y = param.title.press_start_position - (PLAYER_HEIGHT / 2);
|
||||
const int Y = param.title.press_start_position - (Player::HEIGHT / 2);
|
||||
constexpr bool DEMO = false;
|
||||
|
||||
Player::Config config_player1;
|
||||
config_player1.id = Player::Id::PLAYER1;
|
||||
config_player1.x = param.game.game_area.center_x - (PLAYER_WIDTH / 2);
|
||||
config_player1.x = param.game.game_area.center_x - (Player::WIDTH / 2);
|
||||
config_player1.y = Y;
|
||||
config_player1.demo = DEMO;
|
||||
config_player1.play_area = ¶m.game.play_area.rect;
|
||||
@@ -500,7 +520,7 @@ void Title::initPlayers() {
|
||||
|
||||
Player::Config config_player2;
|
||||
config_player2.id = Player::Id::PLAYER2;
|
||||
config_player2.x = param.game.game_area.center_x - (PLAYER_WIDTH / 2);
|
||||
config_player2.x = param.game.game_area.center_x - (Player::WIDTH / 2);
|
||||
config_player2.y = Y;
|
||||
config_player2.demo = DEMO;
|
||||
config_player2.play_area = ¶m.game.play_area.rect;
|
||||
@@ -510,6 +530,10 @@ void Title::initPlayers() {
|
||||
config_player2.glowing_entry = &Options::settings.glowing_entries.at(static_cast<int>(Player::Id::PLAYER2) - 1);
|
||||
players_.emplace_back(std::make_unique<Player>(config_player2));
|
||||
players_.back()->setPlayingState(Player::State::TITLE_HIDDEN);
|
||||
|
||||
// Registra los jugadores en Options
|
||||
Options::keyboard.addPlayer(players_.at(0));
|
||||
Options::keyboard.addPlayer(players_.at(1));
|
||||
}
|
||||
|
||||
// Actualza los jugadores
|
||||
|
||||
@@ -57,12 +57,12 @@ class Title {
|
||||
};
|
||||
|
||||
// --- Objetos y punteros ---
|
||||
std::shared_ptr<Text> text_; // Objeto de texto para escribir en pantalla
|
||||
std::unique_ptr<Fade> fade_; // Fundido en pantalla
|
||||
std::unique_ptr<TiledBG> tiled_bg_; // Fondo animado de tiles
|
||||
std::unique_ptr<GameLogo> game_logo_; // Logo del juego
|
||||
std::unique_ptr<Sprite> mini_logo_sprite_; // Logo JailGames mini
|
||||
std::vector<std::shared_ptr<Player>> players_; // Vector de jugadores
|
||||
std::shared_ptr<Text> text_; // Objeto de texto para escribir en pantalla
|
||||
std::unique_ptr<Fade> fade_; // Fundido en pantalla
|
||||
std::unique_ptr<TiledBG> tiled_bg_; // Fondo animado de tiles
|
||||
std::unique_ptr<GameLogo> game_logo_; // Logo del juego
|
||||
std::unique_ptr<Sprite> mini_logo_sprite_; // Logo JailGames mini
|
||||
std::vector<std::shared_ptr<Player>> players_; // Vector de jugadores
|
||||
|
||||
// --- Variables de estado ---
|
||||
int counter_ = 0; // Temporizador para la pantalla de título
|
||||
@@ -88,6 +88,7 @@ class Title {
|
||||
void checkEvents(); // Comprueba los eventos
|
||||
void checkInput(); // Comprueba las entradas
|
||||
void handleKeyDownEvent(const SDL_Event& event); // Maneja el evento de tecla presionada
|
||||
void processKeyboardStart(); // Procesa las entradas del teclado
|
||||
void processControllerInputs(); // Procesa las entradas de los mandos
|
||||
[[nodiscard]] static auto isStartButtonPressed(const Options::Gamepad* controller) -> bool; // Comprueba si se ha pulsado el botón Start
|
||||
void handleStartButtonPress(const Options::Gamepad* controller); // Maneja la pulsación del botón Start
|
||||
|
||||
Reference in New Issue
Block a user