Fallo parcial en la carga de animaciones desde streams
This commit is contained in:
124
source/game.cpp
124
source/game.cpp
@@ -48,6 +48,16 @@ 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;
|
||||
|
||||
loadAnimations(mAsset->get("balloon1.ani"), balloon1Animation);
|
||||
loadAnimations(mAsset->get("balloon2.ani"), balloon2Animation);
|
||||
loadAnimations(mAsset->get("balloon3.ani"), balloon3Animation);
|
||||
loadAnimations(mAsset->get("balloon4.ani"), balloon4Animation);
|
||||
|
||||
mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), mRenderer);
|
||||
mTextScoreBoard = new Text(mAsset->get("8bithud.png"), mAsset->get("8bithud.txt"), mRenderer);
|
||||
mTextBig = new Text(mAsset->get("smb2_big.png"), mAsset->get("smb2_big.txt"), mRenderer);
|
||||
@@ -84,12 +94,6 @@ Game::~Game()
|
||||
|
||||
mOptions->input[0].deviceType = mOnePlayerControl;
|
||||
|
||||
mRenderer = nullptr;
|
||||
mScreen = nullptr;
|
||||
mAsset = nullptr;
|
||||
mLang = nullptr;
|
||||
mInput = nullptr;
|
||||
|
||||
for (auto player : players)
|
||||
{
|
||||
delete player;
|
||||
@@ -127,87 +131,45 @@ Game::~Game()
|
||||
balloon4Texture->unload();
|
||||
delete balloon4Texture;
|
||||
|
||||
delete balloon1Animation;
|
||||
delete balloon2Animation;
|
||||
delete balloon3Animation;
|
||||
delete balloon4Animation;
|
||||
|
||||
mTextureBullet->unload();
|
||||
delete mTextureBullet;
|
||||
mTextureBullet = nullptr;
|
||||
|
||||
mTextureGameBG->unload();
|
||||
delete mTextureGameBG;
|
||||
mTextureGameBG = nullptr;
|
||||
|
||||
mTextureGameText->unload();
|
||||
delete mTextureGameText;
|
||||
mTextureGameText = nullptr;
|
||||
|
||||
mTextureItems->unload();
|
||||
delete mTextureItems;
|
||||
mTextureItems = nullptr;
|
||||
|
||||
delete mText;
|
||||
mText = nullptr;
|
||||
|
||||
delete mTextBig;
|
||||
mTextBig = nullptr;
|
||||
|
||||
delete mTextScoreBoard;
|
||||
mTextScoreBoard = nullptr;
|
||||
|
||||
delete mTextNokia2;
|
||||
mTextNokia2 = nullptr;
|
||||
|
||||
delete mTextNokiaBig2;
|
||||
mTextNokiaBig2 = nullptr;
|
||||
|
||||
delete mMenuGameOver;
|
||||
mMenuGameOver = nullptr;
|
||||
|
||||
delete mMenuPause;
|
||||
mMenuPause = nullptr;
|
||||
|
||||
delete mFade;
|
||||
mFade = nullptr;
|
||||
|
||||
delete mEventHandler;
|
||||
mEventHandler = nullptr;
|
||||
|
||||
delete mClouds1a;
|
||||
mClouds1a = nullptr;
|
||||
|
||||
delete mClouds1b;
|
||||
mClouds1b = nullptr;
|
||||
|
||||
delete mClouds2a;
|
||||
mClouds2a = nullptr;
|
||||
|
||||
delete mClouds2b;
|
||||
mClouds2b = nullptr;
|
||||
|
||||
delete m1000Bitmap;
|
||||
m1000Bitmap = nullptr;
|
||||
|
||||
delete m2500Bitmap;
|
||||
m2500Bitmap = nullptr;
|
||||
|
||||
delete m5000Bitmap;
|
||||
m5000Bitmap = nullptr;
|
||||
|
||||
delete mSpriteBackground;
|
||||
mSpriteBackground = nullptr;
|
||||
|
||||
delete mSpriteGetReady;
|
||||
mSpriteGetReady = nullptr;
|
||||
|
||||
delete mSpriteGradient;
|
||||
mSpriteGradient = nullptr;
|
||||
|
||||
delete mSpriteGrass;
|
||||
mSpriteGrass = nullptr;
|
||||
|
||||
delete mSpritePowerMeter;
|
||||
mSpritePowerMeter = nullptr;
|
||||
|
||||
delete mSpriteScoreBoard;
|
||||
mSpriteScoreBoard = nullptr;
|
||||
|
||||
JA_DeleteSound(mSoundBalloon);
|
||||
JA_DeleteSound(mSoundBullet);
|
||||
@@ -1400,12 +1362,12 @@ void Game::deployEnemyFormation()
|
||||
const Uint8 numEnemies = mStage[mCurrentStage].enemyPool->set[set]->numberOfEnemies;
|
||||
for (int i = 0; i < numEnemies; ++i)
|
||||
{
|
||||
createNewBalloon(mStage[mCurrentStage].enemyPool->set[set]->init[i].x,
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].y,
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].kind,
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].velX,
|
||||
mEnemySpeed,
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].creationCounter);
|
||||
createBalloon(mStage[mCurrentStage].enemyPool->set[set]->init[i].x,
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].y,
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].kind,
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].velX,
|
||||
mEnemySpeed,
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].creationCounter);
|
||||
}
|
||||
|
||||
mEnemyDeployCounter = 300;
|
||||
@@ -1766,10 +1728,9 @@ void Game::renderBalloons()
|
||||
}
|
||||
|
||||
// Crea un globo nuevo en el vector de globos
|
||||
Uint8 Game::createNewBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 creationtimer)
|
||||
Uint8 Game::createBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 creationtimer)
|
||||
{
|
||||
const std::string file = balloonAnimation(kind);
|
||||
Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, balloonTexture(kind), file, mRenderer);
|
||||
Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, balloonTexture(kind), balloonStreamAnimation(kind), mRenderer);
|
||||
balloons.push_back(b);
|
||||
return (Uint8)(balloons.size() - 1);
|
||||
}
|
||||
@@ -1786,7 +1747,7 @@ void Game::createPowerBall()
|
||||
const int x[3] = {left, center, right};
|
||||
const int posX = x[rand() % 3];
|
||||
|
||||
Balloon *b = new Balloon(posX, posY, POWER_BALL, BALLOON_VELX_POSITIVE * (((rand() % 2) * 2) - 1), mEnemySpeed, 100, balloon4Texture, mAsset->get("balloon4.ani"), mRenderer);
|
||||
Balloon *b = new Balloon(posX, posY, POWER_BALL, BALLOON_VELX_POSITIVE * (((rand() % 2) * 2) - 1), mEnemySpeed, 100, balloon4Texture, balloon4Animation, mRenderer);
|
||||
balloons.push_back(b);
|
||||
|
||||
mPowerBallEnabled = true;
|
||||
@@ -1911,7 +1872,7 @@ 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 = createNewBalloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_NEGATIVE, mEnemySpeed, 0);
|
||||
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)
|
||||
{
|
||||
@@ -1922,7 +1883,7 @@ void Game::popBalloon(Balloon *balloon)
|
||||
balloons.at(index)->setVelY(BALLOON_VELX_NEGATIVE);
|
||||
}
|
||||
|
||||
const int index2 = createNewBalloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_POSITIVE, mEnemySpeed, 0);
|
||||
const int index2 = createBalloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_POSITIVE, mEnemySpeed, 0);
|
||||
balloons.at(index2)->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
||||
if (balloons.at(index2)->getClass() == BALLOON_CLASS)
|
||||
{
|
||||
@@ -2074,6 +2035,8 @@ 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;
|
||||
@@ -2098,29 +2061,29 @@ LTexture *Game::balloonTexture(int kind)
|
||||
}
|
||||
|
||||
// Obtiene la animacion correspondiente en funcion del tipo
|
||||
std::string Game::balloonAnimation(int kind)
|
||||
std::stringstream *Game::balloonStreamAnimation(int kind)
|
||||
{
|
||||
if (kind == 1 || kind == 5)
|
||||
{
|
||||
return mAsset->get("balloon1.ani");
|
||||
return balloon1Animation;
|
||||
}
|
||||
|
||||
else if (kind == 2 || kind == 6)
|
||||
{
|
||||
return mAsset->get("balloon2.ani");
|
||||
return balloon2Animation;
|
||||
}
|
||||
|
||||
else if (kind == 3 || kind == 7)
|
||||
{
|
||||
return mAsset->get("balloon3.ani");
|
||||
return balloon3Animation;
|
||||
}
|
||||
|
||||
else if (kind == 4 || kind == 8 || kind == 9)
|
||||
{
|
||||
return mAsset->get("balloon4.ani");
|
||||
return balloon4Animation;
|
||||
}
|
||||
|
||||
return mAsset->get("balloon1.ani");
|
||||
return balloon1Animation;
|
||||
}
|
||||
|
||||
// Vacia el vector de globos
|
||||
@@ -3657,4 +3620,23 @@ void Game::checkEventHandler()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Carga las animaciones
|
||||
void Game::loadAnimations(std::string filePath, std::stringstream *buffer)
|
||||
{
|
||||
std::ifstream file(filePath);
|
||||
|
||||
if (file)
|
||||
{
|
||||
std::cout << "Animation loaded: " << filePath.substr(filePath.find_last_of("\\/") + 1).c_str() << std::endl;
|
||||
*buffer << file.rdbuf();
|
||||
file.close();
|
||||
}
|
||||
|
||||
// std::string line;
|
||||
// while (std::getline(*buffer, line))
|
||||
//{
|
||||
// std::cout << line << std::endl;
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user