Optimizada la carga de las animaciones de los globos. Cacheada

This commit is contained in:
2022-10-04 12:13:47 +02:00
parent ddb70c8c85
commit c3fd348a61
6 changed files with 45 additions and 51 deletions

View File

@@ -48,10 +48,10 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
mTextureGameText = new LTexture(mRenderer, mAsset->get("game_text.png"));
mTextureItems = new LTexture(mRenderer, mAsset->get("items.png"));
balloon1Animation = new std::stringstream;
balloon2Animation = new std::stringstream;
balloon3Animation = new std::stringstream;
balloon4Animation = new std::stringstream;
balloon1Animation = new std::vector<std::string>;
balloon2Animation = new std::vector<std::string>;
balloon3Animation = new std::vector<std::string>;
balloon4Animation = new std::vector<std::string>;
loadAnimations(mAsset->get("balloon1.ani"), balloon1Animation);
loadAnimations(mAsset->get("balloon2.ani"), balloon2Animation);
@@ -1871,7 +1871,6 @@ void Game::popBalloon(Balloon *balloon)
// En cualquier otro caso, crea dos globos de un tipo inferior
default:
// Balloon *b1 = new Balloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_NEGATIVE, mEnemySpeed, 0, mRenderer);
const int index = createBalloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_NEGATIVE, mEnemySpeed, 0);
balloons.at(index)->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
if (balloons.at(index)->getClass() == BALLOON_CLASS)
@@ -2035,8 +2034,6 @@ Uint8 Game::countBalloons()
// Obtiene la textura correspondiente en funcion del tipo
LTexture *Game::balloonTexture(int kind)
{
std::cout << " ********** kind: " << kind << std::endl;
if (kind == 1 || kind == 5)
{
return balloon1Texture;
@@ -2061,7 +2058,7 @@ LTexture *Game::balloonTexture(int kind)
}
// Obtiene la animacion correspondiente en funcion del tipo
std::stringstream *Game::balloonStreamAnimation(int kind)
std::vector<std::string> *Game::balloonStreamAnimation(int kind)
{
if (kind == 1 || kind == 5)
{
@@ -2186,9 +2183,9 @@ void Game::checkPlayerItemCollision(Player *player)
// Comprueba y procesa la colisión entre las balas y los globos
void Game::checkBulletBalloonCollision()
{
for (auto balloon : balloons)
for (auto bullet : bullets)
{
for (auto bullet : bullets)
for (auto balloon : balloons)
{
if (balloon->isEnabled() && (!balloon->isInvulnerable()) && bullet->isActive())
{
@@ -2227,6 +2224,7 @@ void Game::checkBulletBalloonCollision()
mCoffeeMachineEnabled = true;
}
}
break;
}
}
@@ -3623,20 +3621,18 @@ void Game::checkEventHandler()
}
// Carga las animaciones
void Game::loadAnimations(std::string filePath, std::stringstream *buffer)
void Game::loadAnimations(std::string filePath, std::vector<std::string> *buffer)
{
std::ifstream file(filePath);
std::string line;
if (file)
{
std::cout << "Animation loaded: " << filePath.substr(filePath.find_last_of("\\/") + 1).c_str() << std::endl;
*buffer << file.rdbuf();
while (std::getline(file, line))
{
buffer->push_back(line);
}
file.close();
}
// std::string line;
// while (std::getline(*buffer, line))
//{
// std::cout << line << std::endl;
// }
}