Modificada la cadencia de foc sense autofire i arreglades un poc les animacions de cool_down i cooling
This commit is contained in:
@@ -557,17 +557,17 @@ void Game::checkBulletBalloonCollision()
|
|||||||
auto player = getPlayer(bullet->getOwner());
|
auto player = getPlayer(bullet->getOwner());
|
||||||
|
|
||||||
// Suelta el item si se da el caso
|
// Suelta el item si se da el caso
|
||||||
const auto droppeditem = dropItem();
|
const auto dropped_item = dropItem();
|
||||||
if (droppeditem != ItemType::NONE && !demo_.recording)
|
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"));
|
JA_PlaySound(Resource::get()->getSound("itemdrop.wav"));
|
||||||
}
|
}
|
||||||
else
|
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;
|
coffee_machine_enabled_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1257,7 +1257,14 @@ void Game::checkEvents()
|
|||||||
}
|
}
|
||||||
case SDLK_8:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case SDLK_9:
|
case SDLK_9:
|
||||||
@@ -1481,8 +1488,10 @@ void Game::handleFireInput(const std::shared_ptr<Player> &player, BulletType bul
|
|||||||
: InputType::FIRE_RIGHT);
|
: InputType::FIRE_RIGHT);
|
||||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 6, player->getPosY() + (player->getHeight() / 2), bulletType, player->isPowerUp(), player->getId());
|
createBullet(player->getPosX() + (player->getWidth() / 2) - 6, player->getPosY() + (player->getHeight() / 2), bulletType, player->isPowerUp(), player->getId());
|
||||||
JA_PlaySound(Resource::get()->getSound("bullet.wav"));
|
JA_PlaySound(Resource::get()->getSound("bullet.wav"));
|
||||||
|
|
||||||
// Establece un tiempo de espera para el próximo disparo.
|
// 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_)
|
for (const auto &player : players_)
|
||||||
{
|
{
|
||||||
if (player->isPlaying())
|
if (player->isPlaying())
|
||||||
{ // Maneja el input de los jugadores en modo normal.
|
{
|
||||||
|
// Maneja el input de los jugadores en modo normal.
|
||||||
handleNormalPlayerInput(player);
|
handleNormalPlayerInput(player);
|
||||||
}
|
}
|
||||||
else if (player->isContinue() || player->isWaiting())
|
else if (player->isContinue() || player->isWaiting())
|
||||||
{ // Gestiona la continuación del jugador.
|
{
|
||||||
|
// Gestiona la continuación del jugador.
|
||||||
handlePlayerContinue(player);
|
handlePlayerContinue(player);
|
||||||
}
|
}
|
||||||
else if (player->isEnteringName() || player->isEnteringNameGameCompleted())
|
else if (player->isEnteringName() || player->isEnteringNameGameCompleted())
|
||||||
{ // Gestiona la introducción del nombre del jugador.
|
{
|
||||||
|
// Gestiona la introducción del nombre del jugador.
|
||||||
handleNameInput(player);
|
handleNameInput(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1593,8 +1605,8 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player)
|
|||||||
{
|
{
|
||||||
player->setInput(InputType::START);
|
player->setInput(InputType::START);
|
||||||
addScoreToScoreBoard(player->getRecordName(), player->getScore());
|
addScoreToScoreBoard(player->getRecordName(), player->getScore());
|
||||||
const auto status = player->getPlayingState();
|
const auto state = player->getPlayingState();
|
||||||
player->setPlayingState(status == PlayerState::ENTERING_NAME ? PlayerState::CONTINUE : PlayerState::LEAVING_SCREEN);
|
player->setPlayingState(state == PlayerState::ENTERING_NAME ? PlayerState::CONTINUE : PlayerState::LEAVING_SCREEN);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1617,8 +1629,8 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player)
|
|||||||
{
|
{
|
||||||
player->setInput(InputType::START);
|
player->setInput(InputType::START);
|
||||||
addScoreToScoreBoard(player->getRecordName(), player->getScore());
|
addScoreToScoreBoard(player->getRecordName(), player->getScore());
|
||||||
const auto status = player->getPlayingState();
|
const auto state = player->getPlayingState();
|
||||||
player->setPlayingState(status == PlayerState::ENTERING_NAME ? PlayerState::CONTINUE : PlayerState::LEAVING_SCREEN);
|
player->setPlayingState(state == PlayerState::ENTERING_NAME ? PlayerState::CONTINUE : PlayerState::LEAVING_SCREEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ void Notifier::update()
|
|||||||
// Si la notificación anterior está "saliendo", no hagas nada
|
// Si la notificación anterior está "saliendo", no hagas nada
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
{
|
{
|
||||||
if (notifications_[i - 1].status == NotificationStatus::RISING)
|
if (notifications_[i - 1].state == NotificationStatus::RISING)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -73,8 +73,8 @@ void Notifier::update()
|
|||||||
{
|
{
|
||||||
if (param.notification.sound)
|
if (param.notification.sound)
|
||||||
{
|
{
|
||||||
if (notifications_[i].status == NotificationStatus::RISING)
|
if (notifications_[i].state == NotificationStatus::RISING)
|
||||||
{
|
{
|
||||||
// Reproduce el sonido de la notificación
|
// Reproduce el sonido de la notificación
|
||||||
JA_PlaySound(Resource::get()->getSound("notify.wav"));
|
JA_PlaySound(Resource::get()->getSound("notify.wav"));
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ void Notifier::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los estados
|
// 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 float step = ((float)notifications_[i].counter / notifications_[i].travel_dist);
|
||||||
const int alpha = 255 * step;
|
const int alpha = 255 * step;
|
||||||
@@ -99,21 +99,21 @@ void Notifier::update()
|
|||||||
|
|
||||||
if (notifications_[i].rect.y == notifications_[i].y)
|
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].texture->setAlpha(255);
|
||||||
notifications_[i].counter = 0;
|
notifications_[i].counter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (notifications_[i].status == NotificationStatus::STAY)
|
else if (notifications_[i].state == NotificationStatus::STAY)
|
||||||
{
|
{
|
||||||
if (notifications_[i].counter == wait_time_)
|
if (notifications_[i].counter == wait_time_)
|
||||||
{
|
{
|
||||||
notifications_[i].status = NotificationStatus::VANISHING;
|
notifications_[i].state = NotificationStatus::VANISHING;
|
||||||
notifications_[i].counter = 0;
|
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);
|
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)
|
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)
|
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);
|
notifications_.erase(notifications_.begin() + i);
|
||||||
}
|
}
|
||||||
@@ -302,7 +302,7 @@ void Notifier::clearNotifications()
|
|||||||
{
|
{
|
||||||
for (auto ¬ification : notifications_)
|
for (auto ¬ification : notifications_)
|
||||||
{
|
{
|
||||||
notification.status = NotificationStatus::FINISHED;
|
notification.state = NotificationStatus::FINISHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearFinishedNotifications();
|
clearFinishedNotifications();
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ private:
|
|||||||
std::shared_ptr<Sprite> sprite;
|
std::shared_ptr<Sprite> sprite;
|
||||||
std::vector<std::string> texts;
|
std::vector<std::string> texts;
|
||||||
int counter;
|
int counter;
|
||||||
NotificationStatus status;
|
NotificationStatus state;
|
||||||
NotificationShape shape;
|
NotificationShape shape;
|
||||||
SDL_Rect rect;
|
SDL_Rect rect;
|
||||||
int y;
|
int y;
|
||||||
@@ -46,7 +46,7 @@ private:
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit Notification()
|
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("") {}
|
shape(NotificationShape::SQUARED), rect{0, 0, 0, 0}, y(0), travel_dist(0), code("") {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ void Player::init()
|
|||||||
vel_y_ = 0;
|
vel_y_ = 0;
|
||||||
score_ = 0;
|
score_ = 0;
|
||||||
score_multiplier_ = 1.0f;
|
score_multiplier_ = 1.0f;
|
||||||
cooldown_ = 10;
|
cool_down_ = 10;
|
||||||
enter_name_->init();
|
enter_name_->init();
|
||||||
|
|
||||||
// Establece la posición del sprite
|
// Establece la posición del sprite
|
||||||
@@ -401,37 +401,38 @@ void Player::setAnimation()
|
|||||||
// Actualiza el valor de la variable
|
// Actualiza el valor de la variable
|
||||||
void Player::updateCooldown()
|
void Player::updateCooldown()
|
||||||
{
|
{
|
||||||
if (cooldown_ > 0)
|
if (cool_down_ > 0)
|
||||||
{
|
{
|
||||||
cooldown_ -= power_up_ ? 2 : 1;
|
--cool_down_;
|
||||||
|
cooling_state_counter_ = 50;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!isCooling())
|
if (cooling_state_counter_ > 0)
|
||||||
{
|
{
|
||||||
cooling_status_counter_ = 40;
|
if (cooling_state_counter_ == 40)
|
||||||
switch (firing_state_)
|
|
||||||
{
|
{
|
||||||
case PlayerState::FIRING_LEFT:
|
switch (firing_state_)
|
||||||
firing_state_ = PlayerState::COOLING_LEFT;
|
{
|
||||||
break;
|
case PlayerState::FIRING_LEFT:
|
||||||
case PlayerState::FIRING_RIGHT:
|
setFiringState(PlayerState::COOLING_LEFT);
|
||||||
firing_state_ = PlayerState::COOLING_RIGHT;
|
break;
|
||||||
break;
|
case PlayerState::FIRING_RIGHT:
|
||||||
case PlayerState::FIRING_UP:
|
setFiringState(PlayerState::COOLING_RIGHT);
|
||||||
firing_state_ = PlayerState::COOLING_UP;
|
break;
|
||||||
break;
|
case PlayerState::FIRING_UP:
|
||||||
default:
|
setFiringState(PlayerState::COOLING_UP);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
--cooling_state_counter_;
|
||||||
else if (cooling_status_counter_ > 0)
|
|
||||||
{
|
|
||||||
--cooling_status_counter_;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setFiringState(PlayerState::FIRING_NONE);
|
setFiringState(PlayerState::FIRING_NONE);
|
||||||
|
cooling_state_counter_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ private:
|
|||||||
int default_pos_y_; // Posición inicial para el jugador
|
int default_pos_y_; // Posición inicial para el jugador
|
||||||
float vel_x_ = 0.0f; // Cantidad de pixeles a desplazarse en el eje X
|
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 vel_y_ = 0.0f; // Cantidad de pixeles a desplazarse en el eje Y
|
||||||
int cooldown_ = 0; // Contador durante el cual no puede disparar
|
int cool_down_ = 0; // Contador durante el cual no puede disparar
|
||||||
int cooling_status_counter_ = 0; // Contador para la animación del estado cooling
|
int cooling_state_counter_ = 0; // Contador para la animación del estado cooling
|
||||||
int score_ = 0; // Puntos del jugador
|
int score_ = 0; // Puntos del jugador
|
||||||
float score_multiplier_ = 1.0f; // Multiplicador de puntos
|
float score_multiplier_ = 1.0f; // Multiplicador de puntos
|
||||||
PlayerState walking_state_ = PlayerState::WALKING_STOP; // Estado del jugador al moverse
|
PlayerState walking_state_ = PlayerState::WALKING_STOP; // Estado del jugador al moverse
|
||||||
@@ -207,10 +207,10 @@ public:
|
|||||||
bool isWaiting() const { return playing_state_ == PlayerState::WAITING; }
|
bool isWaiting() const { return playing_state_ == PlayerState::WAITING; }
|
||||||
|
|
||||||
// Getters
|
// 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 hasExtraHit() const { return extra_hit_; }
|
||||||
bool isCooling() { return firing_state_ == PlayerState::COOLING_LEFT || firing_state_ == PlayerState::COOLING_UP || firing_state_ == PlayerState::COOLING_RIGHT; }
|
bool isCooling() const { 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 IsEligibleForHighScore() const { return score_ > options.game.hi_score_table.back().score; }
|
||||||
bool isInvulnerable() const { return invulnerable_; }
|
bool isInvulnerable() const { return invulnerable_; }
|
||||||
bool isPowerUp() const { return power_up_; }
|
bool isPowerUp() const { return power_up_; }
|
||||||
Circle &getCollider() { return collider_; }
|
Circle &getCollider() { return collider_; }
|
||||||
@@ -233,7 +233,7 @@ public:
|
|||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
void setController(int index) { controller_index_ = index; }
|
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 setFiringState(PlayerState state) { firing_state_ = state; }
|
||||||
void setInvulnerableCounter(int value) { invulnerable_counter_ = value; }
|
void setInvulnerableCounter(int value) { invulnerable_counter_ = value; }
|
||||||
void setName(const std::string &name) { name_ = name; }
|
void setName(const std::string &name) { name_ = name; }
|
||||||
|
|||||||
Reference in New Issue
Block a user