Ya precarga todos los recursos del juego
This commit is contained in:
169
source/game.cpp
169
source/game.cpp
@@ -14,7 +14,7 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
|
||||
// Pasa variables
|
||||
this->demo.enabled = demo;
|
||||
this->numPlayers = numPlayers;
|
||||
this->currentStage = 5; // currentStage;
|
||||
this->currentStage = currentStage;
|
||||
lastStageReached = currentStage;
|
||||
if (numPlayers == 1)
|
||||
{ // Si solo juega un jugador, permite jugar tanto con teclado como con mando
|
||||
@@ -27,9 +27,9 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
|
||||
fade = new Fade(renderer);
|
||||
eventHandler = new SDL_Event();
|
||||
|
||||
std::vector<std::vector<std::string> *> *itemAnimations;
|
||||
std::vector<std::vector<std::string> *> *playerAnimations;
|
||||
std::vector<std::vector<std::string> *> *balloonAnimations;
|
||||
// std::vector<std::vector<std::string> *> *itemAnimations = new std::vector<std::vector<std::string> *>;
|
||||
// std::vector<std::vector<std::string> *> *playerAnimations = new std::vector<std::vector<std::string> *>;
|
||||
// std::vector<std::vector<std::string> *> *balloonAnimations = new std::vector<std::vector<std::string> *>;
|
||||
|
||||
// Carga los recursos
|
||||
loadMedia();
|
||||
@@ -67,18 +67,6 @@ Game::~Game()
|
||||
// Elimina todos los objetos contenidos en vectores
|
||||
deleteAllVectorObjects();
|
||||
|
||||
balloon1Texture->unload();
|
||||
delete balloon1Texture;
|
||||
|
||||
balloon2Texture->unload();
|
||||
delete balloon2Texture;
|
||||
|
||||
balloon3Texture->unload();
|
||||
delete balloon3Texture;
|
||||
|
||||
balloon4Texture->unload();
|
||||
delete balloon4Texture;
|
||||
|
||||
bulletTexture->unload();
|
||||
delete bulletTexture;
|
||||
|
||||
@@ -103,13 +91,7 @@ Game::~Game()
|
||||
itemTexture->unload();
|
||||
delete itemTexture;
|
||||
|
||||
for (auto texture : itemsTexture)
|
||||
{
|
||||
texture->unload();
|
||||
delete texture;
|
||||
}
|
||||
itemsTexture.clear();
|
||||
|
||||
// Animaciones
|
||||
for (auto animation : playerAnimations)
|
||||
{
|
||||
delete animation;
|
||||
@@ -128,19 +110,34 @@ Game::~Game()
|
||||
}
|
||||
itemAnimations.clear();
|
||||
|
||||
for (auto texture : player1Texture)
|
||||
// Texturas
|
||||
for (auto texture : player1Textures)
|
||||
{
|
||||
texture->unload();
|
||||
delete texture;
|
||||
}
|
||||
player1Texture.clear();
|
||||
player1Textures.clear();
|
||||
|
||||
for (auto texture : player2Texture)
|
||||
for (auto texture : player2Textures)
|
||||
{
|
||||
texture->unload();
|
||||
delete texture;
|
||||
}
|
||||
player2Texture.clear();
|
||||
player2Textures.clear();
|
||||
|
||||
for (auto texture : itemTextures)
|
||||
{
|
||||
texture->unload();
|
||||
delete texture;
|
||||
}
|
||||
itemTextures.clear();
|
||||
|
||||
for (auto texture : balloonTextures)
|
||||
{
|
||||
texture->unload();
|
||||
delete texture;
|
||||
}
|
||||
balloonTextures.clear();
|
||||
|
||||
delete text;
|
||||
delete textBig;
|
||||
@@ -198,14 +195,14 @@ void Game::init()
|
||||
|
||||
if (numPlayers == 1)
|
||||
{
|
||||
Player *player = new Player(renderer, asset, PLAY_AREA_CENTER_X - 11, PLAY_AREA_BOTTOM - 24);
|
||||
Player *player = new Player(PLAY_AREA_CENTER_X - 11, PLAY_AREA_BOTTOM - 24, renderer, player2Textures, playerAnimations);
|
||||
players.push_back(player);
|
||||
}
|
||||
|
||||
else if (numPlayers == 2)
|
||||
{
|
||||
Player *player1 = new Player(renderer, asset, (PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24);
|
||||
Player *player2 = new Player(renderer, asset, (PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24);
|
||||
Player *player1 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, renderer, player1Textures, playerAnimations);
|
||||
Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, renderer, player2Textures, playerAnimations);
|
||||
players.push_back(player1);
|
||||
players.push_back(player2);
|
||||
}
|
||||
@@ -372,10 +369,6 @@ void Game::loadMedia()
|
||||
loadDemoFile();
|
||||
|
||||
// Texturas
|
||||
balloon1Texture = new LTexture(renderer, asset->get("balloon1.png"));
|
||||
balloon2Texture = new LTexture(renderer, asset->get("balloon2.png"));
|
||||
balloon3Texture = new LTexture(renderer, asset->get("balloon3.png"));
|
||||
balloon4Texture = new LTexture(renderer, asset->get("balloon4.png"));
|
||||
bulletTexture = new LTexture(renderer, asset->get("bullet.png"));
|
||||
gameBuildingsTexture = new LTexture(renderer, asset->get("game_buildings.png"));
|
||||
gameCloudsTexture = new LTexture(renderer, asset->get("game_clouds.png"));
|
||||
@@ -385,47 +378,63 @@ void Game::loadMedia()
|
||||
gameTextTexture = new LTexture(renderer, asset->get("game_text.png"));
|
||||
itemTexture = new LTexture(renderer, asset->get("items.png"));
|
||||
|
||||
// Texturas - Globos
|
||||
LTexture *balloon1Texture = new LTexture(renderer, asset->get("balloon1.png"));
|
||||
balloonTextures.push_back(balloon1Texture);
|
||||
|
||||
LTexture *balloon2Texture = new LTexture(renderer, asset->get("balloon2.png"));
|
||||
balloonTextures.push_back(balloon2Texture);
|
||||
|
||||
LTexture *balloon3Texture = new LTexture(renderer, asset->get("balloon3.png"));
|
||||
balloonTextures.push_back(balloon3Texture);
|
||||
|
||||
LTexture *balloon4Texture = new LTexture(renderer, asset->get("balloon4.png"));
|
||||
balloonTextures.push_back(balloon4Texture);
|
||||
|
||||
// Texturas - Items
|
||||
LTexture *item1 = new LTexture(renderer, asset->get("item_points1_disk.png"));
|
||||
itemsTexture.push_back(item1);
|
||||
itemTextures.push_back(item1);
|
||||
|
||||
LTexture *item2 = new LTexture(renderer, asset->get("item_points2_gavina.png"));
|
||||
itemsTexture.push_back(item2);
|
||||
itemTextures.push_back(item2);
|
||||
|
||||
LTexture *item3 = new LTexture(renderer, asset->get("item_points3_pacmar.png"));
|
||||
itemsTexture.push_back(item3);
|
||||
itemTextures.push_back(item3);
|
||||
|
||||
LTexture *item4 = new LTexture(renderer, asset->get("item_clock.png"));
|
||||
itemsTexture.push_back(item4);
|
||||
itemTextures.push_back(item4);
|
||||
|
||||
LTexture *item5 = new LTexture(renderer, asset->get("item_coffee.png"));
|
||||
itemsTexture.push_back(item5);
|
||||
itemTextures.push_back(item5);
|
||||
|
||||
LTexture *item6 = new LTexture(renderer, asset->get("item_coffee_machine.png"));
|
||||
itemsTexture.push_back(item6);
|
||||
itemTextures.push_back(item6);
|
||||
|
||||
// Texturas - Player1
|
||||
LTexture *player1Head = new LTexture(renderer, asset->get("player_bal1_head.png"));
|
||||
player1Texture.push_back(player1Head);
|
||||
player1Textures.push_back(player1Head);
|
||||
|
||||
LTexture *player1Body = new LTexture(renderer, asset->get("player_bal1_body.png"));
|
||||
player1Texture.push_back(player1Body);
|
||||
player1Textures.push_back(player1Body);
|
||||
|
||||
LTexture *player1Legs = new LTexture(renderer, asset->get("player_bal1_legs.png"));
|
||||
player1Texture.push_back(player1Legs);
|
||||
player1Textures.push_back(player1Legs);
|
||||
|
||||
LTexture *player1Death = new LTexture(renderer, asset->get("player_bal1_death.png"));
|
||||
player1Texture.push_back(player1Death);
|
||||
player1Textures.push_back(player1Death);
|
||||
|
||||
// Texturas - Player2
|
||||
LTexture *player2Head = new LTexture(renderer, asset->get("player_arounder_head.png"));
|
||||
player2Texture.push_back(player2Head);
|
||||
player2Textures.push_back(player2Head);
|
||||
|
||||
LTexture *player2Body = new LTexture(renderer, asset->get("player_arounder_body.png"));
|
||||
player2Texture.push_back(player2Body);
|
||||
player2Textures.push_back(player2Body);
|
||||
|
||||
LTexture *player2Legs = new LTexture(renderer, asset->get("player_arounder_legs.png"));
|
||||
player2Texture.push_back(player2Legs);
|
||||
player2Textures.push_back(player2Legs);
|
||||
|
||||
LTexture *player2Death = new LTexture(renderer, asset->get("player_arounder_death.png"));
|
||||
player2Texture.push_back(player2Death);
|
||||
player2Textures.push_back(player2Death);
|
||||
|
||||
// Animaciones -- Jugador
|
||||
std::vector<std::string> *playerHeadAnimation = new std::vector<std::string>;
|
||||
@@ -1828,7 +1837,8 @@ void Game::renderBalloons()
|
||||
// Crea un globo nuevo en el vector de globos
|
||||
Uint8 Game::createBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 creationtimer)
|
||||
{
|
||||
Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, balloonTexture(kind), balloonStreamAnimation(kind), renderer);
|
||||
const int index = (kind - 1) % 4;
|
||||
Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, balloonTextures.at(index), balloonAnimations.at(index), renderer);
|
||||
balloons.push_back(b);
|
||||
return (Uint8)(balloons.size() - 1);
|
||||
}
|
||||
@@ -1846,7 +1856,7 @@ void Game::createPowerBall()
|
||||
const int x[3] = {left, center, right};
|
||||
const float vx[3] = {BALLOON_VELX_POSITIVE, BALLOON_VELX_POSITIVE, BALLOON_VELX_NEGATIVE};
|
||||
|
||||
Balloon *b = new Balloon(x[luck], posY, POWER_BALL, vx[luck], enemySpeed, 100, balloon4Texture, balloon4Animation, renderer);
|
||||
Balloon *b = new Balloon(x[luck], posY, POWER_BALL, vx[luck], enemySpeed, 100, balloonTextures.at(3), balloonAnimations.at(3), renderer);
|
||||
balloons.push_back(b);
|
||||
|
||||
powerBallEnabled = true;
|
||||
@@ -1857,8 +1867,6 @@ void Game::createPowerBall()
|
||||
void Game::setBalloonSpeed(float speed)
|
||||
{
|
||||
for (auto balloon : balloons)
|
||||
|
||||
// for (int i = 0; i < MAX_BALLOONS; i++)
|
||||
{
|
||||
if (balloon->isEnabled())
|
||||
{
|
||||
@@ -2130,58 +2138,6 @@ Uint8 Game::countBalloons()
|
||||
return num;
|
||||
}
|
||||
|
||||
// Obtiene la textura correspondiente en funcion del tipo
|
||||
LTexture *Game::balloonTexture(int kind)
|
||||
{
|
||||
if (kind == 1 || kind == 5)
|
||||
{
|
||||
return balloon1Texture;
|
||||
}
|
||||
|
||||
else if (kind == 2 || kind == 6)
|
||||
{
|
||||
return balloon2Texture;
|
||||
}
|
||||
|
||||
else if (kind == 3 || kind == 7)
|
||||
{
|
||||
return balloon3Texture;
|
||||
}
|
||||
|
||||
else if (kind == 4 || kind == 8 || kind == 9)
|
||||
{
|
||||
return balloon4Texture;
|
||||
}
|
||||
|
||||
return balloon1Texture;
|
||||
}
|
||||
|
||||
// Obtiene la animacion correspondiente en funcion del tipo
|
||||
std::vector<std::string> *Game::balloonStreamAnimation(int kind)
|
||||
{
|
||||
if (kind == 1 || kind == 5)
|
||||
{
|
||||
return balloon1Animation;
|
||||
}
|
||||
|
||||
else if (kind == 2 || kind == 6)
|
||||
{
|
||||
return balloon2Animation;
|
||||
}
|
||||
|
||||
else if (kind == 3 || kind == 7)
|
||||
{
|
||||
return balloon3Animation;
|
||||
}
|
||||
|
||||
else if (kind == 4 || kind == 8 || kind == 9)
|
||||
{
|
||||
return balloon4Animation;
|
||||
}
|
||||
|
||||
return balloon1Animation;
|
||||
}
|
||||
|
||||
// Vacia el vector de globos
|
||||
void Game::freeBalloons()
|
||||
{
|
||||
@@ -2489,9 +2445,10 @@ Uint8 Game::dropItem()
|
||||
}
|
||||
|
||||
// Crea un objeto item
|
||||
void Game::createItem(Uint8 type, float x, float y)
|
||||
void Game::createItem(Uint8 kind, float x, float y)
|
||||
{
|
||||
Item *item = new Item(renderer, asset, type, x, y);
|
||||
const int index = kind - 1;
|
||||
Item *item = new Item(kind, x, y, itemTextures.at(index), itemAnimations.at(index), renderer);
|
||||
items.push_back(item);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user