Arreglada la animacion de morir. Ya no se usan smartsprites

This commit is contained in:
2022-10-06 13:13:27 +02:00
parent 50d2a5d1c7
commit 56c1a1d7f3
8 changed files with 53 additions and 116 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -209,7 +209,6 @@ bool Director::setFileList()
asset->add("data/gfx/intro.png", t_bitmap); asset->add("data/gfx/intro.png", t_bitmap);
asset->add("data/gfx/logo.png", t_bitmap); asset->add("data/gfx/logo.png", t_bitmap);
asset->add("data/gfx/items.png", t_bitmap);
asset->add("data/gfx/item_points1_disk.png", t_bitmap); asset->add("data/gfx/item_points1_disk.png", t_bitmap);
asset->add("data/gfx/item_points1_disk.ani", t_data); asset->add("data/gfx/item_points1_disk.ani", t_data);
asset->add("data/gfx/item_points2_gavina.png", t_bitmap); asset->add("data/gfx/item_points2_gavina.png", t_bitmap);

View File

@@ -84,9 +84,6 @@ Game::~Game()
gameTextTexture->unload(); gameTextTexture->unload();
delete gameTextTexture; delete gameTextTexture;
itemTexture->unload();
delete itemTexture;
// Animaciones // Animaciones
for (auto animation : playerAnimations) for (auto animation : playerAnimations)
{ {
@@ -372,7 +369,6 @@ void Game::loadMedia()
gamePowerMeterTexture = new LTexture(renderer, asset->get("game_power_meter.png")); gamePowerMeterTexture = new LTexture(renderer, asset->get("game_power_meter.png"));
gameSkyColorsTexture = new LTexture(renderer, asset->get("game_sky_colors.png")); gameSkyColorsTexture = new LTexture(renderer, asset->get("game_sky_colors.png"));
gameTextTexture = new LTexture(renderer, asset->get("game_text.png")); gameTextTexture = new LTexture(renderer, asset->get("game_text.png"));
itemTexture = new LTexture(renderer, asset->get("items.png"));
// Texturas - Globos // Texturas - Globos
LTexture *balloon1Texture = new LTexture(renderer, asset->get("balloon1.png")); LTexture *balloon1Texture = new LTexture(renderer, asset->get("balloon1.png"));
@@ -1703,82 +1699,24 @@ void Game::updateStage()
void Game::updateDeath() void Game::updateDeath()
{ {
// Comprueba si todos los jugadores estan muertos // Comprueba si todos los jugadores estan muertos
bool allAreDead = true; bool allPlayersAreDead = true;
for (auto player : players) for (auto player : players)
{ {
allAreDead &= (!player->isAlive()); allPlayersAreDead &= (!player->isAlive());
/*if (!player->isAlive())
{
// Animación
if ((player->getDeathCounter() / 5) % 4 == 0)
{
smartSprites[player->deathIndex]->setSpriteClip(24 * 0, 24, 24, 24);
}
else if ((player->getDeathCounter() / 5) % 4 == 1)
{
smartSprites[player->deathIndex]->setSpriteClip(24 * 1, 24, 24, 24);
}
else if ((player->getDeathCounter() / 5) % 4 == 2)
{
smartSprites[player->deathIndex]->setSpriteClip(24 * 2, 24, 24, 24);
}
else if ((player->getDeathCounter() / 5) % 4 == 3)
{
smartSprites[player->deathIndex]->setSpriteClip(24 * 3, 24, 24, 24);
}
// Rebote en los laterales
if (smartSprites[player->deathIndex]->getVelX() > 0)
{
if (smartSprites[player->deathIndex]->getPosX() > (GAME_WIDTH - smartSprites[player->deathIndex]->getWidth()))
{
smartSprites[player->deathIndex]->setPosX(GAME_WIDTH - smartSprites[player->deathIndex]->getWidth());
smartSprites[player->deathIndex]->setVelX(smartSprites[player->deathIndex]->getVelX() * (-1));
smartSprites[player->deathIndex]->setDestX(smartSprites[player->deathIndex]->getDestX() * (-1));
}
}
else
{
if (smartSprites[player->deathIndex]->getPosX() < 0)
{
smartSprites[player->deathIndex]->setPosX(0);
smartSprites[player->deathIndex]->setVelX(smartSprites[player->deathIndex]->getVelX() * (-1));
smartSprites[player->deathIndex]->setDestX(smartSprites[player->deathIndex]->getDestX() * (-1));
}
}
}*/
} }
if (allAreDead) if (allPlayersAreDead)
{ {
if (deathCounter > 0) if (deathCounter > 0)
{ {
deathCounter--; deathCounter--;
if ((deathCounter == 250) || (deathCounter == 200) || (deathCounter == 180) || (deathCounter == 120) || (deathCounter == 60)) if ((deathCounter == 250) || (deathCounter == 200) || (deathCounter == 180) || (deathCounter == 120) || (deathCounter == 60))
{ {
const Uint8 sound = rand() % 4; // Hace sonar aleatoriamente uno de los 4 sonidos de burbujas
switch (sound) const Uint8 index = rand() % 4;
{ const JA_Sound sound[4] = {bubble1Sound, bubble2Sound, bubble3Sound, bubble4Sound};
case 0: JA_PlaySound(sound[index], 0);
JA_PlaySound(bubble1Sound, 0);
break;
case 1:
JA_PlaySound(bubble2Sound, 0);
break;
case 2:
JA_PlaySound(bubble3Sound, 0);
break;
case 3:
JA_PlaySound(bubble4Sound, 0);
break;
default:
break;
}
} }
} }
else else
@@ -2556,7 +2494,7 @@ void Game::updateShakeEffect()
// Crea un SmartSprite para arrojar el item café al recibir un impacto // Crea un SmartSprite para arrojar el item café al recibir un impacto
void Game::throwCoffee(int x, int y) void Game::throwCoffee(int x, int y)
{ {
SmartSprite *ss = new SmartSprite(itemTexture, renderer); SmartSprite *ss = new SmartSprite(itemTextures.at(4), renderer);
smartSprites.push_back(ss); smartSprites.push_back(ss);
ss->setPosX(x - 8); ss->setPosX(x - 8);
@@ -2571,36 +2509,12 @@ void Game::throwCoffee(int x, int y)
ss->setDestY(GAME_HEIGHT + 1); ss->setDestY(GAME_HEIGHT + 1);
ss->setEnabled(true); ss->setEnabled(true);
ss->setEnabledCounter(1); ss->setEnabledCounter(1);
ss->setSpriteClip(80, 16, 16, 16); ss->setSpriteClip(0, 0, 16, 16);
ss->setRotate(true); ss->setRotate(true);
ss->setRotateSpeed(10); ss->setRotateSpeed(10);
ss->setRotateAmount(90.0); ss->setRotateAmount(90.0);
} }
// Crea un SmartSprite para arrojar al jugador al morir
void Game::throwPlayer(int x, int y, Player *player)
{
const int sentit = ((rand() % 2) ? 1 : -1);
SmartSprite *ss = new SmartSprite(nullptr, renderer);
smartSprites.push_back(ss);
ss->setTexture(player->getDeadTexture());
ss->setPosX(x);
ss->setPosY(y);
ss->setWidth(24);
ss->setHeight(24);
ss->setVelX(2.0f * sentit);
ss->setVelY(-5.0f);
ss->setAccelX(0.0f);
ss->setAccelY(0.2f);
ss->setDestX(GAME_WIDTH * sentit);
ss->setDestY(GAME_HEIGHT + 1);
ss->setEnabled(true);
ss->setEnabledCounter(1);
ss->setSpriteClip(0, 0, 24, 24);
}
// Actualiza los SmartSprites // Actualiza los SmartSprites
void Game::updateSmartSprites() void Game::updateSmartSprites()
{ {
@@ -2638,7 +2552,6 @@ void Game::killPlayer(Player *player)
shakeScreen(); shakeScreen();
SDL_Delay(500); SDL_Delay(500);
JA_PlaySound(coffeeOutSound); JA_PlaySound(coffeeOutSound);
throwPlayer(player->getPosX(), player->getPosY(), player);
player->setAlive(false); player->setAlive(false);
if (allPlayersAreDead()) if (allPlayersAreDead())
{ {

View File

@@ -138,8 +138,6 @@ private:
LTexture *gameSkyColorsTexture; // Textura con los diferentes colores de fondo del juego LTexture *gameSkyColorsTexture; // Textura con los diferentes colores de fondo del juego
LTexture *gameTextTexture; // Textura para los sprites con textos LTexture *gameTextTexture; // Textura para los sprites con textos
LTexture *itemTexture; // Textura para los items
std::vector<std::vector<std::string> *> itemAnimations; // Vector con las animaciones de los items std::vector<std::vector<std::string> *> itemAnimations; // Vector con las animaciones de los items
std::vector<std::vector<std::string> *> playerAnimations; // Vector con las animaciones del jugador std::vector<std::vector<std::string> *> playerAnimations; // Vector con las animaciones del jugador
std::vector<std::vector<std::string> *> balloonAnimations; // Vector con las animaciones de los globos std::vector<std::vector<std::string> *> balloonAnimations; // Vector con las animaciones de los globos
@@ -201,7 +199,6 @@ private:
float stageBitmapPath[STAGE_COUNTER]; // Vector con los puntos Y por donde se desplaza el texto float stageBitmapPath[STAGE_COUNTER]; // Vector con los puntos Y por donde se desplaza el texto
float getReadyBitmapPath[STAGE_COUNTER]; // Vector con los puntos X por donde se desplaza el texto float getReadyBitmapPath[STAGE_COUNTER]; // Vector con los puntos X por donde se desplaza el texto
Uint16 deathCounter; // Contador para la animación de muerte del jugador Uint16 deathCounter; // Contador para la animación de muerte del jugador
Uint8 deathIndex; // Indice del vector de smartsprites que contiene el sprite del jugador
Uint8 menaceCurrent; // Nivel de amenaza actual Uint8 menaceCurrent; // Nivel de amenaza actual
Uint8 menaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el numero de globos Uint8 menaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el numero de globos
bool timeStopped; // Indica si el tiempo está detenido bool timeStopped; // Indica si el tiempo está detenido
@@ -399,9 +396,6 @@ private:
// Crea un SmartSprite para arrojar el item café al recibir un impacto // Crea un SmartSprite para arrojar el item café al recibir un impacto
void throwCoffee(int x, int y); void throwCoffee(int x, int y);
// Crea un SmartSprite para arrojar al jugador al morir
void throwPlayer(int x, int y, Player *player);
// Actualiza los SmartSprites // Actualiza los SmartSprites
void updateSmartSprites(); void updateSmartSprites();

View File

@@ -35,12 +35,12 @@ private:
// Variables // Variables
Uint16 counter; // Contador Uint16 counter; // Contador
Uint16 counterEnd; // Valor final para el contador Uint16 counterEnd; // Valor final para el contador
section_t section; // Estado del bucle principal para saber si continua o se sale section_t section; // Estado del bucle principal para saber si continua o se sale
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
bool manualQuit; // Indica si se quiere salir del modo manual bool manualQuit; // Indica si se quiere salir del modo manual
mode_e mode; // Modo en el que se van a ejecutar las instrucciones mode_e mode; // Modo en el que se van a ejecutar las instrucciones
// Actualiza las variables // Actualiza las variables
void update(); void update();

View File

@@ -2,7 +2,7 @@
#include "player.h" #include "player.h"
// Constructor // Constructor
Player::Player(float x, int y, SDL_Renderer *renderer, std::vector<LTexture *> texture, std::vector<std::vector<std::string>*> animations) Player::Player(float x, int y, SDL_Renderer *renderer, std::vector<LTexture *> texture, std::vector<std::vector<std::string> *> animations)
{ {
// Copia los punteros // Copia los punteros
this->renderer = renderer; this->renderer = renderer;
@@ -131,7 +131,9 @@ void Player::move()
// Si el jugador abandona el area de juego por los laterales // Si el jugador abandona el area de juego por los laterales
if ((posX < PLAY_AREA_LEFT - 5) || (posX + width > PLAY_AREA_RIGHT + 5)) if ((posX < PLAY_AREA_LEFT - 5) || (posX + width > PLAY_AREA_RIGHT + 5))
posX -= velX; // Restaura su posición { // Restaura su posición
posX -= velX;
}
// Actualiza la posición del sprite // Actualiza la posición del sprite
legsSprite->setPosX(getPosX()); legsSprite->setPosX(getPosX());
@@ -143,6 +145,20 @@ void Player::move()
headSprite->setPosX(getPosX()); headSprite->setPosX(getPosX());
headSprite->setPosY(posY); headSprite->setPosY(posY);
} }
else
{
deathSprite->update();
// Si el cadaver abandona el area de juego por los laterales
if ((deathSprite->getPosX() < PLAY_AREA_LEFT) || (deathSprite->getPosX() + width > PLAY_AREA_RIGHT))
{ // Restaura su posición
const float vx = deathSprite->getVelX();
deathSprite->setPosX(deathSprite->getPosX() - vx);
// Rebota
deathSprite->setVelX(-vx);
}
}
} }
// Pinta el jugador en pantalla // Pinta el jugador en pantalla
@@ -166,6 +182,10 @@ void Player::render()
headSprite->render(); headSprite->render();
} }
} }
else
{
deathSprite->render();
}
} }
// Establece el estado del jugador cuando camina // Establece el estado del jugador cuando camina
@@ -186,8 +206,6 @@ void Player::setFiringStatus(Uint8 status)
if (statusFiring != status) if (statusFiring != status)
{ {
statusFiring = status; statusFiring = status;
// bodySprite->setCurrentFrame(0);
// headSprite->setCurrentFrame(0);
} }
} }
@@ -217,7 +235,7 @@ void Player::setAnimation()
{ // No esta disparando { // No esta disparando
bodySprite->setCurrentAnimation(aWalking + aBodyCoffees); bodySprite->setCurrentAnimation(aWalking + aBodyCoffees);
bodySprite->setFlip(flipWalk); bodySprite->setFlip(flipWalk);
headSprite->setCurrentAnimation(aWalking + aHeadCoffees+ aPowerUp); headSprite->setCurrentAnimation(aWalking + aHeadCoffees + aPowerUp);
headSprite->setFlip(flipWalk); headSprite->setFlip(flipWalk);
} }
else else
@@ -336,6 +354,18 @@ bool Player::isAlive()
void Player::setAlive(bool value) void Player::setAlive(bool value)
{ {
alive = value; alive = value;
if (!value)
{
deathSprite->setPos(headSprite->getRect());
deathSprite->setAccelY(0.2f);
deathSprite->setVelY(-6.6f);
deathSprite->setVelX(3.3f);
if (rand() % 2 == 0)
{
deathSprite->setVelX(-3.3f);
}
}
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
@@ -533,7 +563,8 @@ void Player::shiftColliders()
// Obtiene el puntero a la textura con los gráficos de la animación de morir // Obtiene el puntero a la textura con los gráficos de la animación de morir
LTexture *Player::getDeadTexture() LTexture *Player::getDeadTexture()
{ {
return deathSprite->getTexture();; return deathSprite->getTexture();
;
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
@@ -547,20 +578,20 @@ void Player::updatePowerUpHeadOffset()
{ {
if (!powerUp) if (!powerUp)
{ {
//powerUpHeadOffset = 0; // powerUpHeadOffset = 0;
} }
else else
{ {
//powerUpHeadOffset = 96; // powerUpHeadOffset = 96;
if (powerUpCounter < 300) if (powerUpCounter < 300)
{ {
if (powerUpCounter % 10 > 4) if (powerUpCounter % 10 > 4)
{ {
//powerUpHeadOffset = 96; // powerUpHeadOffset = 96;
} }
else else
{ {
//powerUpHeadOffset = 0; // powerUpHeadOffset = 0;
} }
} }
} }