Corregido el bug de la asignacion de items del menu de la intro

This commit is contained in:
2022-09-28 22:23:26 +02:00
parent 3d75fae393
commit fd90a3c66c
6 changed files with 153 additions and 153 deletions

View File

@@ -50,37 +50,37 @@ int AnimatedSprite::getIndex(std::string name)
// Calcula el frame correspondiente a la animación
void AnimatedSprite::animate()
{
if (!enabled || animation[currentAnimation].speed == 0)
if (!enabled || animation.at(currentAnimation).speed == 0)
{
return;
}
// Calcula el frame actual a partir del contador
animation[currentAnimation].currentFrame = animation[currentAnimation].counter / animation[currentAnimation].speed;
animation.at(currentAnimation).currentFrame = animation.at(currentAnimation).counter / animation.at(currentAnimation).speed;
// Si alcanza el final de la animación, reinicia el contador de la animación
// en función de la variable loop y coloca el nuevo frame
if (animation[currentAnimation].currentFrame >= (int)animation[currentAnimation].frames.size())
if (animation.at(currentAnimation).currentFrame >= (int)animation.at(currentAnimation).frames.size())
{
if (animation[currentAnimation].loop == -1)
if (animation.at(currentAnimation).loop == -1)
{ // Si no hay loop, deja el último frame
animation[currentAnimation].currentFrame = animation[currentAnimation].frames.size();
animation[currentAnimation].completed = true;
animation.at(currentAnimation).currentFrame = animation.at(currentAnimation).frames.size();
animation.at(currentAnimation).completed = true;
}
else
{ // Si hay loop, vuelve al frame indicado
animation[currentAnimation].counter = 0;
animation[currentAnimation].currentFrame = animation[currentAnimation].loop;
animation.at(currentAnimation).counter = 0;
animation.at(currentAnimation).currentFrame = animation.at(currentAnimation).loop;
}
}
// En caso contrario
else
{
// Escoge el frame correspondiente de la animación
setSpriteClip(animation[currentAnimation].frames[animation[currentAnimation].currentFrame]);
setSpriteClip(animation.at(currentAnimation).frames.at(animation.at(currentAnimation).currentFrame));
// Incrementa el contador de la animacion
animation[currentAnimation].counter++;
animation.at(currentAnimation).counter++;
}
}
@@ -88,76 +88,76 @@ void AnimatedSprite::animate()
void AnimatedSprite::setCurrentFrame(int num)
{
// Descarta valores fuera de rango
if (num >= (int)animation[currentAnimation].frames.size())
if (num >= (int)animation.at(currentAnimation).frames.size())
{
num = 0;
}
// Cambia el valor de la variable
animation[currentAnimation].counter = animation[currentAnimation].speed * num;
animation.at(currentAnimation).counter = animation.at(currentAnimation).speed * num;
// Escoge el frame correspondiente de la animación
setSpriteClip(animation[currentAnimation].frames[animation[currentAnimation].currentFrame]);
setSpriteClip(animation.at(currentAnimation).frames.at(animation.at(currentAnimation).currentFrame));
}
// Establece el valor del contador
void AnimatedSprite::setAnimationCounter(std::string name, int num)
{
animation[getIndex(name)].counter = num;
animation.at(getIndex(name)).counter = num;
}
// Establece la velocidad de una animación
void AnimatedSprite::setAnimationSpeed(std::string name, int speed)
{
animation[getIndex(name)].counter = speed;
animation.at(getIndex(name)).counter = speed;
}
// Establece la velocidad de una animación
void AnimatedSprite::setAnimationSpeed(int index, int speed)
{
animation[index].counter = speed;
animation.at(index).counter = speed;
}
// Establece si la animación se reproduce en bucle
void AnimatedSprite::setAnimationLoop(std::string name, int loop)
{
animation[getIndex(name)].loop = loop;
animation.at(getIndex(name)).loop = loop;
}
// Establece si la animación se reproduce en bucle
void AnimatedSprite::setAnimationLoop(int index, int loop)
{
animation[index].loop = loop;
animation.at(index).loop = loop;
}
// Establece el valor de la variable
void AnimatedSprite::setAnimationCompleted(std::string name, bool value)
{
animation[getIndex(name)].completed = value;
animation.at(getIndex(name)).completed = value;
}
// OLD - Establece el valor de la variable
void AnimatedSprite::setAnimationCompleted(int index, bool value)
{
animation[index].completed = value;
animation.at(index).completed = value;
}
// Comprueba si ha terminado la animación
bool AnimatedSprite::animationIsCompleted()
{
return animation[currentAnimation].completed;
return animation.at(currentAnimation).completed;
}
// Devuelve el rectangulo de una animación y frame concreto
SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index)
{
return animation[getIndex(name)].frames[index];
return animation.at(getIndex(name)).frames.at(index);
}
// Devuelve el rectangulo de una animación y frame concreto
SDL_Rect AnimatedSprite::getAnimationClip(int indexA, Uint8 indexF)
{
return animation[indexA].frames[indexF];
return animation.at(indexA).frames.at(indexF);
}
// Carga la animación desde un fichero
@@ -309,9 +309,9 @@ void AnimatedSprite::setCurrentAnimation(std::string name)
if (currentAnimation != newAnimation)
{
currentAnimation = newAnimation;
animation[currentAnimation].currentFrame = 0;
animation[currentAnimation].counter = 0;
animation[currentAnimation].completed = false;
animation.at(currentAnimation).currentFrame = 0;
animation.at(currentAnimation).counter = 0;
animation.at(currentAnimation).completed = false;
}
}
@@ -322,9 +322,9 @@ void AnimatedSprite::setCurrentAnimation(int index)
if (currentAnimation != newAnimation)
{
currentAnimation = newAnimation;
animation[currentAnimation].currentFrame = 0;
animation[currentAnimation].counter = 0;
animation[currentAnimation].completed = false;
animation.at(currentAnimation).currentFrame = 0;
animation.at(currentAnimation).counter = 0;
animation.at(currentAnimation).completed = false;
}
}
@@ -338,7 +338,7 @@ void AnimatedSprite::update()
// Establece el rectangulo para un frame de una animación
void AnimatedSprite::setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h)
{
animation[index_animation].frames.push_back({x, y, w, h});
animation.at(index_animation).frames.push_back({x, y, w, h});
}
// OLD - Establece el contador para todas las animaciones

View File

@@ -960,8 +960,8 @@ void Balloon::updateBounce()
{
if (mBouncing.enabled)
{
mBouncing.zoomW = mBouncing.w[mBouncing.counter / mBouncing.speed];
mBouncing.zoomH = mBouncing.h[mBouncing.counter / mBouncing.speed];
mBouncing.zoomW = mBouncing.w.at(mBouncing.counter / mBouncing.speed);
mBouncing.zoomH = mBouncing.h.at(mBouncing.counter / mBouncing.speed);
mSprite->setZoomW(mBouncing.zoomW);
mSprite->setZoomH(mBouncing.zoomH);
mBouncing.despX = (mSprite->getSpriteClip().w - (mSprite->getSpriteClip().w * mBouncing.zoomW));

View File

@@ -37,54 +37,54 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang)
bitmaps.push_back(ss);
}
bitmaps[0]->setPosX(-128);
bitmaps[0]->setPosY(SCREEN_FIRST_QUARTER_Y - 24);
bitmaps[0]->setVelX(0.0f);
bitmaps[0]->setVelY(0.0f);
bitmaps[0]->setAccelX(0.6f);
bitmaps[0]->setAccelY(0.0f);
bitmaps[0]->setSpriteClip(0, 0, 128, 96);
bitmaps.at(0)->setPosX(-128);
bitmaps.at(0)->setPosY(SCREEN_FIRST_QUARTER_Y - 24);
bitmaps.at(0)->setVelX(0.0f);
bitmaps.at(0)->setVelY(0.0f);
bitmaps.at(0)->setAccelX(0.6f);
bitmaps.at(0)->setAccelY(0.0f);
bitmaps.at(0)->setSpriteClip(0, 0, 128, 96);
bitmaps[1]->setPosX(GAME_WIDTH);
bitmaps[1]->setPosY(SCREEN_FIRST_QUARTER_Y - 24);
bitmaps[1]->setVelX(-1.0f);
bitmaps[1]->setVelY(0.0f);
bitmaps[1]->setAccelX(-0.3f);
bitmaps[1]->setAccelY(0.0f);
bitmaps[1]->setSpriteClip(128, 0, 128, 96);
bitmaps.at(1)->setPosX(GAME_WIDTH);
bitmaps.at(1)->setPosY(SCREEN_FIRST_QUARTER_Y - 24);
bitmaps.at(1)->setVelX(-1.0f);
bitmaps.at(1)->setVelY(0.0f);
bitmaps.at(1)->setAccelX(-0.3f);
bitmaps.at(1)->setAccelY(0.0f);
bitmaps.at(1)->setSpriteClip(128, 0, 128, 96);
bitmaps[2]->setPosX(SCREEN_CENTER_X - 64);
bitmaps[2]->setPosY(-96);
bitmaps[2]->setVelX(0.0f);
bitmaps[2]->setVelY(3.0f);
bitmaps[2]->setAccelX(0.1f);
bitmaps[2]->setAccelY(0.3f);
bitmaps[2]->setSpriteClip(0, 96, 128, 96);
bitmaps[2]->setEnabledCounter(250);
bitmaps.at(2)->setPosX(SCREEN_CENTER_X - 64);
bitmaps.at(2)->setPosY(-96);
bitmaps.at(2)->setVelX(0.0f);
bitmaps.at(2)->setVelY(3.0f);
bitmaps.at(2)->setAccelX(0.1f);
bitmaps.at(2)->setAccelY(0.3f);
bitmaps.at(2)->setSpriteClip(0, 96, 128, 96);
bitmaps.at(2)->setEnabledCounter(250);
bitmaps[3]->setPosX(SCREEN_CENTER_X - 64);
bitmaps[3]->setPosY(GAME_HEIGHT);
bitmaps[3]->setVelX(0.0f);
bitmaps[3]->setVelY(-0.7f);
bitmaps[3]->setAccelX(0.0f);
bitmaps[3]->setAccelY(0.0f);
bitmaps[3]->setSpriteClip(128, 96, 128, 96);
bitmaps.at(3)->setPosX(SCREEN_CENTER_X - 64);
bitmaps.at(3)->setPosY(GAME_HEIGHT);
bitmaps.at(3)->setVelX(0.0f);
bitmaps.at(3)->setVelY(-0.7f);
bitmaps.at(3)->setAccelX(0.0f);
bitmaps.at(3)->setAccelY(0.0f);
bitmaps.at(3)->setSpriteClip(128, 96, 128, 96);
bitmaps[4]->setPosX(SCREEN_CENTER_X - 64);
bitmaps[4]->setPosY(-96);
bitmaps[4]->setVelX(0.0f);
bitmaps[4]->setVelY(3.0f);
bitmaps[4]->setAccelX(0.1f);
bitmaps[4]->setAccelY(0.3f);
bitmaps[4]->setSpriteClip(0, 192, 128, 96);
bitmaps.at(4)->setPosX(SCREEN_CENTER_X - 64);
bitmaps.at(4)->setPosY(-96);
bitmaps.at(4)->setVelX(0.0f);
bitmaps.at(4)->setVelY(3.0f);
bitmaps.at(4)->setAccelX(0.1f);
bitmaps.at(4)->setAccelY(0.3f);
bitmaps.at(4)->setSpriteClip(0, 192, 128, 96);
bitmaps[5]->setPosX(GAME_WIDTH);
bitmaps[5]->setPosY(SCREEN_FIRST_QUARTER_Y - 24);
bitmaps[5]->setVelX(-0.7f);
bitmaps[5]->setVelY(0.0f);
bitmaps[5]->setAccelX(0.0f);
bitmaps[5]->setAccelY(0.0f);
bitmaps[5]->setSpriteClip(128, 192, 128, 96);
bitmaps.at(5)->setPosX(GAME_WIDTH);
bitmaps.at(5)->setPosY(SCREEN_FIRST_QUARTER_Y - 24);
bitmaps.at(5)->setVelX(-0.7f);
bitmaps.at(5)->setVelY(0.0f);
bitmaps.at(5)->setAccelX(0.0f);
bitmaps.at(5)->setAccelY(0.0f);
bitmaps.at(5)->setSpriteClip(128, 192, 128, 96);
// Inicializa los textos de la intro
const int totalTexts = 9;
@@ -100,40 +100,40 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang)
}
// Un dia qualsevol de l'any 2000
texts[0]->setCaption(lang->getText(27));
texts[0]->setSpeed(10);
texts.at(0)->setCaption(lang->getText(27));
texts.at(0)->setSpeed(10);
// Tot esta tranquil a la UPV
texts[1]->setCaption(lang->getText(28));
texts[1]->setSpeed(10);
texts.at(1)->setCaption(lang->getText(28));
texts.at(1)->setSpeed(10);
// Fins que un desaprensiu...
texts[2]->setCaption(lang->getText(29));
texts[2]->setSpeed(15);
texts.at(2)->setCaption(lang->getText(29));
texts.at(2)->setSpeed(15);
// HEY! ME ANE A FERME UN CORTAET...
texts[3]->setCaption(lang->getText(30));
texts[3]->setSpeed(10);
texts.at(3)->setCaption(lang->getText(30));
texts.at(3)->setSpeed(10);
// UAAAAAAAAAAAAA!!!
texts[4]->setCaption(lang->getText(31));
texts[4]->setSpeed(1);
texts.at(4)->setCaption(lang->getText(31));
texts.at(4)->setSpeed(1);
// Espera un moment...
texts[5]->setCaption(lang->getText(32));
texts[5]->setSpeed(20);
texts.at(5)->setCaption(lang->getText(32));
texts.at(5)->setSpeed(20);
// Si resulta que no tinc solt!
texts[6]->setCaption(lang->getText(33));
texts[6]->setSpeed(2);
texts.at(6)->setCaption(lang->getText(33));
texts.at(6)->setSpeed(2);
// MERDA DE MAQUINA!
texts[7]->setCaption(lang->getText(34));
texts[7]->setSpeed(3);
texts.at(7)->setCaption(lang->getText(34));
texts.at(7)->setSpeed(3);
// Blop... blop... blop...
texts[8]->setCaption(lang->getText(35));
texts[8]->setSpeed(20);
texts.at(8)->setCaption(lang->getText(35));
texts.at(8)->setSpeed(20);
for (auto text : texts)
{
@@ -201,36 +201,36 @@ void Intro::updateScenes()
{
case 1:
// Primera imagen - UPV
if (!bitmaps[0]->hasFinished())
if (!bitmaps.at(0)->hasFinished())
{
bitmaps[0]->setEnabled(true);
bitmaps.at(0)->setEnabled(true);
}
// Primer texto de la primera imagen
if (bitmaps[0]->hasFinished() && !texts[0]->hasFinished())
if (bitmaps.at(0)->hasFinished() && !texts.at(0)->hasFinished())
{
texts[0]->setEnabled(true);
texts.at(0)->setEnabled(true);
}
// Segundo texto de la primera imagen
if (texts[0]->hasFinished() && !texts[1]->hasFinished())
if (texts.at(0)->hasFinished() && !texts.at(1)->hasFinished())
{
texts[0]->setEnabled(false);
texts[1]->setEnabled(true);
texts.at(0)->setEnabled(false);
texts.at(1)->setEnabled(true);
}
// Tercer texto de la primera imagen
if (texts[1]->hasFinished() && !texts[2]->hasFinished())
if (texts.at(1)->hasFinished() && !texts.at(2)->hasFinished())
{
texts[1]->setEnabled(false);
texts[2]->setEnabled(true);
texts.at(1)->setEnabled(false);
texts.at(2)->setEnabled(true);
}
// Fin de la primera escena
if (texts[2]->hasFinished())
if (texts.at(2)->hasFinished())
{
bitmaps[0]->setEnabled(false);
texts[2]->setEnabled(false);
bitmaps.at(0)->setEnabled(false);
texts.at(2)->setEnabled(false);
scene++;
}
@@ -238,22 +238,22 @@ void Intro::updateScenes()
case 2:
// Segunda imagen - Máquina
if (!bitmaps[1]->hasFinished())
if (!bitmaps.at(1)->hasFinished())
{
bitmaps[1]->setEnabled(true);
bitmaps.at(1)->setEnabled(true);
}
// Primer texto de la segunda imagen
if (bitmaps[1]->hasFinished() && !texts[3]->hasFinished())
if (bitmaps.at(1)->hasFinished() && !texts.at(3)->hasFinished())
{
texts[3]->setEnabled(true);
texts.at(3)->setEnabled(true);
}
// Fin de la segunda escena
if (texts[3]->hasFinished())
if (texts.at(3)->hasFinished())
{
bitmaps[1]->setEnabled(false);
texts[3]->setEnabled(false);
bitmaps.at(1)->setEnabled(false);
texts.at(3)->setEnabled(false);
scene++;
}
@@ -261,17 +261,17 @@ void Intro::updateScenes()
case 3:
// Tercera imagen junto con primer texto - GRITO
if (!bitmaps[2]->hasFinished() && !texts[4]->hasFinished())
if (!bitmaps.at(2)->hasFinished() && !texts.at(4)->hasFinished())
{
bitmaps[2]->setEnabled(true);
texts[4]->setEnabled(true);
bitmaps.at(2)->setEnabled(true);
texts.at(4)->setEnabled(true);
}
// Fin de la tercera escena
if (bitmaps[2]->hasFinished() && texts[4]->hasFinished())
if (bitmaps.at(2)->hasFinished() && texts.at(4)->hasFinished())
{
bitmaps[2]->setEnabled(false);
texts[4]->setEnabled(false);
bitmaps.at(2)->setEnabled(false);
texts.at(4)->setEnabled(false);
scene++;
}
@@ -279,24 +279,24 @@ void Intro::updateScenes()
case 4:
// Cuarta imagen junto con primer texto - Reflexión
if (!bitmaps[3]->hasFinished() && !texts[5]->hasFinished())
if (!bitmaps.at(3)->hasFinished() && !texts.at(5)->hasFinished())
{
bitmaps[3]->setEnabled(true);
texts[5]->setEnabled(true);
bitmaps.at(3)->setEnabled(true);
texts.at(5)->setEnabled(true);
}
// Segundo texto de la cuarta imagen
if (texts[5]->hasFinished() && !texts[6]->hasFinished())
if (texts.at(5)->hasFinished() && !texts.at(6)->hasFinished())
{
texts[5]->setEnabled(false);
texts[6]->setEnabled(true);
texts.at(5)->setEnabled(false);
texts.at(6)->setEnabled(true);
}
// Fin de la cuarta escena
if (bitmaps[3]->hasFinished() && texts[6]->hasFinished())
if (bitmaps.at(3)->hasFinished() && texts.at(6)->hasFinished())
{
bitmaps[3]->setEnabled(false);
texts[6]->setEnabled(false);
bitmaps.at(3)->setEnabled(false);
texts.at(6)->setEnabled(false);
scene++;
}
@@ -304,22 +304,22 @@ void Intro::updateScenes()
case 5:
// Quinta imagen - Patada
if (!bitmaps[4]->hasFinished())
if (!bitmaps.at(4)->hasFinished())
{
bitmaps[4]->setEnabled(true);
bitmaps.at(4)->setEnabled(true);
}
// Primer texto de la quinta imagen
if (bitmaps[4]->hasFinished() && !texts[7]->hasFinished())
if (bitmaps.at(4)->hasFinished() && !texts.at(7)->hasFinished())
{
texts[7]->setEnabled(true);
texts.at(7)->setEnabled(true);
}
// Fin de la quinta escena
if (bitmaps[4]->hasFinished() && texts[7]->hasFinished())
if (bitmaps.at(4)->hasFinished() && texts.at(7)->hasFinished())
{
bitmaps[4]->setEnabled(false);
texts[7]->setEnabled(false);
bitmaps.at(4)->setEnabled(false);
texts.at(7)->setEnabled(false);
scene++;
}
@@ -327,17 +327,17 @@ void Intro::updateScenes()
case 6:
// Sexta imagen junto con texto - Globos de café
if (!bitmaps[5]->hasFinished() && !texts[8]->hasFinished())
if (!bitmaps.at(5)->hasFinished() && !texts.at(8)->hasFinished())
{
bitmaps[5]->setEnabled(true);
texts[8]->setEnabled(true);
bitmaps.at(5)->setEnabled(true);
texts.at(8)->setEnabled(true);
}
// Acaba el último texto
if (bitmaps[5]->hasFinished() && texts[8]->hasFinished())
if (bitmaps.at(5)->hasFinished() && texts.at(8)->hasFinished())
{
bitmaps[5]->setEnabled(false);
texts[8]->setEnabled(false);
bitmaps.at(5)->setEnabled(false);
texts.at(8)->setEnabled(false);
JA_StopMusic();
section.name = PROG_SECTION_TITLE;
section.subsection = TITLE_SECTION_1;

View File

@@ -739,12 +739,12 @@ void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool gre
{
item_t temp;
if (item.size() == 0)
if (item.empty())
{// Si es el primer item coge la posición en el eje Y del propio menu
temp.rect.y = y;
}
else
{// En caso contrario, coge la posición en el eje Y a partir del elemento anterior
{// En caso contrario, coge la posición en el eje Y a partir del último elemento
temp.rect.y = item.back().rect.y + item.back().rect.h + item.back().hPaddingDown;
}
@@ -758,11 +758,11 @@ void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool gre
setItemCaption(item.size() - 1, text);
if (item.size() > 0)
if (item.size() > 1)
{
if (item[item.size() - 1].linkedDown)
if (item.at(item.size() - 2).linkedDown)
{
item[item.size()].linkedUp = true;
item.back().linkedUp = true;
}
}
@@ -773,13 +773,13 @@ void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool gre
// Cambia el texto de un item
void Menu::setItemCaption(int index, std::string text)
{
item[index].label = text;
item[index].rect.w = this->text->lenght(item[index].label);
item[index].rect.h = this->text->getCharacterSize();
item.at(index).label = text;
item.at(index).rect.w = this->text->lenght(item.at(index).label);
item.at(index).rect.h = this->text->getCharacterSize();
reorganize();
const std::string texto = item[index].label + ":" + std::to_string(item[index].rect.w);
printf("Adding menu item -> %s\n", texto.c_str());
const std::string t = item.at(index).label + ":" + std::to_string(item.at(index).rect.w);
printf("Adding menu item -> %s\n", t.c_str());
}
// Establece el indice del itemm que se usará por defecto al cancelar el menu

View File

@@ -344,7 +344,7 @@ void Screen::renderSpectrumFade()
const float step = (float)spectrumFadeCounter / (float)spectrumFadeLenght;
const int max = spectrumColor.size() - 1;
const int index = max + (0 - max) * step;
const color_t c = spectrumColor[index];
const color_t c = spectrumColor.at(index);
SDL_SetTextureColorMod(gameCanvas, c.r, c.g, c.b);
}

View File

@@ -29,7 +29,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), mRenderer);
mText2 = new Text(mAsset->get("8bithud.png"), mAsset->get("8bithud.txt"), mRenderer);
//mMenu.title = new Menu(mRenderer, mAsset, mInput, mAsset->get("title.men"));
mMenu.title = new Menu(mRenderer, mAsset, mInput, mAsset->get("title.men"));
mMenu.options = new Menu(mRenderer, mAsset, mInput, mAsset->get("options.men"));
// Sonidos