Ya empieza a funcionar la INTRO
This commit is contained in:
@@ -163,9 +163,10 @@ SDL_Rect AnimatedSprite::getAnimationClip(int indexA, Uint8 indexF)
|
||||
// Carga la animación desde un fichero
|
||||
bool AnimatedSprite::load(std::string filePath)
|
||||
{
|
||||
int frames_per_row = 0;
|
||||
int frame_width = 0;
|
||||
int frame_height = 0;
|
||||
int framesPerRow = 0;
|
||||
int frameWidth = 0;
|
||||
int frameHeight = 0;
|
||||
int maxTiles = 0;
|
||||
|
||||
// Indicador de éxito en la carga
|
||||
bool success = true;
|
||||
@@ -216,12 +217,13 @@ bool AnimatedSprite::load(std::string filePath)
|
||||
// Se introducen los valores separados por comas en un vector
|
||||
std::stringstream ss(line.substr(pos + 1, line.length()));
|
||||
std::string tmp;
|
||||
SDL_Rect rect = {0, 0, frame_width, frame_height};
|
||||
SDL_Rect rect = {0, 0, frameWidth, frameHeight};
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
int num_tile = std::stoi(tmp);
|
||||
rect.x = (num_tile % frames_per_row) * frame_width;
|
||||
rect.y = (num_tile / frames_per_row) * frame_height;
|
||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||
const int numTile = std::stoi(tmp) > maxTiles ? 0 : std::stoi(tmp);
|
||||
rect.x = (numTile % framesPerRow) * frameWidth;
|
||||
rect.y = (numTile / framesPerRow) * frameHeight;
|
||||
buffer.frames.push_back(rect);
|
||||
}
|
||||
}
|
||||
@@ -246,25 +248,19 @@ bool AnimatedSprite::load(std::string filePath)
|
||||
// Procesa las dos subcadenas
|
||||
if (pos != (int)line.npos)
|
||||
{
|
||||
if (line.substr(0, pos) == "frames_per_row")
|
||||
if (line.substr(0, pos) == "framesPerRow")
|
||||
{
|
||||
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
|
||||
framesPerRow = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frame_width")
|
||||
else if (line.substr(0, pos) == "frameWidth")
|
||||
{
|
||||
frame_width = std::stoi(line.substr(pos + 1, line.length()));
|
||||
|
||||
// Normaliza valores
|
||||
if (frames_per_row == 0)
|
||||
{
|
||||
frames_per_row = texture->getWidth() / frame_width;
|
||||
}
|
||||
frameWidth = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frame_height")
|
||||
else if (line.substr(0, pos) == "frameHeight")
|
||||
{
|
||||
frame_height = std::stoi(line.substr(pos + 1, line.length()));
|
||||
frameHeight = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else
|
||||
@@ -272,6 +268,19 @@ bool AnimatedSprite::load(std::string filePath)
|
||||
printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
|
||||
success = false;
|
||||
}
|
||||
|
||||
// Normaliza valores
|
||||
if (framesPerRow == 0 && frameWidth > 0)
|
||||
{
|
||||
framesPerRow = texture->getWidth() / frameWidth;
|
||||
}
|
||||
|
||||
if (maxTiles == 0 && frameWidth > 0 && frameHeight > 0)
|
||||
{
|
||||
const int w = texture->getWidth() / frameWidth;
|
||||
const int h = texture->getHeight() / frameHeight;
|
||||
maxTiles = w * h;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -288,7 +297,7 @@ bool AnimatedSprite::load(std::string filePath)
|
||||
}
|
||||
|
||||
// Pone un valor por defecto
|
||||
setPos({0, 0, frame_width, frame_height});
|
||||
setPos({0, 0, frameWidth, frameHeight});
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ bool Menu::load(std::string file_path)
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
// Lee la siguiente linea
|
||||
std::getline(file, line);
|
||||
|
||||
// Encuentra la posición del caracter '='
|
||||
|
||||
@@ -100,7 +100,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
|
||||
mCrisisBitmap->setVelY(-2.5f);
|
||||
mCrisisBitmap->setAccelX(0.0f);
|
||||
mCrisisBitmap->setAccelY(-0.1f);
|
||||
mCrisisBitmap->setSpriteClip(0, 46, 137, 46);
|
||||
mCrisisBitmap->setSpriteClip(0, 0, 137, 46);
|
||||
mCrisisBitmap->setEnabled(true);
|
||||
mCrisisBitmap->setEnabledCounter(0);
|
||||
mCrisisBitmap->setDestX(60);
|
||||
@@ -259,15 +259,13 @@ void Title::update()
|
||||
|
||||
// Sección 3 - La pantalla de titulo con el menú y la música
|
||||
case TITLE_SECTION_3:
|
||||
{
|
||||
if (mCounter > 0)
|
||||
{
|
||||
// Reproduce la música
|
||||
JA_PlayMusic(mMusic);
|
||||
|
||||
// Calcula la lógica de los objetos
|
||||
if (SDL_GetTicks() - mTicks > mTicksSpeed)
|
||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||
{
|
||||
JA_PlayMusic(mMusic);
|
||||
}
|
||||
|
||||
// Actualiza el contador de ticks
|
||||
mTicks = SDL_GetTicks();
|
||||
|
||||
@@ -435,20 +433,11 @@ void Title::update()
|
||||
}
|
||||
|
||||
if (mMenu.active->getName() == "TITLE")
|
||||
{
|
||||
mCounter--;
|
||||
}
|
||||
}
|
||||
else if (mCounter == 0)
|
||||
{
|
||||
// if (mDemo)
|
||||
//{
|
||||
// runDemoGame();
|
||||
// runInstructions(INSTRUCTIONS_MODE_AUTO);
|
||||
// }
|
||||
// else
|
||||
mSection.name = PROG_SECTION_LOGO;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -503,8 +492,9 @@ void Title::render()
|
||||
mCrisisBitmap->setPosX(b + v[n / 3]);
|
||||
mCoffeeBitmap->render();
|
||||
mCrisisBitmap->render();
|
||||
mDustBitmapR->animate();
|
||||
mDustBitmapL->animate();
|
||||
|
||||
mDustBitmapR->update();
|
||||
mDustBitmapL->update();
|
||||
mDustBitmapR->render();
|
||||
mDustBitmapL->render();
|
||||
|
||||
@@ -929,7 +919,7 @@ void Title::createTiledBackground()
|
||||
SDL_RenderClear(mRenderer);
|
||||
|
||||
// Rellena la textura con el tile
|
||||
tile->setSpriteClip(192, 0, 64, 64);
|
||||
tile->setSpriteClip(0, 0, 64, 64);
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
for (int j = 0; j < 6; ++j)
|
||||
|
||||
Reference in New Issue
Block a user