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