|
|
|
|
@@ -108,14 +108,18 @@ void Game::init(int playerID)
|
|
|
|
|
players.clear();
|
|
|
|
|
|
|
|
|
|
// Crea los dos jugadores
|
|
|
|
|
Player *player1 = new Player((param->game.playArea.firstQuarterX * ((0 * 2) + 1)) - 11, param->game.playArea.rect.h - 30, ¶m->game.playArea.rect ,playerTextures[0], playerAnimations);
|
|
|
|
|
Player *player1 = new Player(1, (param->game.playArea.firstQuarterX * ((0 * 2) + 1)) - 11, param->game.playArea.rect.h - 30, ¶m->game.playArea.rect, playerTextures[0], playerAnimations);
|
|
|
|
|
player1->setScoreBoardPanel(SCOREBOARD_LEFT_PANEL);
|
|
|
|
|
player1->setName(lang->getText(53));
|
|
|
|
|
const int controller1 = getController(player1->getId());
|
|
|
|
|
player1->setController(controller1);
|
|
|
|
|
players.push_back(player1);
|
|
|
|
|
|
|
|
|
|
Player *player2 = new Player((param->game.playArea.firstQuarterX * ((1 * 2) + 1)) - 11, param->game.playArea.rect.h - 30, ¶m->game.playArea.rect, playerTextures[1], playerAnimations);
|
|
|
|
|
Player *player2 = new Player(2, (param->game.playArea.firstQuarterX * ((1 * 2) + 1)) - 11, param->game.playArea.rect.h - 30, ¶m->game.playArea.rect, playerTextures[1], playerAnimations);
|
|
|
|
|
player2->setScoreBoardPanel(SCOREBOARD_RIGHT_PANEL);
|
|
|
|
|
player2->setName(lang->getText(54));
|
|
|
|
|
const int controller2 = getController(player2->getId());
|
|
|
|
|
player2->setController(controller2);
|
|
|
|
|
players.push_back(player2);
|
|
|
|
|
|
|
|
|
|
// Cambia el estado del jugador seleccionado
|
|
|
|
|
@@ -1401,9 +1405,13 @@ void Game::checkBulletBalloonCollision()
|
|
|
|
|
if (checkCollision(balloon->getCollider(), bullet->getCollider()))
|
|
|
|
|
{
|
|
|
|
|
// Otorga los puntos correspondientes al globo al jugador que disparó la bala
|
|
|
|
|
int index = bullet->getOwner();
|
|
|
|
|
players[index]->incScoreMultiplier();
|
|
|
|
|
players[index]->addScore(Uint32(balloon->getScore() * players[index]->getScoreMultiplier() * difficultyScoreMultiplier));
|
|
|
|
|
Player *player = getPlayer(bullet->getOwner());
|
|
|
|
|
if (!player)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
player->incScoreMultiplier();
|
|
|
|
|
player->addScore(Uint32(balloon->getScore() * player->getScoreMultiplier() * difficultyScoreMultiplier));
|
|
|
|
|
updateHiScore();
|
|
|
|
|
|
|
|
|
|
// Suelta el item si se da el caso
|
|
|
|
|
@@ -1417,7 +1425,7 @@ void Game::checkBulletBalloonCollision()
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
createItem(droppeditem, players[index]->getPosX(), 0);
|
|
|
|
|
createItem(droppeditem, player->getPosX(), 0);
|
|
|
|
|
coffeeMachineEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -2133,14 +2141,14 @@ void Game::checkInput()
|
|
|
|
|
demo.keys.fireLeft = 0;
|
|
|
|
|
demo.keys.fireRight = 0;
|
|
|
|
|
#endif
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (auto player : players)
|
|
|
|
|
{
|
|
|
|
|
const int controllerIndex = player->getController();
|
|
|
|
|
const bool autofire = player->isPowerUp() || options->game.autofire;
|
|
|
|
|
if (player->isPlaying())
|
|
|
|
|
{
|
|
|
|
|
// Input a la izquierda
|
|
|
|
|
if (input->checkInput(input_left, ALLOW_REPEAT, options->controller[i].deviceType, options->controller[i].index))
|
|
|
|
|
if (input->checkInput(input_left, ALLOW_REPEAT, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
|
|
|
|
{
|
|
|
|
|
player->setInput(input_left);
|
|
|
|
|
#ifdef RECORDING
|
|
|
|
|
@@ -2150,7 +2158,7 @@ void Game::checkInput()
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Input a la derecha
|
|
|
|
|
if (input->checkInput(input_right, ALLOW_REPEAT, options->controller[i].deviceType, options->controller[i].index))
|
|
|
|
|
if (input->checkInput(input_right, ALLOW_REPEAT, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
|
|
|
|
{
|
|
|
|
|
player->setInput(input_right);
|
|
|
|
|
#ifdef RECORDING
|
|
|
|
|
@@ -2167,12 +2175,12 @@ void Game::checkInput()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Comprueba el input de disparar al centro
|
|
|
|
|
if (input->checkInput(input_fire_center, autofire, options->controller[i].deviceType, options->controller[i].index))
|
|
|
|
|
if (input->checkInput(input_fire_center, autofire, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
|
|
|
|
{
|
|
|
|
|
if (player->canFire())
|
|
|
|
|
{
|
|
|
|
|
player->setInput(input_fire_center);
|
|
|
|
|
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_UP, player->isPowerUp(), i);
|
|
|
|
|
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_UP, player->isPowerUp(), player->getId());
|
|
|
|
|
player->setFireCooldown(10);
|
|
|
|
|
|
|
|
|
|
// Reproduce el sonido de disparo
|
|
|
|
|
@@ -2184,12 +2192,12 @@ void Game::checkInput()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Comprueba el input de disparar a la izquierda
|
|
|
|
|
else if (input->checkInput(input_fire_left, autofire, options->controller[i].deviceType, options->controller[i].index))
|
|
|
|
|
else if (input->checkInput(input_fire_left, autofire, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
|
|
|
|
{
|
|
|
|
|
if (player->canFire())
|
|
|
|
|
{
|
|
|
|
|
player->setInput(input_fire_left);
|
|
|
|
|
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_LEFT, player->isPowerUp(), i);
|
|
|
|
|
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_LEFT, player->isPowerUp(), player->getId());
|
|
|
|
|
player->setFireCooldown(10);
|
|
|
|
|
|
|
|
|
|
// Reproduce el sonido de disparo
|
|
|
|
|
@@ -2201,12 +2209,12 @@ void Game::checkInput()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Comprueba el input de disparar a la derecha
|
|
|
|
|
else if (input->checkInput(input_fire_right, autofire, options->controller[i].deviceType, options->controller[i].index))
|
|
|
|
|
else if (input->checkInput(input_fire_right, autofire, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
|
|
|
|
{
|
|
|
|
|
if (player->canFire())
|
|
|
|
|
{
|
|
|
|
|
player->setInput(input_fire_right);
|
|
|
|
|
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_RIGHT, player->isPowerUp(), i);
|
|
|
|
|
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_RIGHT, player->isPowerUp(), player->getId());
|
|
|
|
|
player->setFireCooldown(10);
|
|
|
|
|
|
|
|
|
|
// Reproduce el sonido de disparo
|
|
|
|
|
@@ -2225,12 +2233,11 @@ void Game::checkInput()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Si no está jugando, el botón de start le permite continuar jugando
|
|
|
|
|
if (input->checkInput(input_start, ALLOW_REPEAT, options->controller[i].deviceType, options->controller[i].index))
|
|
|
|
|
if (input->checkInput(input_start, ALLOW_REPEAT, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
|
|
|
|
{
|
|
|
|
|
// Si no ha entrado ya en el estado de game over, entonces se puede continuar
|
|
|
|
|
if (gameOverCounter == GAME_OVER_COUNTER)
|
|
|
|
|
@@ -2240,14 +2247,13 @@ void Game::checkInput()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Si está continuando, los botones de fuego hacen decrementar el contador
|
|
|
|
|
const bool fire1 = input->checkInput(input_fire_left, false, options->controller[i].deviceType, options->controller[i].index);
|
|
|
|
|
const bool fire2 = input->checkInput(input_fire_center, false, options->controller[i].deviceType, options->controller[i].index);
|
|
|
|
|
const bool fire3 = input->checkInput(input_fire_right, false, options->controller[i].deviceType, options->controller[i].index);
|
|
|
|
|
const bool fire1 = input->checkInput(input_fire_left, false, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index);
|
|
|
|
|
const bool fire2 = input->checkInput(input_fire_center, false, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index);
|
|
|
|
|
const bool fire3 = input->checkInput(input_fire_right, false, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index);
|
|
|
|
|
if (fire1 || fire2 || fire3)
|
|
|
|
|
{
|
|
|
|
|
player->decContinueCounter();
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -2766,3 +2772,31 @@ void Game::checkPlayersStatusPlaying()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Obtiene un jugador a partir de su "id"
|
|
|
|
|
Player *Game::getPlayer(int id)
|
|
|
|
|
{
|
|
|
|
|
for (auto player : players)
|
|
|
|
|
{
|
|
|
|
|
if (player->getId() == id)
|
|
|
|
|
{
|
|
|
|
|
return player;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Obtiene un controlador a partir del "id" del jugador
|
|
|
|
|
int Game::getController(int playerId)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < (int)options->controller.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if (options->controller[i].playerId == playerId)
|
|
|
|
|
{
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|