Ya empieza a funcionar la INTRO

This commit is contained in:
2022-09-28 19:41:12 +02:00
parent c213124193
commit e2298dc2b2
3 changed files with 238 additions and 239 deletions

View File

@@ -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;
}

View File

@@ -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 '='

View File

@@ -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);
@@ -138,48 +138,48 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
}
// Inicializa los objetos de menu
//mMenu.title->setText(mAsset->get("smb2.png"), mAsset->get("smb2.txt"));
//mMenu.title->setName("TITLE");
//mMenu.title->setPos(0, (14 * BLOCK) + 4);
//mMenu.title->setBackgroundType(MENU_BACKGROUND_TRANSPARENT);
//mMenu.title->addItem(mLang->getText(51), 2); // 1 PLAYER
//mMenu.title->addItem(mLang->getText(52), 7); // 2 PLAYERS
//mMenu.title->addItem(mLang->getText(1), 7); // OPTIONS
//mMenu.title->addItem(mLang->getText(3)); // QUIT
//mMenu.title->setDefaultActionWhenCancel(3);
//mMenu.title->setBackgroundColor({0x30, 0x30, 0x40}, 192);
//mMenu.title->setSelectorColor({0xe5, 0x1c, 0x23}, 0);
//mMenu.title->setSelectorTextColor({0xFF, 0xB4, 0x00});
//mMenu.title->centerMenuOnX(SCREEN_CENTER_X);
//mMenu.title->centerMenuElementsOnX();
// mMenu.title->setText(mAsset->get("smb2.png"), mAsset->get("smb2.txt"));
// mMenu.title->setName("TITLE");
// mMenu.title->setPos(0, (14 * BLOCK) + 4);
// mMenu.title->setBackgroundType(MENU_BACKGROUND_TRANSPARENT);
// mMenu.title->addItem(mLang->getText(51), 2); // 1 PLAYER
// mMenu.title->addItem(mLang->getText(52), 7); // 2 PLAYERS
// mMenu.title->addItem(mLang->getText(1), 7); // OPTIONS
// mMenu.title->addItem(mLang->getText(3)); // QUIT
// mMenu.title->setDefaultActionWhenCancel(3);
// mMenu.title->setBackgroundColor({0x30, 0x30, 0x40}, 192);
// mMenu.title->setSelectorColor({0xe5, 0x1c, 0x23}, 0);
// mMenu.title->setSelectorTextColor({0xFF, 0xB4, 0x00});
// mMenu.title->centerMenuOnX(SCREEN_CENTER_X);
// mMenu.title->centerMenuElementsOnX();
//mMenu.options->setText(mAsset->get("smb2.png"), mAsset->get("smb2.txt"));
//mMenu.options->setName("OPTIONS");
//mMenu.options->setPos(0, BLOCK);
//mMenu.options->setBackgroundType(MENU_BACKGROUND_TRANSPARENT);
//mMenu.options->addItem(mLang->getText(59), 7); // (0) DIFFICULTY
//mMenu.options->addItem(mLang->getText(62), 2, true, false, true); // (1) PLAYER 1 CONTROLS
//mMenu.options->addItem(mLang->getText(69), 7, false, false); // (2) KEYBOARD
//mMenu.options->addItem(mLang->getText(63), 2, true, false, true); // (3) PLAYER 2 CONTROLS
//mMenu.options->addItem(mLang->getText(70), 7, false, false); // (4) GAME CONTROLLER
//mMenu.options->addItem(mLang->getText(8), 7); // (5) LANGUAGE
//mMenu.options->addItem(mLang->getText(58), 2, true, false, true); // (6) DISPLAY MODE
//mMenu.options->addItem(mLang->getText(4), 7, false, false); // (7) WINDOW
//mMenu.options->addItem(mLang->getText(7), 2); // (8) WINDOW SIZE
//mMenu.options->addItem(mLang->getText(60), 2); // (9) FILTER
//mMenu.options->addItem(mLang->getText(61), 7); // (10) VSYNC
//mMenu.options->addItem(mLang->getText(2), 7); // (11) HOW TO PLAY
//mMenu.options->addItem(mLang->getText(9), 2); // (12) ACCEPT
//mMenu.options->addItem(mLang->getText(10)); // (13) CANCEL
//mMenu.options->setDefaultActionWhenCancel(13);
//mMenu.options->setBackgroundColor({0x30, 0x30, 0x40}, 192);
//mMenu.options->setSelectorColor({0xe5, 0x1c, 0x23}, 255);
//mMenu.options->setSelectorTextColor({0xFF, 0xF1, 0x76});
//mMenu.options->centerMenuOnX(SCREEN_CENTER_X);
//mMenu.options->centerMenuOnY(SCREEN_CENTER_Y);
// mMenu.options->setText(mAsset->get("smb2.png"), mAsset->get("smb2.txt"));
// mMenu.options->setName("OPTIONS");
// mMenu.options->setPos(0, BLOCK);
// mMenu.options->setBackgroundType(MENU_BACKGROUND_TRANSPARENT);
// mMenu.options->addItem(mLang->getText(59), 7); // (0) DIFFICULTY
// mMenu.options->addItem(mLang->getText(62), 2, true, false, true); // (1) PLAYER 1 CONTROLS
// mMenu.options->addItem(mLang->getText(69), 7, false, false); // (2) KEYBOARD
// mMenu.options->addItem(mLang->getText(63), 2, true, false, true); // (3) PLAYER 2 CONTROLS
// mMenu.options->addItem(mLang->getText(70), 7, false, false); // (4) GAME CONTROLLER
// mMenu.options->addItem(mLang->getText(8), 7); // (5) LANGUAGE
// mMenu.options->addItem(mLang->getText(58), 2, true, false, true); // (6) DISPLAY MODE
// mMenu.options->addItem(mLang->getText(4), 7, false, false); // (7) WINDOW
// mMenu.options->addItem(mLang->getText(7), 2); // (8) WINDOW SIZE
// mMenu.options->addItem(mLang->getText(60), 2); // (9) FILTER
// mMenu.options->addItem(mLang->getText(61), 7); // (10) VSYNC
// mMenu.options->addItem(mLang->getText(2), 7); // (11) HOW TO PLAY
// mMenu.options->addItem(mLang->getText(9), 2); // (12) ACCEPT
// mMenu.options->addItem(mLang->getText(10)); // (13) CANCEL
// mMenu.options->setDefaultActionWhenCancel(13);
// mMenu.options->setBackgroundColor({0x30, 0x30, 0x40}, 192);
// mMenu.options->setSelectorColor({0xe5, 0x1c, 0x23}, 255);
// mMenu.options->setSelectorTextColor({0xFF, 0xF1, 0x76});
// mMenu.options->centerMenuOnX(SCREEN_CENTER_X);
// mMenu.options->centerMenuOnY(SCREEN_CENTER_Y);
// Actualiza los textos de los menus
//updateMenuLabels();
// updateMenuLabels();
}
// Destructor
@@ -260,195 +260,184 @@ 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
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{
// Reproduce la música
JA_PlayMusic(mMusic);
}
// Calcula la lógica de los objetos
if (SDL_GetTicks() - mTicks > mTicksSpeed)
// Actualiza el contador de ticks
mTicks = SDL_GetTicks();
mDustBitmapR->update();
mDustBitmapL->update();
// Actualiza la lógica del titulo
mMenu.active->update();
mFade->update();
if (mFade->hasEnded())
{
switch (mPostFade)
{
// Actualiza el contador de ticks
mTicks = SDL_GetTicks();
case 0: // 1 PLAYER
mSection.name = PROG_SECTION_GAME;
mSection.subsection = GAME_SECTION_PLAY_1P;
JA_StopMusic();
break;
mDustBitmapR->update();
mDustBitmapL->update();
case 1: // 2 PLAYERS
mSection.name = PROG_SECTION_GAME;
mSection.subsection = GAME_SECTION_PLAY_2P;
JA_StopMusic();
break;
// Actualiza la lógica del titulo
mMenu.active->update();
mFade->update();
if (mFade->hasEnded())
case 2: // QUIT
mSection.name = PROG_SECTION_QUIT;
JA_StopMusic();
break;
case 3: // TIME OUT
mCounter = TITLE_COUNTER;
mMenu.active->reset();
if (mDemo)
{
switch (mPostFade)
{
case 0: // 1 PLAYER
mSection.name = PROG_SECTION_GAME;
mSection.subsection = GAME_SECTION_PLAY_1P;
JA_StopMusic();
break;
case 1: // 2 PLAYERS
mSection.name = PROG_SECTION_GAME;
mSection.subsection = GAME_SECTION_PLAY_2P;
JA_StopMusic();
break;
case 2: // QUIT
mSection.name = PROG_SECTION_QUIT;
JA_StopMusic();
break;
case 3: // TIME OUT
mCounter = TITLE_COUNTER;
mMenu.active->reset();
if (mDemo)
{
runDemoGame();
runInstructions(INSTRUCTIONS_MODE_AUTO);
}
else
mSection.name = PROG_SECTION_LOGO;
break;
default:
break;
}
runDemoGame();
runInstructions(INSTRUCTIONS_MODE_AUTO);
}
else
mSection.name = PROG_SECTION_LOGO;
break;
// Actualiza el tileado de fondo
updateBG();
// Comprueba las entradas para el menu
if (mMenuVisible == true)
{
mMenu.active->checkInput();
}
// Comprueba si se ha seleccionado algún item del menú
if (mMenu.active->getName() == "TITLE")
{
switch (mMenu.active->getItemSelected())
{
case 0: // 1 PLAYER
mPostFade = 0;
mFade->activateFade();
break;
case 1: // 2 PLAYERS
mPostFade = 1;
mFade->activateFade();
break;
case 2: // OPTIONS
mMenu.active = mMenu.options;
mOptionsPrevious = *mOptions;
break;
case 3: // QUIT
mPostFade = 2;
mFade->activateFade();
break;
default:
break;
}
}
// Comprueba si se ha seleccionado algún item de opciones
if (mMenu.active->getName() == "OPTIONS")
{
switch (mMenu.active->getItemSelected())
{
case 0: // Difficulty
if (mOptions->difficulty == DIFFICULTY_EASY)
mOptions->difficulty = DIFFICULTY_NORMAL;
else if (mOptions->difficulty == DIFFICULTY_NORMAL)
mOptions->difficulty = DIFFICULTY_HARD;
else
mOptions->difficulty = DIFFICULTY_EASY;
updateMenuLabels();
break;
case 1: // PLAYER 1 CONTROLS
updatePlayerInputs(0);
updateMenuLabels();
break;
case 3: // PLAYER 2 CONTROLS
updatePlayerInputs(1);
updateMenuLabels();
break;
case 5: // Language
mOptions->language++;
if (mOptions->language == 3)
mOptions->language = 0;
updateMenuLabels();
break;
case 6: // Display mode
switchFullScreenModeVar();
if (mOptions->fullScreenMode != 0)
{
mMenu.options->setSelectable(8, false);
mMenu.options->setGreyed(8, true);
}
else
{
mMenu.options->setSelectable(8, true);
mMenu.options->setGreyed(8, false);
}
updateMenuLabels();
break;
case 8: // Windows size
mOptions->windowSize++;
if (mOptions->windowSize == 5)
mOptions->windowSize = 1;
updateMenuLabels();
break;
case 9: // FILTER
if (mOptions->filter == FILTER_LINEAL)
mOptions->filter = FILTER_NEAREST;
else
mOptions->filter = FILTER_LINEAL;
updateMenuLabels();
break;
case 10: // VSYNC
if (mOptions->vSync)
mOptions->vSync = false;
else
mOptions->vSync = true;
updateMenuLabels();
break;
case 11: // HOW TO PLAY
runInstructions(INSTRUCTIONS_MODE_MANUAL);
break;
case 12: // ACCEPT
applyOptions();
mMenu.active->reset();
mMenu.active = mMenu.title;
break;
case 13: // CANCEL
mOptions = &mOptionsPrevious;
updateMenuLabels();
mMenu.active->reset();
mMenu.active = mMenu.title;
break;
default:
break;
}
}
if (mMenu.active->getName() == "TITLE")
mCounter--;
default:
break;
}
}
else if (mCounter == 0)
// Actualiza el tileado de fondo
updateBG();
// Comprueba las entradas para el menu
if (mMenuVisible == true)
{
// if (mDemo)
//{
// runDemoGame();
// runInstructions(INSTRUCTIONS_MODE_AUTO);
// }
// else
mSection.name = PROG_SECTION_LOGO;
mMenu.active->checkInput();
}
// Comprueba si se ha seleccionado algún item del menú
if (mMenu.active->getName() == "TITLE")
{
switch (mMenu.active->getItemSelected())
{
case 0: // 1 PLAYER
mPostFade = 0;
mFade->activateFade();
break;
case 1: // 2 PLAYERS
mPostFade = 1;
mFade->activateFade();
break;
case 2: // OPTIONS
mMenu.active = mMenu.options;
mOptionsPrevious = *mOptions;
break;
case 3: // QUIT
mPostFade = 2;
mFade->activateFade();
break;
default:
break;
}
}
// Comprueba si se ha seleccionado algún item de opciones
if (mMenu.active->getName() == "OPTIONS")
{
switch (mMenu.active->getItemSelected())
{
case 0: // Difficulty
if (mOptions->difficulty == DIFFICULTY_EASY)
mOptions->difficulty = DIFFICULTY_NORMAL;
else if (mOptions->difficulty == DIFFICULTY_NORMAL)
mOptions->difficulty = DIFFICULTY_HARD;
else
mOptions->difficulty = DIFFICULTY_EASY;
updateMenuLabels();
break;
case 1: // PLAYER 1 CONTROLS
updatePlayerInputs(0);
updateMenuLabels();
break;
case 3: // PLAYER 2 CONTROLS
updatePlayerInputs(1);
updateMenuLabels();
break;
case 5: // Language
mOptions->language++;
if (mOptions->language == 3)
mOptions->language = 0;
updateMenuLabels();
break;
case 6: // Display mode
switchFullScreenModeVar();
if (mOptions->fullScreenMode != 0)
{
mMenu.options->setSelectable(8, false);
mMenu.options->setGreyed(8, true);
}
else
{
mMenu.options->setSelectable(8, true);
mMenu.options->setGreyed(8, false);
}
updateMenuLabels();
break;
case 8: // Windows size
mOptions->windowSize++;
if (mOptions->windowSize == 5)
mOptions->windowSize = 1;
updateMenuLabels();
break;
case 9: // FILTER
if (mOptions->filter == FILTER_LINEAL)
mOptions->filter = FILTER_NEAREST;
else
mOptions->filter = FILTER_LINEAL;
updateMenuLabels();
break;
case 10: // VSYNC
if (mOptions->vSync)
mOptions->vSync = false;
else
mOptions->vSync = true;
updateMenuLabels();
break;
case 11: // HOW TO PLAY
runInstructions(INSTRUCTIONS_MODE_MANUAL);
break;
case 12: // ACCEPT
applyOptions();
mMenu.active->reset();
mMenu.active = mMenu.title;
break;
case 13: // CANCEL
mOptions = &mOptionsPrevious;
updateMenuLabels();
mMenu.active->reset();
mMenu.active = mMenu.title;
break;
default:
break;
}
}
if (mMenu.active->getName() == "TITLE")
{
mCounter--;
}
}
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)