El juego ya empieza con el jugador que ha pulsado el botón
This commit is contained in:
@@ -16,7 +16,7 @@ Director::Director(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
section = new section_t();
|
section = new section_t();
|
||||||
section->name = SECTION_PROG_LOGO;
|
section->name = SECTION_PROG_TITLE;
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
checkProgramArguments(argc, argv);
|
checkProgramArguments(argc, argv);
|
||||||
@@ -758,8 +758,8 @@ void Director::runTitle()
|
|||||||
// Ejecuta la seccion de juego donde se juega
|
// Ejecuta la seccion de juego donde se juega
|
||||||
void Director::runGame()
|
void Director::runGame()
|
||||||
{
|
{
|
||||||
const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2;
|
const int playerID = section->subsection == SUBSECTION_GAME_PLAY_1P ? 0 : 1;
|
||||||
game = new Game(numPlayers, 0, renderer, screen, asset, lang, input, false, param, options, section, getMusic(musics, "playing.ogg"));
|
game = new Game(playerID, 0, renderer, screen, asset, lang, input, false, param, options, section, getMusic(musics, "playing.ogg"));
|
||||||
game->run();
|
game->run();
|
||||||
delete game;
|
delete game;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,7 +162,10 @@ void Game::init(int playerID)
|
|||||||
// Elimina qualquier jugador que hubiese antes de crear los nuevos
|
// Elimina qualquier jugador que hubiese antes de crear los nuevos
|
||||||
for (auto player : players)
|
for (auto player : players)
|
||||||
{
|
{
|
||||||
delete player;
|
if (player)
|
||||||
|
{
|
||||||
|
delete player;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
players.clear();
|
players.clear();
|
||||||
|
|
||||||
@@ -173,7 +176,7 @@ void Game::init(int playerID)
|
|||||||
Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, renderer, playerTextures[1], playerAnimations);
|
Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, renderer, playerTextures[1], playerAnimations);
|
||||||
players.push_back(player2);
|
players.push_back(player2);
|
||||||
|
|
||||||
numPlayers = 2;
|
players[playerID]->enable(true);
|
||||||
|
|
||||||
// Variables relacionadas con la dificultad
|
// Variables relacionadas con la dificultad
|
||||||
switch (difficulty)
|
switch (difficulty)
|
||||||
@@ -1606,7 +1609,7 @@ void Game::updateDeath()
|
|||||||
bool allPlayersAreDead = true;
|
bool allPlayersAreDead = true;
|
||||||
for (auto player : players)
|
for (auto player : players)
|
||||||
{
|
{
|
||||||
allPlayersAreDead &= (!player->isAlive());
|
allPlayersAreDead &= (!player->isAlive() || !player->isEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allPlayersAreDead)
|
if (allPlayersAreDead)
|
||||||
|
|||||||
@@ -174,7 +174,6 @@ private:
|
|||||||
JA_Music_t *music; // Musica de fondo
|
JA_Music_t *music; // Musica de fondo
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int numPlayers; // Numero de jugadores
|
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
Uint32 hiScore; // Puntuación máxima
|
Uint32 hiScore; // Puntuación máxima
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ Player::Player(float x, int y, SDL_Renderer *renderer, std::vector<Texture *> te
|
|||||||
defaultPosX = posX = x;
|
defaultPosX = posX = x;
|
||||||
defaultPosY = posY = y;
|
defaultPosY = posY = y;
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
enabled = false;
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,6 +175,11 @@ void Player::move()
|
|||||||
// Pinta el jugador en pantalla
|
// Pinta el jugador en pantalla
|
||||||
void Player::render()
|
void Player::render()
|
||||||
{
|
{
|
||||||
|
if (!enabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isAlive())
|
if (isAlive())
|
||||||
{
|
{
|
||||||
if (invulnerable)
|
if (invulnerable)
|
||||||
@@ -330,6 +337,11 @@ void Player::updateCooldown()
|
|||||||
// Actualiza al jugador a su posicion, animación y controla los contadores
|
// Actualiza al jugador a su posicion, animación y controla los contadores
|
||||||
void Player::update()
|
void Player::update()
|
||||||
{
|
{
|
||||||
|
if (!enabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
move();
|
move();
|
||||||
setAnimation();
|
setAnimation();
|
||||||
shiftColliders();
|
shiftColliders();
|
||||||
@@ -603,3 +615,15 @@ void Player::setPlayerTextures(std::vector<Texture *> texture)
|
|||||||
deathSprite->setTexture(texture[3]);
|
deathSprite->setTexture(texture[3]);
|
||||||
fireSprite->setTexture(texture[4]);
|
fireSprite->setTexture(texture[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Activa o descativa el jugador
|
||||||
|
void Player::enable(bool value)
|
||||||
|
{
|
||||||
|
enabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool Player::isEnabled()
|
||||||
|
{
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
@@ -67,6 +67,7 @@ private:
|
|||||||
bool input; // Indica si puede recibir ordenes de entrada
|
bool input; // Indica si puede recibir ordenes de entrada
|
||||||
circle_t collider; // Circulo de colisión del jugador
|
circle_t collider; // Circulo de colisión del jugador
|
||||||
bool alive; // Indica si el jugador está vivo
|
bool alive; // Indica si el jugador está vivo
|
||||||
|
bool enabled; // Indica si el jugador está activo
|
||||||
|
|
||||||
// Actualiza el circulo de colisión a la posición del jugador
|
// Actualiza el circulo de colisión a la posición del jugador
|
||||||
void shiftColliders();
|
void shiftColliders();
|
||||||
@@ -209,6 +210,12 @@ public:
|
|||||||
|
|
||||||
// Obtiene el puntero a la textura con los gráficos de la animación de morir
|
// Obtiene el puntero a la textura con los gráficos de la animación de morir
|
||||||
Texture *getDeadTexture();
|
Texture *getDeadTexture();
|
||||||
|
|
||||||
|
// Activa o descativa el jugador
|
||||||
|
void enable(bool value);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool isEnabled();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -94,13 +94,13 @@ void Title::update()
|
|||||||
{
|
{
|
||||||
switch (postFade)
|
switch (postFade)
|
||||||
{
|
{
|
||||||
case 0: // 1 PLAYER
|
case 1: // 1 PLAYER
|
||||||
section->name = SECTION_PROG_GAME;
|
section->name = SECTION_PROG_GAME;
|
||||||
section->subsection = SUBSECTION_GAME_PLAY_1P;
|
section->subsection = SUBSECTION_GAME_PLAY_1P;
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: // 2 PLAYER
|
case 2: // 2 PLAYER
|
||||||
section->name = SECTION_PROG_GAME;
|
section->name = SECTION_PROG_GAME;
|
||||||
section->subsection = SUBSECTION_GAME_PLAY_2P;
|
section->subsection = SUBSECTION_GAME_PLAY_2P;
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
@@ -216,33 +216,35 @@ void Title::checkEvents()
|
|||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void Title::checkInput()
|
void Title::checkInput()
|
||||||
{
|
{
|
||||||
// Comprueba todos los controladores
|
// Comprueba todos los controladores para salir
|
||||||
for (int i = 0; i < numControllers; ++i)
|
for (int i = 0; i < numControllers; ++i)
|
||||||
{
|
{
|
||||||
if (input->checkInput(input_exit, REPEAT_FALSE, options->game.input[i].deviceType, options->game.input[i].id))
|
if (input->checkInput(input_exit, REPEAT_FALSE, options->game.input[i].deviceType, options->game.input[i].id))
|
||||||
{
|
{
|
||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkInput(input_accept, REPEAT_FALSE, options->game.input[i].deviceType, options->game.input[i].id))
|
|
||||||
{
|
|
||||||
fade->activate();
|
|
||||||
postFade = i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el teclado
|
// Comprueba el teclado para salir
|
||||||
if (input->checkInput(input_exit, REPEAT_FALSE))
|
if (input->checkInput(input_exit, REPEAT_FALSE))
|
||||||
{
|
{
|
||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkInput(input_accept, REPEAT_FALSE))
|
// Comprueba si se ha pulsado algún botón para empezar a jugar
|
||||||
|
const int index = input->checkAnyButtonPressed();
|
||||||
|
if (index)
|
||||||
{
|
{
|
||||||
fade->activate();
|
fade->activate();
|
||||||
postFade = 0;
|
postFade = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//else if (input->checkInput(input_start, REPEAT_FALSE))
|
||||||
|
//{
|
||||||
|
// fade->activate();
|
||||||
|
// postFade = 0;
|
||||||
|
//}
|
||||||
|
|
||||||
// Comprueba el input para el resto de objetos
|
// Comprueba el input para el resto de objetos
|
||||||
screen->checkInput();
|
screen->checkInput();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user