Revisada la carrega de recursos en game.cpp
This commit is contained in:
175
source/game.cpp
175
source/game.cpp
@@ -304,15 +304,18 @@ void Game::loadMedia()
|
||||
|
||||
// Limpia
|
||||
{
|
||||
player_animations_.clear();
|
||||
balloon_animations_.clear();
|
||||
item_animations_.clear();
|
||||
player1_textures_.clear();
|
||||
player2_textures_.clear();
|
||||
item_textures_.clear();
|
||||
// Texturas
|
||||
game_text_textures_.clear();
|
||||
balloon_textures_.clear();
|
||||
explosions_textures_.clear();
|
||||
game_text_textures_.clear();
|
||||
item_textures_.clear();
|
||||
player_textures_.clear();
|
||||
|
||||
// Animaciones
|
||||
player_animations_.clear();
|
||||
balloon_animations_.clear();
|
||||
explosions_animations_.clear();
|
||||
item_animations_.clear();
|
||||
}
|
||||
|
||||
// Texturas
|
||||
@@ -358,109 +361,64 @@ void Game::loadMedia()
|
||||
|
||||
// Texturas - Player1
|
||||
{
|
||||
player1_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("player1.gif")));
|
||||
player1_textures_.back()->addPalette(asset_->get("player1_pal1.gif"));
|
||||
player1_textures_.back()->addPalette(asset_->get("player1_pal2.gif"));
|
||||
player1_textures_.back()->addPalette(asset_->get("player1_pal3.gif"));
|
||||
std::vector<std::shared_ptr<Texture>> player_texture;
|
||||
player_texture.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("player1.gif")));
|
||||
player_texture.back()->addPalette(asset_->get("player1_pal1.gif"));
|
||||
player_texture.back()->addPalette(asset_->get("player1_pal2.gif"));
|
||||
player_texture.back()->addPalette(asset_->get("player1_pal3.gif"));
|
||||
|
||||
player1_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("player_power.gif")));
|
||||
player1_textures_.back()->addPalette(asset_->get("player_power_pal.gif"));
|
||||
player_texture.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("player_power.gif")));
|
||||
player_texture.back()->addPalette(asset_->get("player_power_pal.gif"));
|
||||
|
||||
player_textures_.push_back(player1_textures_);
|
||||
player_textures_.push_back(player_texture);
|
||||
}
|
||||
|
||||
// Texturas - Player2
|
||||
{
|
||||
player2_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("player2.gif")));
|
||||
player2_textures_.back()->addPalette(asset_->get("player2_pal1.gif"));
|
||||
player2_textures_.back()->addPalette(asset_->get("player2_pal2.gif"));
|
||||
player2_textures_.back()->addPalette(asset_->get("player2_pal3.gif"));
|
||||
std::vector<std::shared_ptr<Texture>> player_texture;
|
||||
player_texture.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("player2.gif")));
|
||||
player_texture.back()->addPalette(asset_->get("player2_pal1.gif"));
|
||||
player_texture.back()->addPalette(asset_->get("player2_pal2.gif"));
|
||||
player_texture.back()->addPalette(asset_->get("player2_pal3.gif"));
|
||||
|
||||
player2_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("player_power.gif")));
|
||||
player2_textures_.back()->addPalette(asset_->get("player_power_pal.gif"));
|
||||
player2_textures_.back()->setPalette(1);
|
||||
player_texture.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("player_power.gif")));
|
||||
player_texture.back()->addPalette(asset_->get("player_power_pal.gif"));
|
||||
player_texture.back()->setPalette(1);
|
||||
|
||||
player_textures_.push_back(player2_textures_);
|
||||
player_textures_.push_back(player_texture);
|
||||
}
|
||||
|
||||
// Animaciones -- Jugador
|
||||
{
|
||||
std::vector<std::string> *player_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("player.ani"), player_animations);
|
||||
player_animations_.push_back(player_animations);
|
||||
|
||||
std::vector<std::string> *player_power_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("player_power.ani"), player_power_animations);
|
||||
player_animations_.push_back(player_power_animations);
|
||||
player_animations_.emplace_back(loadAnimations(asset_->get("player.ani")));
|
||||
player_animations_.emplace_back(loadAnimations(asset_->get("player_power.ani")));
|
||||
}
|
||||
|
||||
// Animaciones -- Globos
|
||||
{
|
||||
std::vector<std::string> *balloon1_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("balloon1.ani"), balloon1_animations);
|
||||
balloon_animations_.push_back(balloon1_animations);
|
||||
|
||||
std::vector<std::string> *balloon2_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("balloon2.ani"), balloon2_animations);
|
||||
balloon_animations_.push_back(balloon2_animations);
|
||||
|
||||
std::vector<std::string> *balloon3_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("balloon3.ani"), balloon3_animations);
|
||||
balloon_animations_.push_back(balloon3_animations);
|
||||
|
||||
std::vector<std::string> *balloon4_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("balloon4.ani"), balloon4_animations);
|
||||
balloon_animations_.push_back(balloon4_animations);
|
||||
|
||||
std::vector<std::string> *balloon5_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("powerball.ani"), balloon5_animations);
|
||||
balloon_animations_.push_back(balloon5_animations);
|
||||
balloon_animations_.emplace_back(loadAnimations(asset_->get("balloon1.ani")));
|
||||
balloon_animations_.emplace_back(loadAnimations(asset_->get("balloon2.ani")));
|
||||
balloon_animations_.emplace_back(loadAnimations(asset_->get("balloon3.ani")));
|
||||
balloon_animations_.emplace_back(loadAnimations(asset_->get("balloon4.ani")));
|
||||
balloon_animations_.emplace_back(loadAnimations(asset_->get("powerball.ani")));
|
||||
}
|
||||
|
||||
// Animaciones -- Explosiones
|
||||
{
|
||||
std::vector<std::string> *explosions1_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("explosion1.ani"), explosions1_animations);
|
||||
explosions_animations_.push_back(explosions1_animations);
|
||||
|
||||
std::vector<std::string> *explosions2_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("explosion2.ani"), explosions2_animations);
|
||||
explosions_animations_.push_back(explosions2_animations);
|
||||
|
||||
std::vector<std::string> *explosions3_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("explosion3.ani"), explosions3_animations);
|
||||
explosions_animations_.push_back(explosions3_animations);
|
||||
|
||||
std::vector<std::string> *explosions4_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("explosion4.ani"), explosions4_animations);
|
||||
explosions_animations_.push_back(explosions4_animations);
|
||||
explosions_animations_.emplace_back(loadAnimations(asset_->get("explosion1.ani")));
|
||||
explosions_animations_.emplace_back(loadAnimations(asset_->get("explosion2.ani")));
|
||||
explosions_animations_.emplace_back(loadAnimations(asset_->get("explosion3.ani")));
|
||||
explosions_animations_.emplace_back(loadAnimations(asset_->get("explosion4.ani")));
|
||||
}
|
||||
|
||||
// Animaciones -- Items
|
||||
{
|
||||
std::vector<std::string> *item1_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("item_points1_disk.ani"), item1_animations);
|
||||
item_animations_.push_back(item1_animations);
|
||||
|
||||
std::vector<std::string> *item2_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("item_points2_gavina.ani"), item2_animations);
|
||||
item_animations_.push_back(item2_animations);
|
||||
|
||||
std::vector<std::string> *item3_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("item_points3_pacmar.ani"), item3_animations);
|
||||
item_animations_.push_back(item3_animations);
|
||||
|
||||
std::vector<std::string> *item4_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("item_clock.ani"), item4_animations);
|
||||
item_animations_.push_back(item4_animations);
|
||||
|
||||
std::vector<std::string> *item5_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("item_coffee.ani"), item5_animations);
|
||||
item_animations_.push_back(item5_animations);
|
||||
|
||||
std::vector<std::string> *item6_animations = new std::vector<std::string>;
|
||||
loadAnimations(asset_->get("item_coffee_machine.ani"), item6_animations);
|
||||
item_animations_.push_back(item6_animations);
|
||||
item_animations_.emplace_back(loadAnimations(asset_->get("item_points1_disk.ani")));
|
||||
item_animations_.emplace_back(loadAnimations(asset_->get("item_points2_gavina.ani")));
|
||||
item_animations_.emplace_back(loadAnimations(asset_->get("item_points3_pacmar.ani")));
|
||||
item_animations_.emplace_back(loadAnimations(asset_->get("item_clock.ani")));
|
||||
item_animations_.emplace_back(loadAnimations(asset_->get("item_coffee.ani")));
|
||||
item_animations_.emplace_back(loadAnimations(asset_->get("item_coffee_machine.ani")));
|
||||
}
|
||||
|
||||
// Texto
|
||||
@@ -498,11 +456,11 @@ void Game::loadMedia()
|
||||
void Game::unloadMedia()
|
||||
{
|
||||
// Texturas
|
||||
player1_textures_.clear();
|
||||
player2_textures_.clear();
|
||||
item_textures_.clear();
|
||||
game_text_textures_.clear();
|
||||
balloon_textures_.clear();
|
||||
explosions_textures_.clear();
|
||||
item_textures_.clear();
|
||||
player_textures_.clear();
|
||||
|
||||
// Animaciones
|
||||
player_animations_.clear();
|
||||
@@ -2158,21 +2116,24 @@ void Game::checkEvents()
|
||||
}
|
||||
|
||||
// Carga las animaciones
|
||||
void Game::loadAnimations(std::string filePath, std::vector<std::string> *buffer)
|
||||
std::vector<std::string> Game::loadAnimations(const std::string &file_path)
|
||||
{
|
||||
std::ifstream file(filePath);
|
||||
std::string line;
|
||||
|
||||
if (file)
|
||||
std::vector<std::string> buffer;
|
||||
std::ifstream file(file_path);
|
||||
if (!file)
|
||||
{
|
||||
|
||||
std::cout << "Animation loaded: " << filePath.substr(filePath.find_last_of("\\/") + 1).c_str() << std::endl;
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
buffer->push_back(line);
|
||||
}
|
||||
file.close();
|
||||
std::cerr << "Error: no se pudo abrir el archivo " << file_path << std::endl;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::string line;
|
||||
std::cout << "Animation loaded: " << file_path.substr(file_path.find_last_of("\\/") + 1) << std::endl;
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
buffer.push_back(line);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// Elimina todos los objetos contenidos en vectores
|
||||
@@ -2198,14 +2159,12 @@ void Game::reloadTextures()
|
||||
texture->reLoad();
|
||||
}
|
||||
|
||||
for (auto &texture : player1_textures_)
|
||||
for (auto &textures : player_textures_)
|
||||
{
|
||||
texture->reLoad();
|
||||
}
|
||||
|
||||
for (auto &texture : player2_textures_)
|
||||
{
|
||||
texture->reLoad();
|
||||
for (auto &texture : textures)
|
||||
{
|
||||
texture->reLoad();
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &texture : game_text_textures_)
|
||||
|
||||
Reference in New Issue
Block a user