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