desacoplament de Player i Options
Player: canviat id de int a enum migrant input: eliminat Device, keyboard separat de la llista de mandos, llig i guarda configuracions de mandos falta: definir botons, asignar mandos a jugadors i guardar la asignació
This commit is contained in:
@@ -353,11 +353,32 @@ void Credits::initPlayers() {
|
||||
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));
|
||||
|
||||
Player::Config config_player1;
|
||||
config_player1.id = Player::Id::PLAYER1;
|
||||
config_player1.x = play_area_.x - AWAY_DISTANCE - PLAYER_WIDTH;
|
||||
config_player1.y = Y;
|
||||
config_player1.demo = DEMO;
|
||||
config_player1.play_area = &play_area_;
|
||||
config_player1.texture = player_textures.at(0);
|
||||
config_player1.animations = player_animations;
|
||||
config_player1.hi_score_table = &Options::settings.hi_score_table;
|
||||
config_player1.glowing_entry = &Options::settings.glowing_entries.at(static_cast<int>(Player::Id::PLAYER1) - 1);
|
||||
players_.emplace_back(std::make_unique<Player>(config_player1));
|
||||
players_.back()->setWalkingState(Player::State::WALKING_RIGHT);
|
||||
players_.back()->setPlayingState(Player::State::CREDITS);
|
||||
|
||||
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));
|
||||
Player::Config config_player2;
|
||||
config_player2.id = Player::Id::PLAYER2;
|
||||
config_player2.x = play_area_.x + play_area_.w + AWAY_DISTANCE;
|
||||
config_player2.y = Y;
|
||||
config_player2.demo = DEMO;
|
||||
config_player2.play_area = &play_area_;
|
||||
config_player2.texture = player_textures.at(1);
|
||||
config_player2.animations = player_animations;
|
||||
config_player2.hi_score_table = &Options::settings.hi_score_table;
|
||||
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()->setWalkingState(Player::State::WALKING_LEFT);
|
||||
players_.back()->setPlayingState(Player::State::CREDITS);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#include "ui/service_menu.h" // Para ServiceMenu
|
||||
|
||||
// Constructor
|
||||
Game::Game(int player_id, int current_stage, bool demo)
|
||||
Game::Game(Player::Id player_id, int current_stage, bool demo)
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
screen_(Screen::get()),
|
||||
input_(Input::get()),
|
||||
@@ -365,7 +365,7 @@ void Game::updateGameStateCompleted() {
|
||||
|
||||
for (auto &player : players_) {
|
||||
if (player->isPlaying()) {
|
||||
player->addScore(1000000);
|
||||
player->addScore(1000000, Options::settings.hi_score_table.back().score);
|
||||
player->setPlayingState(Player::State::CELEBRATING);
|
||||
} else {
|
||||
player->setPlayingState(Player::State::GAME_OVER);
|
||||
@@ -379,7 +379,7 @@ void Game::updateGameStateCompleted() {
|
||||
if (game_completed_counter_ == END_CELEBRATIONS) {
|
||||
for (auto &player : players_) {
|
||||
if (player->isCelebrating()) {
|
||||
player->setPlayingState(player->isEligibleForHighScore() ? Player::State::ENTERING_NAME_GAME_COMPLETED : Player::State::LEAVING_SCREEN);
|
||||
player->setPlayingState(player->qualifiesForHighScore() ? Player::State::ENTERING_NAME_GAME_COMPLETED : Player::State::LEAVING_SCREEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -435,28 +435,28 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player) {
|
||||
if (checkCollision(player->getCollider(), item->getCollider())) {
|
||||
switch (item->getType()) {
|
||||
case ItemType::DISK: {
|
||||
player->addScore(1000);
|
||||
player->addScore(1000, Options::settings.hi_score_table.back().score);
|
||||
const auto X = item->getPosX() + (item->getWidth() - game_text_textures_.at(0)->getWidth()) / 2;
|
||||
createItemText(X, game_text_textures_.at(0));
|
||||
playSound("item_pickup.wav");
|
||||
break;
|
||||
}
|
||||
case ItemType::GAVINA: {
|
||||
player->addScore(2500);
|
||||
player->addScore(2500, Options::settings.hi_score_table.back().score);
|
||||
const auto X = item->getPosX() + (item->getWidth() - game_text_textures_.at(1)->getWidth()) / 2;
|
||||
createItemText(X, game_text_textures_.at(1));
|
||||
playSound("item_pickup.wav");
|
||||
break;
|
||||
}
|
||||
case ItemType::PACMAR: {
|
||||
player->addScore(5000);
|
||||
player->addScore(5000, Options::settings.hi_score_table.back().score);
|
||||
const auto X = item->getPosX() + (item->getWidth() - game_text_textures_.at(2)->getWidth()) / 2;
|
||||
createItemText(X, game_text_textures_.at(2));
|
||||
playSound("item_pickup.wav");
|
||||
break;
|
||||
}
|
||||
case ItemType::DEBIAN: {
|
||||
player->addScore(100000);
|
||||
player->addScore(100000, Options::settings.hi_score_table.back().score);
|
||||
const auto X = item->getPosX() + (item->getWidth() - game_text_textures_.at(6)->getWidth()) / 2;
|
||||
createItemText(X, game_text_textures_.at(6));
|
||||
playSound("debian_pickup.wav");
|
||||
@@ -471,7 +471,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player) {
|
||||
}
|
||||
case ItemType::COFFEE: {
|
||||
if (player->getCoffees() == 2) {
|
||||
player->addScore(5000);
|
||||
player->addScore(5000, Options::settings.hi_score_table.back().score);
|
||||
const auto X = item->getPosX() + (item->getWidth() - game_text_textures_.at(2)->getWidth()) / 2;
|
||||
createItemText(X, game_text_textures_.at(2));
|
||||
} else {
|
||||
@@ -594,11 +594,11 @@ void Game::handleItemDrop(std::shared_ptr<Balloon> balloon, std::shared_ptr<Play
|
||||
|
||||
// Maneja la destrucción del globo y puntuación
|
||||
void Game::handleBalloonDestruction(std::shared_ptr<Balloon> balloon, std::shared_ptr<Player> player) {
|
||||
const auto SCORE = balloon_manager_->popBalloon(balloon);
|
||||
evaluateAndSetMenace();
|
||||
|
||||
if (player->isPlaying()) {
|
||||
player->addScore(SCORE * player->getScoreMultiplier() * difficulty_score_multiplier_);
|
||||
auto const SCORE = balloon_manager_->popBalloon(balloon) * player->getScoreMultiplier() * difficulty_score_multiplier_;
|
||||
player->addScore(SCORE, Options::settings.hi_score_table.back().score);
|
||||
player->incScoreMultiplier();
|
||||
}
|
||||
updateHiScore();
|
||||
@@ -621,7 +621,7 @@ void Game::renderBullets() {
|
||||
}
|
||||
|
||||
// Crea un objeto bala
|
||||
void Game::createBullet(int x, int y, BulletType kind, bool powered_up, int owner) {
|
||||
void Game::createBullet(int x, int y, BulletType kind, bool powered_up, Player::Id owner) {
|
||||
bullets_.emplace_back(std::make_shared<Bullet>(x, y, kind, powered_up, owner));
|
||||
}
|
||||
|
||||
@@ -1174,7 +1174,7 @@ void Game::pause(bool value) {
|
||||
void Game::addScoreToScoreBoard(const std::shared_ptr<Player> &player) {
|
||||
const auto ENTRY = HiScoreEntry(trim(player->getLastEnterName()), player->getScore(), player->get1CC());
|
||||
auto manager = std::make_unique<ManageHiScoreTable>(Options::settings.hi_score_table);
|
||||
Options::settings.last_hi_score_entry.at(player->getId() - 1) = manager->add(ENTRY);
|
||||
Options::settings.glowing_entries.at(static_cast<int>(player->getId()) - 1) = manager->add(ENTRY);
|
||||
manager->saveToFile(Asset::get()->get("score.bin"));
|
||||
hi_score_.name = Options::settings.hi_score_table.front().name;
|
||||
}
|
||||
@@ -1206,7 +1206,7 @@ void Game::checkPlayersStatusPlaying() {
|
||||
}
|
||||
|
||||
// Obtiene un jugador a partir de su "id"
|
||||
auto Game::getPlayer(int id) -> std::shared_ptr<Player> {
|
||||
auto Game::getPlayer(Player::Id id) -> std::shared_ptr<Player> {
|
||||
auto it = std::find_if(players_.begin(), players_.end(), [id](const auto &player) { return player->getId() == id; });
|
||||
|
||||
if (it != players_.end()) {
|
||||
@@ -1216,11 +1216,11 @@ auto Game::getPlayer(int id) -> std::shared_ptr<Player> {
|
||||
}
|
||||
|
||||
// Obtiene un controlador a partir del "id" del jugador
|
||||
auto Game::getController(int player_id) -> int {
|
||||
auto it = std::find_if(Options::controllers.begin(), Options::controllers.end(), [player_id](const auto &controller) { return controller.player_id == player_id; });
|
||||
auto Game::getController(Player::Id player_id) -> int {
|
||||
auto it = std::find_if(Options::gamepads.begin(), Options::gamepads.end(), [player_id](const auto &controller) { return controller->player_id == player_id; });
|
||||
|
||||
if (it != Options::controllers.end()) {
|
||||
return std::distance(Options::controllers.begin(), it);
|
||||
if (it != Options::gamepads.end()) {
|
||||
return std::distance(Options::gamepads.begin(), it);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@@ -1286,7 +1286,7 @@ void Game::demoHandleInput() {
|
||||
|
||||
// Procesa las entradas para un jugador específico durante el modo demo.
|
||||
void Game::demoHandlePlayerInput(const std::shared_ptr<Player> &player, int index) {
|
||||
const auto &demo_data = demo_.data[index][demo_.counter];
|
||||
const auto &demo_data = demo_.data.at(index).at(demo_.counter);
|
||||
|
||||
if (demo_data.left == 1) {
|
||||
player->setInput(Input::Action::LEFT);
|
||||
@@ -1469,7 +1469,7 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player) {
|
||||
}
|
||||
|
||||
// Inicializa las variables para el modo DEMO
|
||||
void Game::initDemo(int player_id) {
|
||||
void Game::initDemo(Player::Id player_id) {
|
||||
if (demo_.enabled) {
|
||||
// Cambia el estado del juego
|
||||
setState(State::PLAYING);
|
||||
@@ -1497,7 +1497,7 @@ void Game::initDemo(int player_id) {
|
||||
|
||||
// Activa o no al otro jugador
|
||||
if (rand() % 3 != 0) {
|
||||
const auto OTHER_PLAYER_ID = player_id == 1 ? 2 : 1;
|
||||
const auto OTHER_PLAYER_ID = player_id == Player::Id::PLAYER1 ? Player::Id::PLAYER2 : Player::Id::PLAYER1;
|
||||
auto other_player = getPlayer(OTHER_PLAYER_ID);
|
||||
other_player->setPlayingState(Player::State::PLAYING);
|
||||
}
|
||||
@@ -1581,30 +1581,54 @@ void Game::initDifficultyVars() {
|
||||
}
|
||||
|
||||
// Inicializa los jugadores
|
||||
void Game::initPlayers(int player_id) {
|
||||
void Game::initPlayers(Player::Id player_id) {
|
||||
const int Y = param.game.play_area.rect.h - Player::HEIGHT + 1; // Se hunde un pixel para esconder el outline de los pies
|
||||
|
||||
// Crea al jugador uno y lo pone en modo espera
|
||||
players_.emplace_back(std::make_unique<Player>(1, param.game.play_area.first_quarter_x - (Player::WIDTH / 2), Y, demo_.enabled, param.game.play_area.rect, player_textures_.at(0), player_animations_));
|
||||
players_.back()->setScoreBoardPanel(Scoreboard::Id::LEFT);
|
||||
players_.back()->setName(Lang::getText("[SCOREBOARD] 1"));
|
||||
//players_.back()->setController(getController(players_.back()->getId()));
|
||||
players_.back()->setGamepad(Options::controllers.front().gamepad);
|
||||
players_.back()->setUsesKeyboard(true);
|
||||
players_.back()->setPlayingState(Player::State::WAITING);
|
||||
Player::Config config_player1;
|
||||
config_player1.id = Player::Id::PLAYER1;
|
||||
config_player1.x = param.game.play_area.first_quarter_x - (Player::WIDTH / 2);
|
||||
config_player1.y = Y;
|
||||
config_player1.demo = demo_.enabled;
|
||||
config_player1.play_area = ¶m.game.play_area.rect;
|
||||
config_player1.texture = player_textures_.at(0);
|
||||
config_player1.animations = player_animations_;
|
||||
config_player1.hi_score_table = &Options::settings.hi_score_table;
|
||||
config_player1.glowing_entry = &Options::settings.glowing_entries.at(static_cast<int>(Player::Id::PLAYER1) - 1);
|
||||
|
||||
auto player1 = std::make_unique<Player>(config_player1);
|
||||
player1->setScoreBoardPanel(Scoreboard::Id::LEFT);
|
||||
player1->setName(Lang::getText("[SCOREBOARD] 1"));
|
||||
player1->setGamepad(Options::gamepads.front()->instance);
|
||||
player1->setUsesKeyboard(Player::Id::PLAYER1 == Options::keyboard.player_id);
|
||||
player1->setPlayingState(Player::State::WAITING);
|
||||
players_.push_back(std::move(player1));
|
||||
|
||||
// Crea al jugador dos y lo pone en modo espera
|
||||
players_.emplace_back(std::make_unique<Player>(2, param.game.play_area.third_quarter_x - (Player::WIDTH / 2), Y, demo_.enabled, param.game.play_area.rect, player_textures_.at(1), player_animations_));
|
||||
players_.back()->setScoreBoardPanel(Scoreboard::Id::RIGHT);
|
||||
players_.back()->setName(Lang::getText("[SCOREBOARD] 2"));
|
||||
//players_.back()->setController(getController(players_.back()->getId()));
|
||||
players_.back()->setPlayingState(Player::State::WAITING);
|
||||
Player::Config config_player2;
|
||||
config_player2.id = Player::Id::PLAYER2;
|
||||
config_player2.x = param.game.play_area.third_quarter_x - (Player::WIDTH / 2);
|
||||
config_player2.y = Y;
|
||||
config_player2.demo = demo_.enabled;
|
||||
config_player2.play_area = ¶m.game.play_area.rect;
|
||||
config_player2.texture = player_textures_.at(1);
|
||||
config_player2.animations = player_animations_;
|
||||
config_player2.hi_score_table = &Options::settings.hi_score_table;
|
||||
config_player2.glowing_entry = &Options::settings.glowing_entries.at(static_cast<int>(Player::Id::PLAYER2) - 1);
|
||||
|
||||
auto player2 = std::make_unique<Player>(config_player2);
|
||||
player2->setScoreBoardPanel(Scoreboard::Id::RIGHT);
|
||||
player2->setName(Lang::getText("[SCOREBOARD] 2"));
|
||||
player2->setGamepad(Options::gamepads.back()->instance);
|
||||
player2->setUsesKeyboard(Player::Id::PLAYER2 == Options::keyboard.player_id);
|
||||
player2->setPlayingState(Player::State::WAITING);
|
||||
players_.push_back(std::move(player2));
|
||||
|
||||
// Activa el jugador que coincide con el "player_id" o ambos si es "0"
|
||||
if (player_id == 0) {
|
||||
if (player_id == Player::Id::BOTH_PLAYERS) {
|
||||
// Activa ambos jugadores
|
||||
getPlayer(1)->setPlayingState(demo_.enabled ? Player::State::PLAYING : Player::State::ENTERING_SCREEN);
|
||||
getPlayer(2)->setPlayingState(demo_.enabled ? Player::State::PLAYING : Player::State::ENTERING_SCREEN);
|
||||
getPlayer(Player::Id::PLAYER1)->setPlayingState(demo_.enabled ? Player::State::PLAYING : Player::State::ENTERING_SCREEN);
|
||||
getPlayer(Player::Id::PLAYER2)->setPlayingState(demo_.enabled ? Player::State::PLAYING : Player::State::ENTERING_SCREEN);
|
||||
} else {
|
||||
// Activa el jugador elegido
|
||||
auto player = getPlayer(player_id);
|
||||
|
||||
@@ -30,18 +30,15 @@ namespace Difficulty {
|
||||
enum class Code;
|
||||
} // namespace Difficulty
|
||||
|
||||
// Modo demo
|
||||
constexpr bool GAME_MODE_DEMO_OFF = false;
|
||||
constexpr bool GAME_MODE_DEMO_ON = true;
|
||||
|
||||
// Cantidad de elementos a escribir en los ficheros de datos
|
||||
constexpr int TOTAL_SCORE_DATA = 3;
|
||||
|
||||
// Clase Game
|
||||
class Game {
|
||||
public:
|
||||
// --- Constantes ---
|
||||
static constexpr bool DEMO_OFF = false;
|
||||
static constexpr bool DEMO_ON = true;
|
||||
|
||||
// --- Constructor y destructor ---
|
||||
Game(int player_id, int current_stage, bool demo);
|
||||
Game(Player::Id player_id, int current_stage, bool demo);
|
||||
~Game();
|
||||
|
||||
// --- Bucle principal ---
|
||||
@@ -174,12 +171,12 @@ class Game {
|
||||
void updateGameStateGameOver(); // Gestiona el estado de fin de partida
|
||||
|
||||
// --- Gestión de jugadores ---
|
||||
void initPlayers(int player_id); // Inicializa los datos de los jugadores
|
||||
void updatePlayers(); // Actualiza las variables y estados de los jugadores
|
||||
void renderPlayers(); // Renderiza todos los jugadores en pantalla
|
||||
void sortPlayersByZOrder(); // Reorganiza el orden de dibujado de jugadores
|
||||
auto getPlayer(int id) -> std::shared_ptr<Player>; // Obtiene un jugador por su identificador
|
||||
static auto getController(int player_id) -> int; // Obtiene el controlador asignado a un jugador
|
||||
void initPlayers(Player::Id player_id); // Inicializa los datos de los jugadores
|
||||
void updatePlayers(); // Actualiza las variables y estados de los jugadores
|
||||
void renderPlayers(); // Renderiza todos los jugadores en pantalla
|
||||
void sortPlayersByZOrder(); // Reorganiza el orden de dibujado de jugadores
|
||||
auto getPlayer(Player::Id id) -> std::shared_ptr<Player>; // Obtiene un jugador por su identificador
|
||||
static auto getController(Player::Id player_id) -> int; // Obtiene el controlador asignado a un jugador
|
||||
|
||||
// --- Estado de jugadores ---
|
||||
void checkAndUpdatePlayerStatus(int active_player_index, int inactive_player_index); // Actualiza estado entre jugadores
|
||||
@@ -214,7 +211,7 @@ class Game {
|
||||
// --- Sistema de balas y proyectiles ---
|
||||
void updateBullets(); // Actualiza posición y estado de todas las balas
|
||||
void renderBullets(); // Renderiza todas las balas activas
|
||||
void createBullet(int x, int y, BulletType kind, bool powered_up, int owner); // Crea una nueva bala
|
||||
void createBullet(int x, int y, BulletType kind, bool powered_up, Player::Id owner); // Crea una nueva bala
|
||||
void checkBulletCollision(); // Verifica colisiones de todas las balas
|
||||
void freeBullets(); // Libera memoria del vector de balas
|
||||
|
||||
@@ -276,7 +273,7 @@ class Game {
|
||||
void initScoreboard(); // Inicializa el sistema de puntuación
|
||||
|
||||
// --- Modo demostración ---
|
||||
void initDemo(int player_id); // Inicializa variables para el modo demostración
|
||||
void initDemo(Player::Id player_id); // Inicializa variables para el modo demostración
|
||||
void updateDemo(); // Actualiza lógica específica del modo demo
|
||||
|
||||
// --- Recursos y renderizado ---
|
||||
|
||||
@@ -348,7 +348,7 @@ void HiScoreTable::iniEntryColors() {
|
||||
// Hace brillar los nombres de la tabla de records
|
||||
void HiScoreTable::glowEntryNames() {
|
||||
const Color ENTRY_COLOR = getEntryColor(counter_ / 5);
|
||||
for (const auto &entry_index : Options::settings.last_hi_score_entry) {
|
||||
for (const auto &entry_index : Options::settings.glowing_entries) {
|
||||
if (entry_index != -1) {
|
||||
entry_names_.at(entry_index)->getTexture()->setColor(ENTRY_COLOR);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ Title::Title()
|
||||
game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)),
|
||||
mini_logo_sprite_(std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"))),
|
||||
define_buttons_(std::make_unique<DefineButtons>()),
|
||||
num_controllers_(Input::get()->getNumControllers()),
|
||||
num_controllers_(Input::get()->getNumGamepads()),
|
||||
state_(TitleState::LOGO_ANIMATING) {
|
||||
// Configura objetos
|
||||
tiled_bg_->setColor(param.title.bg_color);
|
||||
@@ -213,12 +213,12 @@ void Title::printColorValue(const Color& color) {
|
||||
void Title::handleControlKeys(SDL_Keycode key) {
|
||||
switch (key) {
|
||||
case SDLK_1:
|
||||
define_buttons_->enable(0);
|
||||
define_buttons_->enable(Options::gamepads.at(0));
|
||||
resetCounter();
|
||||
break;
|
||||
|
||||
case SDLK_2:
|
||||
define_buttons_->enable(1);
|
||||
define_buttons_->enable(Options::gamepads.at(1));
|
||||
resetCounter();
|
||||
break;
|
||||
|
||||
@@ -262,29 +262,29 @@ auto Title::shouldSkipInputCheck() const -> bool {
|
||||
}
|
||||
|
||||
void Title::processControllerInputs() {
|
||||
for (const auto& controller : Options::controllers) {
|
||||
for (const auto& controller : Options::gamepads) {
|
||||
if (isStartButtonPressed(controller)) {
|
||||
handleStartButtonPress(controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto Title::isStartButtonPressed(const Options::GamepadOptions& controller) -> bool {
|
||||
auto Title::isStartButtonPressed(std::shared_ptr<Options::Gamepad> controller) -> bool {
|
||||
return Input::get()->checkAction(
|
||||
Input::Action::START,
|
||||
Input::DO_NOT_ALLOW_REPEAT,
|
||||
Input::CHECK_KEYBOARD,
|
||||
controller.gamepad);
|
||||
controller->instance);
|
||||
}
|
||||
|
||||
void Title::handleStartButtonPress(const Options::GamepadOptions& controller) {
|
||||
void Title::handleStartButtonPress(std::shared_ptr<Options::Gamepad> controller) {
|
||||
if (!canProcessStartButton()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (controller.player_id == 1) {
|
||||
if (controller->player_id == Player::Id::PLAYER1) {
|
||||
processPlayer1Start();
|
||||
} else if (controller.player_id == 2) {
|
||||
} else if (controller->player_id == Player::Id::PLAYER2) {
|
||||
processPlayer2Start();
|
||||
}
|
||||
}
|
||||
@@ -296,18 +296,18 @@ auto Title::canProcessStartButton() const -> bool {
|
||||
void Title::processPlayer1Start() {
|
||||
if (!player1_start_pressed_) {
|
||||
player1_start_pressed_ = true;
|
||||
activatePlayerAndSetState(1);
|
||||
activatePlayerAndSetState(Player::Id::PLAYER1);
|
||||
}
|
||||
}
|
||||
|
||||
void Title::processPlayer2Start() {
|
||||
if (!player2_start_pressed_) {
|
||||
player2_start_pressed_ = true;
|
||||
activatePlayerAndSetState(2);
|
||||
activatePlayerAndSetState(Player::Id::PLAYER2);
|
||||
}
|
||||
}
|
||||
|
||||
void Title::activatePlayerAndSetState(int player_id) {
|
||||
void Title::activatePlayerAndSetState(Player::Id player_id) {
|
||||
getPlayer(player_id)->setPlayingState(Player::State::TITLE_ANIMATION);
|
||||
setState(TitleState::START_HAS_BEEN_PRESSED);
|
||||
counter_ = 0;
|
||||
@@ -328,7 +328,7 @@ void Title::resetCounter() { counter_ = 0; }
|
||||
|
||||
// Intercambia la asignación de mandos a los jugadores
|
||||
void Title::swapControllers() {
|
||||
if (Input::get()->getNumControllers() == 0) {
|
||||
if (Input::get()->getNumGamepads() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -339,33 +339,34 @@ void Title::swapControllers() {
|
||||
// Intercambia el teclado de jugador
|
||||
void Title::swapKeyboard() {
|
||||
Options::swapKeyboard();
|
||||
std::string text = Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(Options::getPlayerWhoUsesKeyboard()) + ": " + Lang::getText("[DEFINE_BUTTONS] KEYBOARD");
|
||||
std::string text = Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(static_cast<int>(Options::getPlayerWhoUsesKeyboard())) + ": " + Lang::getText("[DEFINE_BUTTONS] KEYBOARD");
|
||||
Notifier::get()->show({text});
|
||||
}
|
||||
|
||||
// Muestra información sobre los controles y los jugadores
|
||||
void Title::showControllers() {
|
||||
// Crea vectores de texto vacíos para un número máximo de mandos
|
||||
constexpr size_t NUM_CONTROLLERS = 2;
|
||||
std::vector<std::string> text(NUM_CONTROLLERS);
|
||||
std::vector<int> player_controller_index(NUM_CONTROLLERS, -1);
|
||||
/* // Crea vectores de texto vacíos para un número máximo de mandos
|
||||
constexpr size_t NUM_CONTROLLERS = 2;
|
||||
std::vector<std::string> text(NUM_CONTROLLERS);
|
||||
std::vector<int> player_controller_index(NUM_CONTROLLERS, -1);
|
||||
|
||||
// Obtiene de cada jugador el índice del mando que tiene asignado
|
||||
for (size_t i = 0; i < NUM_CONTROLLERS; ++i) {
|
||||
// Ejemplo: el jugador 1 tiene el mando 2
|
||||
player_controller_index.at(Options::controllers.at(i).player_id - 1) = i;
|
||||
}
|
||||
// Obtiene de cada jugador el índice del mando que tiene asignado
|
||||
for (size_t i = 0; i < NUM_CONTROLLERS; ++i) {
|
||||
// Ejemplo: el jugador 1 tiene el mando 2
|
||||
player_controller_index.at(Options::controllers.at(i)->player_id - 1) = i;
|
||||
}
|
||||
|
||||
// Genera el texto correspondiente
|
||||
//for (size_t i = 0; i < NUM_CONTROLLERS; ++i) {
|
||||
// const size_t INDEX = player_controller_index.at(i);
|
||||
// if (Options::controllers.at(INDEX).plugged) {
|
||||
// text.at(i) = Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(i + 1) + ": " + Options::controllers.at(INDEX).name;
|
||||
// }
|
||||
//}
|
||||
// Genera el texto correspondiente
|
||||
for (size_t i = 0; i < NUM_CONTROLLERS; ++i) {
|
||||
const size_t INDEX = player_controller_index.at(i);
|
||||
if (Options::controllers.at(INDEX).plugged) {
|
||||
text.at(i) = Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(i + 1) + ": " + Options::controllers.at(INDEX).name;
|
||||
}
|
||||
}
|
||||
|
||||
// Muestra la notificación
|
||||
Notifier::get()->show({text.at(0), text.at(1)});
|
||||
// Muestra la notificación
|
||||
Notifier::get()->show({text.at(0), text.at(1)});
|
||||
*/
|
||||
}
|
||||
|
||||
// Actualiza el fade
|
||||
@@ -558,10 +559,31 @@ void Title::initPlayers() {
|
||||
constexpr int PLAYER_HEIGHT = 32;
|
||||
const int Y = param.title.press_start_position - (PLAYER_HEIGHT / 2);
|
||||
constexpr bool DEMO = false;
|
||||
players_.emplace_back(std::make_unique<Player>(1, param.game.game_area.center_x - (PLAYER_WIDTH / 2), Y, DEMO, param.game.play_area.rect, player_textures.at(0), player_animations));
|
||||
|
||||
Player::Config config_player1;
|
||||
config_player1.id = Player::Id::PLAYER1;
|
||||
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;
|
||||
config_player1.texture = player_textures.at(0);
|
||||
config_player1.animations = player_animations;
|
||||
config_player1.hi_score_table = &Options::settings.hi_score_table;
|
||||
config_player1.glowing_entry = &Options::settings.glowing_entries.at(static_cast<int>(Player::Id::PLAYER1) - 1);
|
||||
players_.emplace_back(std::make_unique<Player>(config_player1));
|
||||
players_.back()->setPlayingState(Player::State::TITLE_HIDDEN);
|
||||
|
||||
players_.emplace_back(std::make_unique<Player>(2, param.game.game_area.center_x - (PLAYER_WIDTH / 2), Y, DEMO, param.game.play_area.rect, player_textures.at(1), player_animations));
|
||||
Player::Config config_player2;
|
||||
config_player2.id = Player::Id::PLAYER2;
|
||||
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;
|
||||
config_player2.texture = player_textures.at(1);
|
||||
config_player2.animations = player_animations;
|
||||
config_player2.hi_score_table = &Options::settings.hi_score_table;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -580,7 +602,7 @@ void Title::renderPlayers() {
|
||||
}
|
||||
|
||||
// Obtiene un jugador a partir de su "id"
|
||||
auto Title::getPlayer(int id) -> std::shared_ptr<Player> {
|
||||
auto Title::getPlayer(Player::Id id) -> std::shared_ptr<Player> {
|
||||
auto it = std::find_if(players_.begin(), players_.end(), [id](const auto& player) { return player->getId() == id; });
|
||||
|
||||
if (it != players_.end()) {
|
||||
|
||||
@@ -7,17 +7,17 @@
|
||||
#include <string_view> // Para string_view
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "player.h" // Para Player
|
||||
#include "section.hpp" // Para Options, Name (ptr only)
|
||||
|
||||
class DefineButtons;
|
||||
class Fade;
|
||||
class GameLogo;
|
||||
class Player;
|
||||
class Sprite;
|
||||
class Text;
|
||||
class TiledBG;
|
||||
namespace Options {
|
||||
struct GamepadOptions;
|
||||
struct Gamepad;
|
||||
} // namespace Options
|
||||
struct Color;
|
||||
|
||||
@@ -87,24 +87,24 @@ class Title {
|
||||
void resetCounter(); // Reinicia el contador interno
|
||||
|
||||
// --- Entrada de usuario ---
|
||||
void checkEvents(); // Comprueba los eventos
|
||||
void checkInput(); // Comprueba las entradas
|
||||
void handleKeyDownEvent(const SDL_Event& event); // Maneja el evento de tecla presionada
|
||||
void handleControlKeys(SDL_Keycode key); // Maneja las teclas de control específicas
|
||||
[[nodiscard]] auto shouldSkipInputCheck() const -> bool; // Determina si se debe omitir la comprobación de entrada
|
||||
void processControllerInputs(); // Procesa las entradas de los mandos
|
||||
[[nodiscard]] static auto isStartButtonPressed(const Options::GamepadOptions& controller) -> bool; // Comprueba si se ha pulsado el botón Start
|
||||
void handleStartButtonPress(const Options::GamepadOptions& controller); // Maneja la pulsación del botón Start
|
||||
[[nodiscard]] auto canProcessStartButton() const -> bool; // Verifica si se puede procesar la pulsación del botón Start
|
||||
void processPlayer1Start(); // Procesa el inicio del jugador 1
|
||||
void processPlayer2Start(); // Procesa el inicio del jugador 2
|
||||
void activatePlayerAndSetState(int player_id); // Activa al jugador y cambia el estado del título
|
||||
void checkEvents(); // Comprueba los eventos
|
||||
void checkInput(); // Comprueba las entradas
|
||||
void handleKeyDownEvent(const SDL_Event& event); // Maneja el evento de tecla presionada
|
||||
void handleControlKeys(SDL_Keycode key); // Maneja las teclas de control específicas
|
||||
[[nodiscard]] auto shouldSkipInputCheck() const -> bool; // Determina si se debe omitir la comprobación de entrada
|
||||
void processControllerInputs(); // Procesa las entradas de los mandos
|
||||
[[nodiscard]] static auto isStartButtonPressed(std::shared_ptr<Options::Gamepad> controller) -> bool; // Comprueba si se ha pulsado el botón Start
|
||||
void handleStartButtonPress(std::shared_ptr<Options::Gamepad> controller); // Maneja la pulsación del botón Start
|
||||
[[nodiscard]] auto canProcessStartButton() const -> bool; // Verifica si se puede procesar la pulsación del botón Start
|
||||
void processPlayer1Start(); // Procesa el inicio del jugador 1
|
||||
void processPlayer2Start(); // Procesa el inicio del jugador 2
|
||||
void activatePlayerAndSetState(Player::Id player_id); // Activa al jugador y cambia el estado del título
|
||||
|
||||
// --- Gestión de jugadores ---
|
||||
void initPlayers(); // Inicializa los jugadores
|
||||
void updatePlayers(); // Actualiza los jugadores
|
||||
void renderPlayers(); // Renderiza los jugadores
|
||||
auto getPlayer(int id) -> std::shared_ptr<Player>; // Obtiene un jugador a partir de su "id"
|
||||
void initPlayers(); // Inicializa los jugadores
|
||||
void updatePlayers(); // Actualiza los jugadores
|
||||
void renderPlayers(); // Renderiza los jugadores
|
||||
auto getPlayer(Player::Id id) -> std::shared_ptr<Player>; // Obtiene un jugador a partir de su "id"
|
||||
|
||||
// --- Visualización / Renderizado ---
|
||||
void render(); // Dibuja el objeto en pantalla
|
||||
|
||||
Reference in New Issue
Block a user