acabat el nou motor d'animacions
This commit is contained in:
157
source/game.cpp
157
source/game.cpp
@@ -28,6 +28,15 @@ Game::Game(int playerID, int currentStage, SDL_Renderer *renderer, Screen *scree
|
||||
scoreboard = new Scoreboard(renderer, screen, asset, lang, options);
|
||||
background = new Background(renderer, screen, asset, param);
|
||||
|
||||
// Inicializa vectores
|
||||
playerAnimations.clear();
|
||||
balloonAnimations.clear();
|
||||
itemAnimations.clear();
|
||||
player1Textures.clear();
|
||||
player2Textures.clear();
|
||||
itemTextures.clear();
|
||||
balloonTextures.clear();
|
||||
|
||||
// Carga los recursos
|
||||
loadMedia();
|
||||
|
||||
@@ -91,48 +100,69 @@ Game::~Game()
|
||||
// Animaciones
|
||||
for (auto animation : playerAnimations)
|
||||
{
|
||||
delete animation;
|
||||
if (animation)
|
||||
{
|
||||
delete animation;
|
||||
}
|
||||
}
|
||||
playerAnimations.clear();
|
||||
|
||||
for (auto animation : balloonAnimations)
|
||||
{
|
||||
delete animation;
|
||||
if (animation)
|
||||
{
|
||||
delete animation;
|
||||
}
|
||||
}
|
||||
balloonAnimations.clear();
|
||||
|
||||
for (auto animation : itemAnimations)
|
||||
{
|
||||
delete animation;
|
||||
if (animation)
|
||||
{
|
||||
delete animation;
|
||||
}
|
||||
}
|
||||
itemAnimations.clear();
|
||||
|
||||
// Texturas
|
||||
for (auto texture : player1Textures)
|
||||
{
|
||||
texture->unload();
|
||||
delete texture;
|
||||
if (texture)
|
||||
{
|
||||
texture->unload();
|
||||
delete texture;
|
||||
}
|
||||
}
|
||||
player1Textures.clear();
|
||||
|
||||
for (auto texture : player2Textures)
|
||||
{
|
||||
texture->unload();
|
||||
delete texture;
|
||||
if (texture)
|
||||
{
|
||||
texture->unload();
|
||||
delete texture;
|
||||
}
|
||||
}
|
||||
player2Textures.clear();
|
||||
|
||||
for (auto texture : itemTextures)
|
||||
{
|
||||
texture->unload();
|
||||
delete texture;
|
||||
if (texture)
|
||||
{
|
||||
texture->unload();
|
||||
delete texture;
|
||||
}
|
||||
}
|
||||
itemTextures.clear();
|
||||
|
||||
for (auto texture : balloonTextures)
|
||||
{
|
||||
texture->unload();
|
||||
delete texture;
|
||||
if (texture)
|
||||
{
|
||||
texture->unload();
|
||||
delete texture;
|
||||
}
|
||||
}
|
||||
balloonTextures.clear();
|
||||
|
||||
@@ -423,61 +453,31 @@ void Game::loadMedia()
|
||||
itemTextures.push_back(item6);
|
||||
|
||||
// Texturas - Player1
|
||||
Texture *player1Head = new Texture(renderer, asset->get("player_bal1_head.png"));
|
||||
player1Textures.push_back(player1Head);
|
||||
Texture *player1 = new Texture(renderer, asset->get("player.png"));
|
||||
player1Textures.push_back(player1);
|
||||
|
||||
Texture *player1Body = new Texture(renderer, asset->get("player_bal1_body.png"));
|
||||
player1Textures.push_back(player1Body);
|
||||
|
||||
Texture *player1Legs = new Texture(renderer, asset->get("player_bal1_legs.png"));
|
||||
player1Textures.push_back(player1Legs);
|
||||
|
||||
Texture *player1Death = new Texture(renderer, asset->get("player_bal1_death.png"));
|
||||
player1Textures.push_back(player1Death);
|
||||
|
||||
Texture *player1Fire = new Texture(renderer, asset->get("player_bal1_fire.png"));
|
||||
player1Textures.push_back(player1Fire);
|
||||
Texture *player1Power = new Texture(renderer, asset->get("player_power.png"));
|
||||
player1Textures.push_back(player1Power);
|
||||
|
||||
playerTextures.push_back(player1Textures);
|
||||
|
||||
// Texturas - Player2
|
||||
Texture *player2Head = new Texture(renderer, asset->get("player_arounder_head.png"));
|
||||
player2Textures.push_back(player2Head);
|
||||
Texture *player2 = new Texture(renderer, asset->get("player.png"));
|
||||
player2Textures.push_back(player2);
|
||||
|
||||
Texture *player2Body = new Texture(renderer, asset->get("player_arounder_body.png"));
|
||||
player2Textures.push_back(player2Body);
|
||||
|
||||
Texture *player2Legs = new Texture(renderer, asset->get("player_arounder_legs.png"));
|
||||
player2Textures.push_back(player2Legs);
|
||||
|
||||
Texture *player2Death = new Texture(renderer, asset->get("player_arounder_death.png"));
|
||||
player2Textures.push_back(player2Death);
|
||||
|
||||
Texture *player2Fire = new Texture(renderer, asset->get("player_arounder_fire.png"));
|
||||
player2Textures.push_back(player2Fire);
|
||||
Texture *player2Power = new Texture(renderer, asset->get("player_power.png"));
|
||||
player2Textures.push_back(player2Power);
|
||||
|
||||
playerTextures.push_back(player2Textures);
|
||||
|
||||
// Animaciones -- Jugador
|
||||
std::vector<std::string> *playerHeadAnimation = new std::vector<std::string>;
|
||||
loadAnimations(asset->get("player_head.ani"), playerHeadAnimation);
|
||||
playerAnimations.push_back(playerHeadAnimation);
|
||||
std::vector<std::string> *playerAnimation = new std::vector<std::string>;
|
||||
loadAnimations(asset->get("player.ani"), playerAnimation);
|
||||
playerAnimations.push_back(playerAnimation);
|
||||
|
||||
std::vector<std::string> *playerBodyAnimation = new std::vector<std::string>;
|
||||
loadAnimations(asset->get("player_body.ani"), playerBodyAnimation);
|
||||
playerAnimations.push_back(playerBodyAnimation);
|
||||
|
||||
std::vector<std::string> *playerLegsAnimation = new std::vector<std::string>;
|
||||
loadAnimations(asset->get("player_legs.ani"), playerLegsAnimation);
|
||||
playerAnimations.push_back(playerLegsAnimation);
|
||||
|
||||
std::vector<std::string> *playerDeathAnimation = new std::vector<std::string>;
|
||||
loadAnimations(asset->get("player_death.ani"), playerDeathAnimation);
|
||||
playerAnimations.push_back(playerDeathAnimation);
|
||||
|
||||
std::vector<std::string> *playerFireAnimation = new std::vector<std::string>;
|
||||
loadAnimations(asset->get("player_fire.ani"), playerFireAnimation);
|
||||
playerAnimations.push_back(playerFireAnimation);
|
||||
std::vector<std::string> *playerPowerAnimation = new std::vector<std::string>;
|
||||
loadAnimations(asset->get("player_power.ani"), playerPowerAnimation);
|
||||
playerAnimations.push_back(playerPowerAnimation);
|
||||
|
||||
// Animaciones -- Globos
|
||||
std::vector<std::string> *balloon1Animation = new std::vector<std::string>;
|
||||
@@ -2441,37 +2441,28 @@ void Game::renderSmartSprites()
|
||||
// Acciones a realizar cuando el jugador muere
|
||||
void Game::killPlayer(Player *player)
|
||||
{
|
||||
if (!player->isEnabled())
|
||||
{
|
||||
if (!player->isEnabled() && player->isInvulnerable())
|
||||
{ // Si no está habilitado o tiene inmunidad, no hace nada
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player->isInvulnerable())
|
||||
{
|
||||
if (player->hasExtraHit())
|
||||
{
|
||||
player->removeExtraHit();
|
||||
throwCoffee(player->getPosX() + (player->getWidth() / 2), player->getPosY() + (player->getHeight() / 2));
|
||||
JA_PlaySound(coffeeOutSound);
|
||||
screen->shake();
|
||||
}
|
||||
else
|
||||
{
|
||||
JA_PauseMusic();
|
||||
stopAllBalloons(10);
|
||||
JA_PlaySound(playerCollisionSound);
|
||||
screen->shake();
|
||||
JA_PlaySound(coffeeOutSound);
|
||||
player->setAlive(false);
|
||||
if (allPlayersAreDead())
|
||||
{
|
||||
JA_StopMusic();
|
||||
}
|
||||
else
|
||||
{
|
||||
JA_ResumeMusic();
|
||||
}
|
||||
}
|
||||
// Si tiene cafes
|
||||
if (player->hasExtraHit())
|
||||
{ // Lo pierde
|
||||
player->removeExtraHit();
|
||||
throwCoffee(player->getPosX() + (player->getWidth() / 2), player->getPosY() + (player->getHeight() / 2));
|
||||
JA_PlaySound(coffeeOutSound);
|
||||
screen->shake();
|
||||
}
|
||||
else
|
||||
{ // Si no tiene cafes, muere
|
||||
JA_PauseMusic();
|
||||
stopAllBalloons(10);
|
||||
JA_PlaySound(playerCollisionSound);
|
||||
screen->shake();
|
||||
JA_PlaySound(coffeeOutSound);
|
||||
player->setAlive(false);
|
||||
allPlayersAreDead() ? JA_StopMusic() : JA_ResumeMusic();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user