Completado el logo y la intro

This commit is contained in:
2022-08-22 23:25:12 +02:00
parent f1e3cfe892
commit 6b4926efb8
16 changed files with 291 additions and 555 deletions

View File

@@ -10,6 +10,9 @@ AnimatedSprite::AnimatedSprite(LTexture *texture, SDL_Renderer *renderer, std::s
// Carga las animaciones
load(file);
// Inicializa variables
currentAnimation = 0;
}
// Destructor
@@ -51,6 +54,7 @@ void AnimatedSprite::animate()
if (animation[currentAnimation].loop == -1)
{ // Si no hay loop, deja el último frame
animation[currentAnimation].currentFrame = animation[currentAnimation].frames.size();
animation[currentAnimation].completed = true;
}
else
{ // Si hay loop, vuelve al frame indicado
@@ -101,9 +105,9 @@ void AnimatedSprite::setAnimationCompleted(std::string name, bool value)
}
// Comprueba si ha terminado la animación
bool AnimatedSprite::animationIsCompleted(std::string name)
bool AnimatedSprite::animationIsCompleted()
{
return animation[getIndex(name)].completed;
return animation[currentAnimation].completed;
}
// Devuelve el rectangulo de una animación y frame concreto
@@ -115,9 +119,10 @@ SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index)
// Carga la animación desde un fichero
bool AnimatedSprite::load(std::string filePath)
{
int png_width_in_tiles = 0;
int tile_width = 0;
int tile_height = 0;
int frames_per_row = 0;
int frame_width = 0;
int frame_height = 0;
// Indicador de éxito en la carga
bool success = true;
@@ -167,12 +172,12 @@ 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, tile_width, tile_height};
SDL_Rect rect = {0, 0, frame_width, frame_height};
while (getline(ss, tmp, ','))
{
int num_tile = std::stoi(tmp);
rect.x = (num_tile % png_width_in_tiles) * tile_width;
rect.y = (num_tile / png_width_in_tiles) * tile_height;
rect.x = (num_tile % frames_per_row) * frame_width;
rect.y = (num_tile / frames_per_row) * frame_height;
buffer.frames.push_back(rect);
}
}
@@ -197,17 +202,17 @@ bool AnimatedSprite::load(std::string filePath)
// Procesa las dos subcadenas
if (pos != line.npos)
{
if (line.substr(0, pos) == "png_width_in_tiles")
if (line.substr(0, pos) == "frames_per_row")
{
png_width_in_tiles = std::stoi(line.substr(pos + 1, line.length()));
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
}
else if (line.substr(0, pos) == "tile_width")
else if (line.substr(0, pos) == "frame_width")
{
tile_width = std::stoi(line.substr(pos + 1, line.length()));
frame_width = std::stoi(line.substr(pos + 1, line.length()));
}
else if (line.substr(0, pos) == "tile_height")
else if (line.substr(0, pos) == "frame_height")
{
tile_height = std::stoi(line.substr(pos + 1, line.length()));
frame_height = std::stoi(line.substr(pos + 1, line.length()));
}
else
{
@@ -229,6 +234,9 @@ bool AnimatedSprite::load(std::string filePath)
success = false;
}
// Pone un valor por defecto
setPos({0, 0, frame_width, frame_height});
return success;
}