diff --git a/source/enemy.cpp b/source/enemy.cpp index ce17644..c7c8008 100644 --- a/source/enemy.cpp +++ b/source/enemy.cpp @@ -11,7 +11,7 @@ Enemy::Enemy(enemy_t enemy) // Crea objetos texture = new LTexture(); - loadTextureFromFile(texture, asset->get(enemy.tileset), renderer); + texture->loadFromFile(asset->get(enemy.tileset), renderer); sprite = new AnimatedSprite(texture, renderer, asset->get(enemy.animation)); // Obten el resto de valores diff --git a/source/item.cpp b/source/item.cpp index 7e94ed1..49da371 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -11,11 +11,9 @@ Item::Item(item_t item) // Crea objetos texture = new LTexture(); + texture->loadFromFile(asset->get(item.tileset), renderer); sprite = new Sprite(item.x, item.y, 8, 8, texture, renderer); - // Carga la textura - loadTextureFromFile(texture, asset->get(item.tileset), renderer); - // Inicia variables sprite->setSpriteClip(item.tile * 8, 0, 8, 8); collider = sprite->getRect(); diff --git a/source/ltexture.cpp b/source/ltexture.cpp index 8225882..16f2c16 100644 --- a/source/ltexture.cpp +++ b/source/ltexture.cpp @@ -50,7 +50,6 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer) SDL_Texture *newTexture = NULL; // Load image at specified path - //SDL_Surface *loadedSurface = IMG_Load(path.c_str()); SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format); if (loadedSurface == NULL) { @@ -58,9 +57,6 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer) } else { - // Color key image - //SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, COLOR_KEY_R, COLOR_KEY_G, COLOR_KEY_B)); - // Create texture from surface pixels newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface); if (newTexture == NULL) diff --git a/source/player.cpp b/source/player.cpp index a2d13e5..82fffdb 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -14,7 +14,7 @@ Player::Player(player_t ini, std::string tileset, std::string animation, SDL_Ren // Crea objetos texture = new LTexture(); - loadTextureFromFile(texture, asset->get(tileset), renderer); + texture->loadFromFile(asset->get(tileset), renderer); sprite = new AnimatedSprite(texture, renderer, animation); // Inicializa variables @@ -289,4 +289,10 @@ player_t Player::getSpawnParams() params.flip = sprite->getFlip(); return params; +} + +// Recarga la textura +void Player::reLoadTexture() +{ + //texture->loadFromFile(asset->get(tileset), renderer); } \ No newline at end of file diff --git a/source/player.h b/source/player.h index 5eb577d..d17468d 100644 --- a/source/player.h +++ b/source/player.h @@ -115,6 +115,9 @@ public: // Obtiene el rectangulo de colision del jugador SDL_Rect &getCollider(); + // Recarga la textura + void reLoadTexture(); + // Deshace el ultimo movimiento void undoLastMove(); diff --git a/source/room.cpp b/source/room.cpp index 050c14c..ebe9a5e 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -15,7 +15,7 @@ Room::Room(std::string file_path, SDL_Renderer *renderer, Asset *asset, ItemTrac // Crea los objetos texture = new LTexture(); load(file_path); - loadTextureFromFile(texture, asset->get(tileset), renderer); + texture->loadFromFile(asset->get(tileset), renderer); itemSound = JA_LoadSound(asset->get("item.wav").c_str()); // Crea la textura para el mapa de tiles de la habitación diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index 9a248b0..5c672ac 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -14,7 +14,7 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, int *lives, int *it // Reserva memoria para los objetos texture = new LTexture(); - loadTextureFromFile(texture, asset->get("player01.png"), renderer); + texture->loadFromFile(asset->get("player01.png"), renderer); sprite = new AnimatedSprite(texture, renderer, asset->get("player01.ani")); sprite->setCurrentAnimation("walk_menu"); text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer); diff --git a/source/text.cpp b/source/text.cpp index e4bf037..79419aa 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -7,7 +7,7 @@ Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer) { texture = new LTexture(); - loadTextureFromFile(texture, bitmapFile, renderer); + texture->loadFromFile(bitmapFile, renderer); mSprite = new Sprite({0, 0, 0, 0}, texture, renderer); mSprite->setTexture(texture); diff --git a/source/utils.cpp b/source/utils.cpp index 36b15cb..dbf35d3 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -140,18 +140,6 @@ bool checkCollision(SDL_Point &p, SDL_Rect &r) return true; } -// Carga un archivo de imagen en una textura -bool loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *renderer) -{ - bool success = true; - if (!texture->loadFromFile(path, renderer)) - { - printf("Failed to load %s texture!\n", path.c_str()); - success = false; - } - return success; -} - // Devuelve un color_t a partir de un string color_t stringToColor(std::string str) { diff --git a/source/utils.h b/source/utils.h index 97580dc..e868235 100644 --- a/source/utils.h +++ b/source/utils.h @@ -77,9 +77,6 @@ bool checkCollision(SDL_Rect &a, SDL_Rect &b); // Detector de colisiones entre un punto y u rectangulo bool checkCollision(SDL_Point &p, SDL_Rect &r); -// Carga un archivo de imagen en una textura -bool loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *renderer); - // Devuelve un color_t a partir de un string color_t stringToColor(std::string str);