Compare commits

..

3 Commits

21 changed files with 114 additions and 84 deletions

View File

@@ -1,5 +1,7 @@
## GAME
game.item_size 20 # Tamaño de los items del juego
game.coffee_machine_w 28 # Ancho de la máquina de café
game.coffee_machine_h 37 # Alto de la máquina de café
game.width 320 # Ancho de la resolucion nativa del juego
game.height 240 # Alto de la resolucion nativa del juego
game.play_area.rect.x 0 # Rectangulo con la posición de la zona de juego

View File

@@ -1,12 +1,14 @@
## GAME
game.item_size 20 # Tamaño de los items del juego
game.width 320 # Ancho de la resolucion nativa del juego
game.height 256 # Alto de la resolucion nativa del juego
game.play_area.rect.x 0 # Rectangulo con la posición de la zona de juego
game.play_area.rect.y 0 # Rectangulo con la posición de la zona de juego
game.play_area.rect.w 320 # Rectangulo con la posición de la zona de juego
game.play_area.rect.h 216 # Rectangulo con la posición de la zona de juego
game.enter_name_seconds 60 # Duración en segundos para introducir el nombre al finalizar la partida
game.item_size 20 # Tamaño de los items del juego
game.coffee_machine_w 28 # Ancho de la máquina de café
game.coffee_machine_h 37 # Alto de la máquina de café
game.width 320 # Ancho de la resolucion nativa del juego
game.height 256 # Alto de la resolucion nativa del juego
game.play_area.rect.x 0 # Rectangulo con la posición de la zona de juego
game.play_area.rect.y 0 # Rectangulo con la posición de la zona de juego
game.play_area.rect.w 320 # Rectangulo con la posición de la zona de juego
game.play_area.rect.h 216 # Rectangulo con la posición de la zona de juego
game.enter_name_seconds 60 # Duración en segundos para introducir el nombre al finalizar la partida
## FADE
fade.num_squares_width 160

View File

Before

Width:  |  Height:  |  Size: 173 B

After

Width:  |  Height:  |  Size: 173 B

View File

Before

Width:  |  Height:  |  Size: 173 B

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

View File

Before

Width:  |  Height:  |  Size: 172 B

After

Width:  |  Height:  |  Size: 172 B

View File

Before

Width:  |  Height:  |  Size: 172 B

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

View File

@@ -40,8 +40,6 @@ Credits::Credits()
throw std::runtime_error("Failed to create SDL texture for text.");
}
section::name = section::Name::CREDITS;
// top_black_rect_ = {play_area_.x, 0, play_area_.w, black_bars_size_};
// bottom_black_rect_ = {play_area_.x, param.game.game_area.rect.h - black_bars_size_, play_area_.w, black_bars_size_};
balloon_manager_->setPlayArea(play_area_);
fade_in_->setColor(fade_color.r, fade_color.g, fade_color.b);

View File

@@ -505,17 +505,17 @@ void Director::setFileList()
{ // Jugador 1
Asset::get()->add(prefix + "/data/gfx/player/player1.gif", AssetType::BITMAP);
Asset::get()->add(prefix + "/data/gfx/player/player1_one_coffee_palette.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/gfx/player/player1_two_coffee_palette.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/gfx/player/player1_all_white_palette.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/gfx/player/player1_1_coffee_palette.gif", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/gfx/player/player1_2_coffee_palette.gif", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/gfx/player/player1_invencible_palette.gif", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/gfx/player/player1_power.png", AssetType::BITMAP);
}
{ // Jugador 2
Asset::get()->add(prefix + "/data/gfx/player/player2.gif", AssetType::BITMAP);
Asset::get()->add(prefix + "/data/gfx/player/player2_one_coffee_palette.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/gfx/player/player2_two_coffee_palette.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/gfx/player/player2_all_white_palette.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/gfx/player/player2_1_coffee_palette.gif", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/gfx/player/player2_2_coffee_palette.gif", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/gfx/player/player2_invencible_palette.gif", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/gfx/player/player2_power.png", AssetType::BITMAP);
}

View File

@@ -557,17 +557,17 @@ void Game::checkBulletBalloonCollision()
auto player = getPlayer(bullet->getOwner());
// Suelta el item si se da el caso
const auto droppeditem = dropItem();
if (droppeditem != ItemType::NONE && !demo_.recording)
const auto dropped_item = dropItem();
if (dropped_item != ItemType::NONE && !demo_.recording)
{
if (droppeditem != ItemType::COFFEE_MACHINE)
if (dropped_item != ItemType::COFFEE_MACHINE)
{
createItem(droppeditem, balloon->getPosX(), balloon->getPosY());
createItem(dropped_item, balloon->getPosX(), balloon->getPosY());
JA_PlaySound(Resource::get()->getSound("itemdrop.wav"));
}
else
{
createItem(droppeditem, player->getPosX(), 0);
createItem(dropped_item, player->getPosX(), param.game.game_area.rect.y - param.game.coffee_machine_h);
coffee_machine_enabled_ = true;
}
}
@@ -1257,7 +1257,14 @@ void Game::checkEvents()
}
case SDLK_8:
{
players_.at(0)->setPlayingState(PlayerState::LEAVING_SCREEN);
for (auto player : players_)
{
if (player->isPlaying())
{
createItem(ItemType::COFFEE_MACHINE, player->getPosX(), param.game.game_area.rect.y - param.game.coffee_machine_h);
break;
}
}
break;
}
case SDLK_9:
@@ -1481,8 +1488,10 @@ void Game::handleFireInput(const std::shared_ptr<Player> &player, BulletType bul
: InputType::FIRE_RIGHT);
createBullet(player->getPosX() + (player->getWidth() / 2) - 6, player->getPosY() + (player->getHeight() / 2), bulletType, player->isPowerUp(), player->getId());
JA_PlaySound(Resource::get()->getSound("bullet.wav"));
// Establece un tiempo de espera para el próximo disparo.
player->setFireCooldown(10);
const int cooldown = player->isPowerUp() ? 5 : options.game.autofire ? 10 : 7;
player->setFireCooldown(cooldown);
}
}
@@ -1492,15 +1501,18 @@ void Game::handlePlayersInput()
for (const auto &player : players_)
{
if (player->isPlaying())
{ // Maneja el input de los jugadores en modo normal.
{
// Maneja el input de los jugadores en modo normal.
handleNormalPlayerInput(player);
}
else if (player->isContinue() || player->isWaiting())
{ // Gestiona la continuación del jugador.
{
// Gestiona la continuación del jugador.
handlePlayerContinue(player);
}
else if (player->isEnteringName() || player->isEnteringNameGameCompleted())
{ // Gestiona la introducción del nombre del jugador.
{
// Gestiona la introducción del nombre del jugador.
handleNameInput(player);
}
}
@@ -1593,8 +1605,8 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player)
{
player->setInput(InputType::START);
addScoreToScoreBoard(player->getRecordName(), player->getScore());
const auto status = player->getPlayingState();
player->setPlayingState(status == PlayerState::ENTERING_NAME ? PlayerState::CONTINUE : PlayerState::LEAVING_SCREEN);
const auto state = player->getPlayingState();
player->setPlayingState(state == PlayerState::ENTERING_NAME ? PlayerState::CONTINUE : PlayerState::LEAVING_SCREEN);
}
else
{
@@ -1617,8 +1629,8 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player)
{
player->setInput(InputType::START);
addScoreToScoreBoard(player->getRecordName(), player->getScore());
const auto status = player->getPlayingState();
player->setPlayingState(status == PlayerState::ENTERING_NAME ? PlayerState::CONTINUE : PlayerState::LEAVING_SCREEN);
const auto state = player->getPlayingState();
player->setPlayingState(state == PlayerState::ENTERING_NAME ? PlayerState::CONTINUE : PlayerState::LEAVING_SCREEN);
}
}

View File

@@ -14,10 +14,10 @@ Item::Item(ItemType type, float x, float y, SDL_Rect &play_area, std::shared_ptr
{
case ItemType::COFFEE_MACHINE:
{
width_ = 28;
height_ = 37;
width_ = param.game.coffee_machine_w;
height_ = param.game.coffee_machine_h;
pos_x_ = ((static_cast<int>(x) + (play_area.w / 2)) % (play_area.w - width_ - 5)) + 2;
pos_y_ = -height_;
pos_y_ = y;
vel_x_ = 0.0f;
vel_y_ = -0.1f;
accel_y_ = 0.1f;
@@ -26,8 +26,8 @@ Item::Item(ItemType type, float x, float y, SDL_Rect &play_area, std::shared_ptr
}
default:
{
width_ = 20;
height_ = 20;
width_ = param.game.item_size;
height_ = param.game.item_size;
pos_x_ = x;
pos_y_ = y;
vel_x_ = -1.0f + ((rand() % 5) * 0.5f);

View File

@@ -60,7 +60,7 @@ void Notifier::update()
// Si la notificación anterior está "saliendo", no hagas nada
if (i > 0)
{
if (notifications_[i - 1].status == NotificationStatus::RISING)
if (notifications_[i - 1].state == NotificationStatus::RISING)
{
break;
}
@@ -73,8 +73,8 @@ void Notifier::update()
{
if (param.notification.sound)
{
if (notifications_[i].status == NotificationStatus::RISING)
{
if (notifications_[i].state == NotificationStatus::RISING)
{
// Reproduce el sonido de la notificación
JA_PlaySound(Resource::get()->getSound("notify.wav"));
}
@@ -82,7 +82,7 @@ void Notifier::update()
}
// Comprueba los estados
if (notifications_[i].status == NotificationStatus::RISING)
if (notifications_[i].state == NotificationStatus::RISING)
{
const float step = ((float)notifications_[i].counter / notifications_[i].travel_dist);
const int alpha = 255 * step;
@@ -99,21 +99,21 @@ void Notifier::update()
if (notifications_[i].rect.y == notifications_[i].y)
{
notifications_[i].status = NotificationStatus::STAY;
notifications_[i].state = NotificationStatus::STAY;
notifications_[i].texture->setAlpha(255);
notifications_[i].counter = 0;
}
}
else if (notifications_[i].status == NotificationStatus::STAY)
else if (notifications_[i].state == NotificationStatus::STAY)
{
if (notifications_[i].counter == wait_time_)
{
notifications_[i].status = NotificationStatus::VANISHING;
notifications_[i].state = NotificationStatus::VANISHING;
notifications_[i].counter = 0;
}
}
else if (notifications_[i].status == NotificationStatus::VANISHING)
else if (notifications_[i].state == NotificationStatus::VANISHING)
{
const float step = (notifications_[i].counter / (float)notifications_[i].travel_dist);
@@ -131,7 +131,7 @@ void Notifier::update()
if (notifications_[i].rect.y == notifications_[i].y - notifications_[i].travel_dist)
{
notifications_[i].status = NotificationStatus::FINISHED;
notifications_[i].state = NotificationStatus::FINISHED;
}
}
@@ -146,7 +146,7 @@ void Notifier::clearFinishedNotifications()
{
for (int i = (int)notifications_.size() - 1; i >= 0; --i)
{
if (notifications_[i].status == NotificationStatus::FINISHED)
if (notifications_[i].state == NotificationStatus::FINISHED)
{
notifications_.erase(notifications_.begin() + i);
}
@@ -302,7 +302,7 @@ void Notifier::clearNotifications()
{
for (auto &notification : notifications_)
{
notification.status = NotificationStatus::FINISHED;
notification.state = NotificationStatus::FINISHED;
}
clearFinishedNotifications();

View File

@@ -37,7 +37,7 @@ private:
std::shared_ptr<Sprite> sprite;
std::vector<std::string> texts;
int counter;
NotificationStatus status;
NotificationStatus state;
NotificationShape shape;
SDL_Rect rect;
int y;
@@ -46,7 +46,7 @@ private:
// Constructor
explicit Notification()
: texture(nullptr), sprite(nullptr), texts(), counter(0), status(NotificationStatus::RISING),
: texture(nullptr), sprite(nullptr), texts(), counter(0), state(NotificationStatus::RISING),
shape(NotificationShape::SQUARED), rect{0, 0, 0, 0}, y(0), travel_dist(0), code("") {}
};

View File

@@ -21,6 +21,8 @@ void initParam()
param.game.width = 320;
param.game.height = 256;
param.game.item_size = 20;
param.game.coffee_machine_w = 28;
param.game.coffee_machine_h = 37;
param.game.game_area.rect = {0, 0, param.game.width, param.game.height};
param.game.play_area.rect = {0, 0, param.game.width, 216};
param.game.enter_name_seconds = 30;
@@ -124,6 +126,16 @@ bool setParams(const std::string &var, const std::string &value)
param.game.item_size = std::stoi(value);
}
else if (var == "game.coffee_machine_w")
{
param.game.coffee_machine_w = std::stoi(value);
}
else if (var == "game.coffee_machine_h")
{
param.game.coffee_machine_h = std::stoi(value);
}
else if (var == "game.play_area.rect.x")
{
param.game.play_area.rect.x = std::stoi(value);

View File

@@ -11,6 +11,8 @@ struct ParamGame
int width; // Ancho de la resolucion nativa del juego
int height; // Alto de la resolucion nativa del juego
int item_size; // Tamaño de los items del juego
int coffee_machine_w; // Ancho de la máquina de café
int coffee_machine_h; // Alto de la máquina de café
Zone play_area; // Rectangulo con la posición de la zona de juego
Zone game_area; // Rectangulo con las dimensiones del juego
int enter_name_seconds; // Duración en segundos para introducir el nombre al finalizar la partida
@@ -63,7 +65,8 @@ struct ParamNotification
};
// Estructura para almacenar todos los parámetros del juego
struct Param {
struct Param
{
ParamGame game;
ParamFade fade;
SDL_Rect scoreboard;
@@ -72,14 +75,14 @@ struct Param {
std::vector<ParamBalloon> balloon;
ParamNotification notification;
Param() : game(), fade(), scoreboard(), title(), background(), notification() {
Param() : game(), fade(), scoreboard(), title(), background(), notification()
{
balloon.reserve(4);
}
};
extern Param param;
extern Param param;
// Establece valores para los parametros a partir de un fichero de texto

View File

@@ -56,7 +56,7 @@ void Player::init()
vel_y_ = 0;
score_ = 0;
score_multiplier_ = 1.0f;
cooldown_ = 10;
cool_down_ = 10;
enter_name_->init();
// Establece la posición del sprite
@@ -401,37 +401,38 @@ void Player::setAnimation()
// Actualiza el valor de la variable
void Player::updateCooldown()
{
if (cooldown_ > 0)
if (cool_down_ > 0)
{
cooldown_ -= power_up_ ? 2 : 1;
--cool_down_;
cooling_state_counter_ = 50;
}
else
{
if (!isCooling())
if (cooling_state_counter_ > 0)
{
cooling_status_counter_ = 40;
switch (firing_state_)
if (cooling_state_counter_ == 40)
{
case PlayerState::FIRING_LEFT:
firing_state_ = PlayerState::COOLING_LEFT;
break;
case PlayerState::FIRING_RIGHT:
firing_state_ = PlayerState::COOLING_RIGHT;
break;
case PlayerState::FIRING_UP:
firing_state_ = PlayerState::COOLING_UP;
break;
default:
break;
switch (firing_state_)
{
case PlayerState::FIRING_LEFT:
setFiringState(PlayerState::COOLING_LEFT);
break;
case PlayerState::FIRING_RIGHT:
setFiringState(PlayerState::COOLING_RIGHT);
break;
case PlayerState::FIRING_UP:
setFiringState(PlayerState::COOLING_UP);
break;
default:
break;
}
}
}
else if (cooling_status_counter_ > 0)
{
--cooling_status_counter_;
--cooling_state_counter_;
}
else
{
setFiringState(PlayerState::FIRING_NONE);
cooling_state_counter_ = 0;
}
}
}

View File

@@ -69,8 +69,8 @@ private:
int default_pos_y_; // Posición inicial para el jugador
float vel_x_ = 0.0f; // Cantidad de pixeles a desplazarse en el eje X
int vel_y_ = 0.0f; // Cantidad de pixeles a desplazarse en el eje Y
int cooldown_ = 0; // Contador durante el cual no puede disparar
int cooling_status_counter_ = 0; // Contador para la animación del estado cooling
int cool_down_ = 0; // Contador durante el cual no puede disparar
int cooling_state_counter_ = 0; // Contador para la animación del estado cooling
int score_ = 0; // Puntos del jugador
float score_multiplier_ = 1.0f; // Multiplicador de puntos
PlayerState walking_state_ = PlayerState::WALKING_STOP; // Estado del jugador al moverse
@@ -207,10 +207,10 @@ public:
bool isWaiting() const { return playing_state_ == PlayerState::WAITING; }
// Getters
bool canFire() const { return cooldown_ > 0 ? false : true; }
bool canFire() const { return cool_down_ > 0 ? false : true; }
bool hasExtraHit() const { return extra_hit_; }
bool isCooling() { return firing_state_ == PlayerState::COOLING_LEFT || firing_state_ == PlayerState::COOLING_UP || firing_state_ == PlayerState::COOLING_RIGHT; }
bool IsEligibleForHighScore() { return score_ > options.game.hi_score_table.back().score; }
bool isCooling() const { return firing_state_ == PlayerState::COOLING_LEFT || firing_state_ == PlayerState::COOLING_UP || firing_state_ == PlayerState::COOLING_RIGHT; }
bool IsEligibleForHighScore() const { return score_ > options.game.hi_score_table.back().score; }
bool isInvulnerable() const { return invulnerable_; }
bool isPowerUp() const { return power_up_; }
Circle &getCollider() { return collider_; }
@@ -233,7 +233,7 @@ public:
// Setters
void setController(int index) { controller_index_ = index; }
void setFireCooldown(int time) { cooldown_ = time; }
void setFireCooldown(int time) { cool_down_ = time; }
void setFiringState(PlayerState state) { firing_state_ = state; }
void setInvulnerableCounter(int value) { invulnerable_counter_ = value; }
void setName(const std::string &name) { name_ = name; }

View File

@@ -254,14 +254,14 @@ void Resource::addPalettes()
{
// Jugador 1
std::cout << "\n>> PALETTES" << std::endl;
getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_one_coffee_palette.pal"));
getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_two_coffee_palette.pal"));
getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_all_white_palette.pal"));
getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_1_coffee_palette.gif"));
getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_2_coffee_palette.gif"));
getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_invencible_palette.gif"));
// Jugador 2
getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_one_coffee_palette.pal"));
getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_two_coffee_palette.pal"));
getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_all_white_palette.pal"));
getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_1_coffee_palette.gif"));
getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_2_coffee_palette.gif"));
getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_invencible_palette.gif"));
// Fuentes
getTexture("smb2.gif")->addPaletteFromFile(Asset::get()->get("smb2_palette1.pal"));