using namespace std en todos los ficheros
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "animatedsprite.h"
|
||||
|
||||
// Carga la animación desde un fichero
|
||||
animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose)
|
||||
animatedSprite_t loadAnimationFromFile(Texture *texture, string filePath, bool verbose)
|
||||
{
|
||||
// Inicializa variables
|
||||
animatedSprite_t as;
|
||||
@@ -11,9 +11,9 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
||||
int frameHeight = 0;
|
||||
int maxTiles = 0;
|
||||
|
||||
const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
|
||||
std::ifstream file(filePath);
|
||||
std::string line;
|
||||
const string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
|
||||
ifstream file(filePath);
|
||||
string line;
|
||||
|
||||
// El fichero se puede abrir
|
||||
if (file.good())
|
||||
@@ -21,9 +21,9 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
||||
// Procesa el fichero linea a linea
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Animation loaded: " << filename << std::endl;
|
||||
cout << "Animation loaded: " << filename << endl;
|
||||
}
|
||||
while (std::getline(file, line))
|
||||
while (getline(file, line))
|
||||
{
|
||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||
if (line == "[animation]")
|
||||
@@ -35,7 +35,7 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
||||
|
||||
do
|
||||
{
|
||||
std::getline(file, line);
|
||||
getline(file, line);
|
||||
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
@@ -50,24 +50,24 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
||||
|
||||
else if (line.substr(0, pos) == "speed")
|
||||
{
|
||||
buffer.speed = std::stoi(line.substr(pos + 1, line.length()));
|
||||
buffer.speed = stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "loop")
|
||||
{
|
||||
buffer.loop = std::stoi(line.substr(pos + 1, line.length()));
|
||||
buffer.loop = stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frames")
|
||||
{
|
||||
// Se introducen los valores separados por comas en un vector
|
||||
std::stringstream ss(line.substr(pos + 1, line.length()));
|
||||
std::string tmp;
|
||||
stringstream ss(line.substr(pos + 1, line.length()));
|
||||
string tmp;
|
||||
SDL_Rect rect = {0, 0, frameWidth, frameHeight};
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||
const int numTile = std::stoi(tmp) > maxTiles ? 0 : std::stoi(tmp);
|
||||
const int numTile = stoi(tmp) > maxTiles ? 0 : stoi(tmp);
|
||||
rect.x = (numTile % framesPerRow) * frameWidth;
|
||||
rect.y = (numTile / framesPerRow) * frameHeight;
|
||||
buffer.frames.push_back(rect);
|
||||
@@ -76,7 +76,7 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
||||
|
||||
else
|
||||
{
|
||||
std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << endl;
|
||||
}
|
||||
}
|
||||
} while (line != "[/animation]");
|
||||
@@ -96,22 +96,22 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
||||
{
|
||||
if (line.substr(0, pos) == "framesPerRow")
|
||||
{
|
||||
framesPerRow = std::stoi(line.substr(pos + 1, line.length()));
|
||||
framesPerRow = stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frameWidth")
|
||||
{
|
||||
frameWidth = std::stoi(line.substr(pos + 1, line.length()));
|
||||
frameWidth = stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frameHeight")
|
||||
{
|
||||
frameHeight = std::stoi(line.substr(pos + 1, line.length()));
|
||||
frameHeight = stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << endl;
|
||||
}
|
||||
|
||||
// Normaliza valores
|
||||
@@ -138,7 +138,7 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl;
|
||||
cout << "Warning: Unable to open " << filename.c_str() << " file" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,9 +146,9 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
||||
}
|
||||
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::string file, std::vector<std::string> *buffer)
|
||||
AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, string file, vector<string> *buffer)
|
||||
{
|
||||
//std::cout << "Creado AnimatedSprite" << std::endl;
|
||||
//cout << "Creado AnimatedSprite" << endl;
|
||||
// Copia los punteros
|
||||
setTexture(texture);
|
||||
setRenderer(renderer);
|
||||
@@ -177,7 +177,7 @@ AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::st
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation)
|
||||
{
|
||||
//std::cout << "Creado AnimatedSprite" << std::endl;
|
||||
//cout << "Creado AnimatedSprite" << endl;
|
||||
// Copia los punteros
|
||||
setTexture(animation->texture);
|
||||
setRenderer(renderer);
|
||||
@@ -195,7 +195,7 @@ AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animati
|
||||
// Destructor
|
||||
AnimatedSprite::~AnimatedSprite()
|
||||
{
|
||||
//std::cout << "Destruido AnimatedSprite" << std::endl;
|
||||
//cout << "Destruido AnimatedSprite" << endl;
|
||||
for (auto &a : animation)
|
||||
{
|
||||
a.frames.clear();
|
||||
@@ -204,7 +204,7 @@ AnimatedSprite::~AnimatedSprite()
|
||||
}
|
||||
|
||||
// Obtiene el indice de la animación a partir del nombre
|
||||
int AnimatedSprite::getIndex(std::string name)
|
||||
int AnimatedSprite::getIndex(string name)
|
||||
{
|
||||
int index = -1;
|
||||
|
||||
@@ -217,7 +217,7 @@ int AnimatedSprite::getIndex(std::string name)
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << std::endl;
|
||||
cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << endl;
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -283,13 +283,13 @@ void AnimatedSprite::setCurrentFrame(int num)
|
||||
}
|
||||
|
||||
// Establece el valor del contador
|
||||
void AnimatedSprite::setAnimationCounter(std::string name, int num)
|
||||
void AnimatedSprite::setAnimationCounter(string name, int num)
|
||||
{
|
||||
animation[getIndex(name)].counter = num;
|
||||
}
|
||||
|
||||
// Establece la velocidad de una animación
|
||||
void AnimatedSprite::setAnimationSpeed(std::string name, int speed)
|
||||
void AnimatedSprite::setAnimationSpeed(string name, int speed)
|
||||
{
|
||||
animation[getIndex(name)].counter = speed;
|
||||
}
|
||||
@@ -301,7 +301,7 @@ void AnimatedSprite::setAnimationSpeed(int index, int speed)
|
||||
}
|
||||
|
||||
// Establece si la animación se reproduce en bucle
|
||||
void AnimatedSprite::setAnimationLoop(std::string name, int loop)
|
||||
void AnimatedSprite::setAnimationLoop(string name, int loop)
|
||||
{
|
||||
animation[getIndex(name)].loop = loop;
|
||||
}
|
||||
@@ -313,7 +313,7 @@ void AnimatedSprite::setAnimationLoop(int index, int loop)
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void AnimatedSprite::setAnimationCompleted(std::string name, bool value)
|
||||
void AnimatedSprite::setAnimationCompleted(string name, bool value)
|
||||
{
|
||||
animation[getIndex(name)].completed = value;
|
||||
}
|
||||
@@ -331,7 +331,7 @@ bool AnimatedSprite::animationIsCompleted()
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo de una animación y frame concreto
|
||||
SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index)
|
||||
SDL_Rect AnimatedSprite::getAnimationClip(string name, Uint8 index)
|
||||
{
|
||||
return animation[getIndex(name)].frames[index];
|
||||
}
|
||||
@@ -343,7 +343,7 @@ SDL_Rect AnimatedSprite::getAnimationClip(int indexA, Uint8 indexF)
|
||||
}
|
||||
|
||||
// Carga la animación desde un vector
|
||||
bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
||||
bool AnimatedSprite::loadFromVector(vector<string> *source)
|
||||
{
|
||||
// Inicializa variables
|
||||
int framesPerRow = 0;
|
||||
@@ -353,7 +353,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
||||
|
||||
// Indicador de éxito en el proceso
|
||||
bool success = true;
|
||||
std::string line;
|
||||
string line;
|
||||
|
||||
// Recorre todo el vector
|
||||
int index = 0;
|
||||
@@ -389,24 +389,24 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
||||
|
||||
else if (line.substr(0, pos) == "speed")
|
||||
{
|
||||
buffer.speed = std::stoi(line.substr(pos + 1, line.length()));
|
||||
buffer.speed = stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "loop")
|
||||
{
|
||||
buffer.loop = std::stoi(line.substr(pos + 1, line.length()));
|
||||
buffer.loop = stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frames")
|
||||
{
|
||||
// Se introducen los valores separados por comas en un vector
|
||||
std::stringstream ss(line.substr(pos + 1, line.length()));
|
||||
std::string tmp;
|
||||
stringstream ss(line.substr(pos + 1, line.length()));
|
||||
string tmp;
|
||||
SDL_Rect rect = {0, 0, frameWidth, frameHeight};
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||
const int numTile = std::stoi(tmp) > maxTiles ? 0 : std::stoi(tmp);
|
||||
const int numTile = stoi(tmp) > maxTiles ? 0 : stoi(tmp);
|
||||
rect.x = (numTile % framesPerRow) * frameWidth;
|
||||
rect.y = (numTile / framesPerRow) * frameHeight;
|
||||
buffer.frames.push_back(rect);
|
||||
@@ -415,7 +415,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
||||
|
||||
else
|
||||
{
|
||||
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||
cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << endl;
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
@@ -436,22 +436,22 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
||||
{
|
||||
if (line.substr(0, pos) == "framesPerRow")
|
||||
{
|
||||
framesPerRow = std::stoi(line.substr(pos + 1, line.length()));
|
||||
framesPerRow = stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frameWidth")
|
||||
{
|
||||
frameWidth = std::stoi(line.substr(pos + 1, line.length()));
|
||||
frameWidth = stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frameHeight")
|
||||
{
|
||||
frameHeight = std::stoi(line.substr(pos + 1, line.length()));
|
||||
frameHeight = stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||
cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << endl;
|
||||
success = false;
|
||||
}
|
||||
|
||||
@@ -481,7 +481,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
||||
}
|
||||
|
||||
// Establece la animacion actual
|
||||
void AnimatedSprite::setCurrentAnimation(std::string name)
|
||||
void AnimatedSprite::setCurrentAnimation(string name)
|
||||
{
|
||||
const int newAnimation = getIndex(name);
|
||||
if (currentAnimation != newAnimation)
|
||||
|
||||
Reference in New Issue
Block a user