Cambiados los accesos a vector de .at a []

This commit is contained in:
2022-12-07 09:29:06 +01:00
parent 7adb049b37
commit c87e1e68a9
8 changed files with 208 additions and 208 deletions

View File

@@ -201,14 +201,14 @@ void Game::init()
// Crea los jugadores
if (numPlayers == 1)
{
Player *player = new Player(PLAY_AREA_CENTER_X - 11, PLAY_AREA_BOTTOM - 24, renderer, playerTextures.at(options->playerSelected), playerAnimations);
Player *player = new Player(PLAY_AREA_CENTER_X - 11, PLAY_AREA_BOTTOM - 24, renderer, playerTextures[options->playerSelected], playerAnimations);
players.push_back(player);
}
else if (numPlayers == 2)
{
Player *player1 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, renderer, playerTextures.at(0), playerAnimations);
Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, renderer, playerTextures.at(1), playerAnimations);
Player *player1 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, renderer, playerTextures[0], 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(player1);
players.push_back(player2);
}
@@ -735,7 +735,7 @@ bool Game::sendOnlineScore()
return true;
}
const int score = players.at(0)->getScore();
const int score = players[0]->getScore();
if (score <= options->online.score)
{
return true;
@@ -1648,21 +1648,21 @@ void Game::renderScoreBoard()
// PLAYER1 - SCORE
textScoreBoard->writeCentered(offsetLeft, offset1, lang->getText(53));
textScoreBoard->writeCentered(offsetLeft, offset2, updateScoreText(players.at(0)->getScore()));
textScoreBoard->writeCentered(offsetLeft, offset2, updateScoreText(players[0]->getScore()));
// PLAYER1 - MULT
textScoreBoard->writeCentered(offsetLeft, offset3, lang->getText(55));
textScoreBoard->writeCentered(offsetLeft, offset4, std::to_string(players.at(0)->getScoreMultiplier()).substr(0, 3));
textScoreBoard->writeCentered(offsetLeft, offset4, std::to_string(players[0]->getScoreMultiplier()).substr(0, 3));
if (numPlayers == 2)
{
// PLAYER2 - SCORE
textScoreBoard->writeCentered(offsetRight, offset1, lang->getText(54));
textScoreBoard->writeCentered(offsetRight, offset2, updateScoreText(players.at(1)->getScore()));
textScoreBoard->writeCentered(offsetRight, offset2, updateScoreText(players[1]->getScore()));
// PLAYER2 - MULT
textScoreBoard->writeCentered(offsetRight, offset3, lang->getText(55));
textScoreBoard->writeCentered(offsetRight, offset4, std::to_string(players.at(1)->getScoreMultiplier()).substr(0, 3));
textScoreBoard->writeCentered(offsetRight, offset4, std::to_string(players[1]->getScoreMultiplier()).substr(0, 3));
}
else
{
@@ -1872,7 +1872,7 @@ void Game::renderBalloons()
Uint8 Game::createBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 creationtimer)
{
const int index = (kind - 1) % 4;
Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, balloonTextures.at(index), balloonAnimations.at(index), renderer);
Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, balloonTextures[index], balloonAnimations[index], renderer);
balloons.push_back(b);
return (Uint8)(balloons.size() - 1);
}
@@ -1890,7 +1890,7 @@ void Game::createPowerBall()
const int x[3] = {left, center, right};
const float vx[3] = {BALLOON_VELX_POSITIVE, BALLOON_VELX_POSITIVE, BALLOON_VELX_NEGATIVE};
Balloon *b = new Balloon(x[luck], posY, POWER_BALL, vx[luck], enemySpeed, 100, balloonTextures.at(3), balloonAnimations.at(3), renderer);
Balloon *b = new Balloon(x[luck], posY, POWER_BALL, vx[luck], enemySpeed, 100, balloonTextures[3], balloonAnimations[3], renderer);
balloons.push_back(b);
powerBallEnabled = true;
@@ -2035,25 +2035,25 @@ void Game::popBalloon(Balloon *balloon)
// En cualquier otro caso, crea dos globos de un tipo inferior
default:
const int index = createBalloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_NEGATIVE, enemySpeed, 0);
balloons.at(index)->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
if (balloons.at(index)->getClass() == BALLOON_CLASS)
balloons[index]->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
if (balloons[index]->getClass() == BALLOON_CLASS)
{
balloons.at(index)->setVelY(-2.50f);
balloons[index]->setVelY(-2.50f);
}
else
{
balloons.at(index)->setVelY(BALLOON_VELX_NEGATIVE);
balloons[index]->setVelY(BALLOON_VELX_NEGATIVE);
}
const int index2 = createBalloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_POSITIVE, enemySpeed, 0);
balloons.at(index2)->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
if (balloons.at(index2)->getClass() == BALLOON_CLASS)
balloons[index2]->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
if (balloons[index2]->getClass() == BALLOON_CLASS)
{
balloons.at(index2)->setVelY(-2.50f);
balloons[index2]->setVelY(-2.50f);
}
else
{
balloons.at(index2)->setVelY(BALLOON_VELX_NEGATIVE);
balloons[index2]->setVelY(BALLOON_VELX_NEGATIVE);
}
// Elimina el globo
@@ -2201,9 +2201,9 @@ void Game::freeBalloons()
{
for (int i = balloons.size() - 1; i >= 0; --i)
{
if (balloons.at(i)->isEnabled() == false)
if (balloons[i]->isEnabled() == false)
{
delete balloons.at(i);
delete balloons[i];
balloons.erase(balloons.begin() + i);
}
}
@@ -2309,8 +2309,8 @@ void Game::checkBulletBalloonCollision()
{
// Otorga los puntos correspondientes al globo al jugador que disparó la bala
int index = bullet->getOwner();
players.at(index)->incScoreMultiplier();
players.at(index)->addScore(Uint32(balloon->getScore() * players.at(index)->getScoreMultiplier() * difficultyScoreMultiplier));
players[index]->incScoreMultiplier();
players[index]->addScore(Uint32(balloon->getScore() * players[index]->getScoreMultiplier() * difficultyScoreMultiplier));
updateHiScore();
// Explota el globo
@@ -2336,7 +2336,7 @@ void Game::checkBulletBalloonCollision()
}
else
{
createItem(droppeditem, players.at(index)->getPosX(), 0);
createItem(droppeditem, players[index]->getPosX(), 0);
coffeeMachineEnabled = true;
}
}
@@ -2357,7 +2357,7 @@ void Game::moveBullets()
{
if (bullet->move() == BULLET_MOVE_OUT)
{
players.at(bullet->getOwner())->decScoreMultiplier();
players[bullet->getOwner()]->decScoreMultiplier();
}
}
}
@@ -2389,9 +2389,9 @@ void Game::freeBullets()
{
for (int i = bullets.size() - 1; i >= 0; --i)
{
if (bullets.at(i)->isEnabled() == false)
if (bullets[i]->isEnabled() == false)
{
delete bullets.at(i);
delete bullets[i];
bullets.erase(bullets.begin() + i);
}
}
@@ -2503,7 +2503,7 @@ Uint8 Game::dropItem()
// Crea un objeto item
void Game::createItem(Uint8 kind, float x, float y)
{
Item *item = new Item(kind, x, y, itemTextures.at(kind), itemAnimations.at(kind), renderer);
Item *item = new Item(kind, x, y, itemTextures[kind], itemAnimations[kind], renderer);
items.push_back(item);
}
@@ -2514,9 +2514,9 @@ void Game::freeItems()
{
for (int i = items.size() - 1; i >= 0; --i)
{
if (items.at(i)->isEnabled() == false)
if (items[i]->isEnabled() == false)
{
delete items.at(i);
delete items[i];
items.erase(items.begin() + i);
}
}
@@ -2546,9 +2546,9 @@ void Game::freeSmartSprites()
{
for (int i = smartSprites.size() - 1; i >= 0; --i)
{
if (smartSprites.at(i)->hasFinished())
if (smartSprites[i]->hasFinished())
{
delete smartSprites.at(i);
delete smartSprites[i];
smartSprites.erase(smartSprites.begin() + i);
}
}
@@ -2588,7 +2588,7 @@ void Game::updateShakeEffect()
// Crea un SmartSprite para arrojar el item café al recibir un impacto
void Game::throwCoffee(int x, int y)
{
SmartSprite *ss = new SmartSprite(itemTextures.at(4), renderer);
SmartSprite *ss = new SmartSprite(itemTextures[4], renderer);
smartSprites.push_back(ss);
ss->setPosX(x - 8);
@@ -2919,7 +2919,7 @@ void Game::render()
renderScoreBoard();
renderPlayers();
if ((deathCounter <= 150) && !players.at(0)->isAlive())
if ((deathCounter <= 150) && !players[0]->isAlive())
{
renderDeathFade(150 - deathCounter);
}
@@ -2976,45 +2976,45 @@ void Game::checkGameInput()
const int index = 0;
if (demo.dataFile[demo.counter].left == 1)
{
players.at(index)->setInput(INPUT_LEFT);
players[index]->setInput(INPUT_LEFT);
}
if (demo.dataFile[demo.counter].right == 1)
{
players.at(index)->setInput(INPUT_RIGHT);
players[index]->setInput(INPUT_RIGHT);
}
if (demo.dataFile[demo.counter].noInput == 1)
{
players.at(index)->setInput(INPUT_NULL);
players[index]->setInput(INPUT_NULL);
}
if (demo.dataFile[demo.counter].fire == 1)
{
if (players.at(index)->canFire())
if (players[index]->canFire())
{
players.at(index)->setInput(INPUT_BUTTON_2);
createBullet(players.at(index)->getPosX() + (players.at(index)->getWidth() / 2) - 4, players.at(index)->getPosY() + (players.at(index)->getHeight() / 2), BULLET_UP, players.at(index)->isPowerUp(), index);
players.at(index)->setFireCooldown(10);
players[index]->setInput(INPUT_BUTTON_2);
createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index);
players[index]->setFireCooldown(10);
}
}
if (demo.dataFile[demo.counter].fireLeft == 1)
{
if (players.at(index)->canFire())
if (players[index]->canFire())
{
players.at(index)->setInput(INPUT_BUTTON_1);
createBullet(players.at(index)->getPosX() + (players.at(index)->getWidth() / 2) - 4, players.at(index)->getPosY() + (players.at(index)->getHeight() / 2), BULLET_UP, players.at(index)->isPowerUp(), index);
players.at(index)->setFireCooldown(10);
players[index]->setInput(INPUT_BUTTON_1);
createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index);
players[index]->setFireCooldown(10);
}
}
if (demo.dataFile[demo.counter].fireRight == 1)
{
if (players.at(index)->canFire())
if (players[index]->canFire())
{
players.at(index)->setInput(INPUT_BUTTON_3);
createBullet(players.at(index)->getPosX() + (players.at(index)->getWidth() / 2) - 4, players.at(index)->getPosY() + (players.at(index)->getHeight() / 2), BULLET_UP, players.at(index)->isPowerUp(), index);
players.at(index)->setFireCooldown(10);
players[index]->setInput(INPUT_BUTTON_3);
createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index);
players[index]->setFireCooldown(10);
}
}
@@ -3296,7 +3296,7 @@ section_t Game::run()
// Reproduce la música
if (!gameCompleted)
{
if (players.at(0)->isAlive())
if (players[0]->isAlive())
{
JA_PlayMusic(gameMusic);
}
@@ -3408,7 +3408,7 @@ void Game::renderPausedGame()
renderScoreBoard();
renderPlayers();
if ((deathCounter <= 150) && !players.at(0)->isAlive())
if ((deathCounter <= 150) && !players[0]->isAlive())
{
renderDeathFade(150 - deathCounter);
}
@@ -3578,7 +3578,7 @@ void Game::renderGameOverScreen()
textBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 6), lang->getText(43));
// Your Score
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 3), lang->getText(44) + std::to_string(players.at(0)->getScore()));
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 3), lang->getText(44) + std::to_string(players[0]->getScore()));
}
else
{
@@ -3592,10 +3592,10 @@ void Game::renderGameOverScreen()
textBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 7), lang->getText(43));
// Player1 Score
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 4), lang->getText(77) + std::to_string(players.at(0)->getScore()));
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 4), lang->getText(77) + std::to_string(players[0]->getScore()));
// Player2 Score
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 2), lang->getText(78) + std::to_string(players.at(1)->getScore()));
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 2), lang->getText(78) + std::to_string(players[1]->getScore()));
}
// Continue?