Compare commits
3 Commits
d3183237df
...
52a0c2b91f
| Author | SHA1 | Date | |
|---|---|---|---|
| 52a0c2b91f | |||
| f12a456017 | |||
| f39e65afaf |
@@ -52,7 +52,7 @@ Director::Director(int argc, const char *argv[])
|
|||||||
section::name = section::Name::GAME;
|
section::name = section::Name::GAME;
|
||||||
section::options = section::Options::GAME_PLAY_1P;
|
section::options = section::Options::GAME_PLAY_1P;
|
||||||
#elif DEBUG
|
#elif DEBUG
|
||||||
section::name = section::Name::LOGO;
|
section::name = section::Name::HI_SCORE_TABLE;
|
||||||
#else // NORMAL GAME
|
#else // NORMAL GAME
|
||||||
section::name = section::Name::LOGO;
|
section::name = section::Name::LOGO;
|
||||||
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
||||||
|
|||||||
@@ -774,7 +774,7 @@ void Game::createItemText(int x, std::shared_ptr<Texture> texture)
|
|||||||
const auto h = texture->getHeight();
|
const auto h = texture->getHeight();
|
||||||
|
|
||||||
const int y0 = param.game.play_area.rect.h - h;
|
const int y0 = param.game.play_area.rect.h - h;
|
||||||
const int y1 = 155;
|
const int y1 = 160 - (h / 2);
|
||||||
const int y2 = -h;
|
const int y2 = -h;
|
||||||
|
|
||||||
// Ajusta para que no se dibuje fuera de pantalla
|
// Ajusta para que no se dibuje fuera de pantalla
|
||||||
@@ -922,20 +922,28 @@ void Game::updateTimeStopped()
|
|||||||
if (time_stopped_counter_ > 120)
|
if (time_stopped_counter_ > 120)
|
||||||
{
|
{
|
||||||
if (time_stopped_counter_ % 30 == 0)
|
if (time_stopped_counter_ % 30 == 0)
|
||||||
|
{
|
||||||
JA_PlaySound(Resource::get()->getSound("clock.wav"));
|
JA_PlaySound(Resource::get()->getSound("clock.wav"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (time_stopped_counter_ % 15 == 0)
|
|
||||||
JA_PlaySound(Resource::get()->getSound("clock.wav"));
|
|
||||||
if (time_stopped_counter_ % 30 == 0)
|
if (time_stopped_counter_ % 30 == 0)
|
||||||
|
{
|
||||||
balloon_manager_->normalColorsToAllBalloons();
|
balloon_manager_->normalColorsToAllBalloons();
|
||||||
if (time_stopped_counter_ % 30 == 15)
|
JA_PlaySound(Resource::get()->getSound("clock.wav"));
|
||||||
|
}
|
||||||
|
else if (time_stopped_counter_ % 30 == 15)
|
||||||
|
{
|
||||||
balloon_manager_->reverseColorsToAllBalloons();
|
balloon_manager_->reverseColorsToAllBalloons();
|
||||||
|
JA_PlaySound(Resource::get()->getSound("clock.wav"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
disableTimeStopItem();
|
disableTimeStopItem();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el juego
|
// Actualiza el juego
|
||||||
@@ -1262,10 +1270,10 @@ void Game::checkEvents()
|
|||||||
createItem(ItemType::CLOCK, players_.at(0)->getPosX(), players_.at(0)->getPosY() - 40);
|
createItem(ItemType::CLOCK, players_.at(0)->getPosX(), players_.at(0)->getPosY() - 40);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SDLK_5: // Crea un PathSprite
|
case SDLK_5: // 5.000
|
||||||
{
|
{
|
||||||
const int x = players_.at(0)->getPosX() + (players_.at(0)->getWidth() - game_text_textures_[3]->getWidth()) / 2;
|
const int x = players_.at(0)->getPosX() + (players_.at(0)->getWidth() - game_text_textures_[3]->getWidth()) / 2;
|
||||||
createItemText(x, game_text_textures_.at(3));
|
createItemText(x, game_text_textures_.at(2));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SDLK_6: // Crea un mensaje
|
case SDLK_6: // Crea un mensaje
|
||||||
@@ -1273,10 +1281,13 @@ void Game::checkEvents()
|
|||||||
createMessage({paths_.at(0), paths_.at(1)}, Resource::get()->getTexture("game_text_get_ready"));
|
createMessage({paths_.at(0), paths_.at(1)}, Resource::get()->getTexture("game_text_get_ready"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SDLK_7: // Flash
|
case SDLK_7: // 100.000
|
||||||
{
|
{
|
||||||
// screen_->flash(flash_color, 3);
|
// screen_->flash(flash_color, 3);
|
||||||
tabe_->setState(TabeState::HIT);
|
// tabe_->setState(TabeState::HIT);
|
||||||
|
const int x = players_.at(0)->getPosX() + (players_.at(0)->getWidth() - game_text_textures_[3]->getWidth()) / 2;
|
||||||
|
createItemText(x, game_text_textures_.at(6));
|
||||||
|
break;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SDLK_8:
|
case SDLK_8:
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ HiScoreTable::HiScoreTable()
|
|||||||
fade_->setMode(fade_mode_);
|
fade_->setMode(fade_mode_);
|
||||||
fade_->activate();
|
fade_->activate();
|
||||||
|
|
||||||
|
// Crea los sprites con los textos
|
||||||
|
createSprites();
|
||||||
|
|
||||||
// Crea el contenido de la textura con la lista de puntuaciones
|
// Crea el contenido de la textura con la lista de puntuaciones
|
||||||
fillTexture();
|
fillTexture();
|
||||||
}
|
}
|
||||||
@@ -108,13 +111,6 @@ void HiScoreTable::update()
|
|||||||
// Crea el contenido de la textura con la lista de puntuaciones
|
// Crea el contenido de la textura con la lista de puntuaciones
|
||||||
void HiScoreTable::fillTexture()
|
void HiScoreTable::fillTexture()
|
||||||
{
|
{
|
||||||
// hay 27 letras - 7 de puntos quedan 20 caracteres 20 - name_lenght 0 num_dots
|
|
||||||
constexpr auto max_names = 10;
|
|
||||||
constexpr auto space_between_header = 32;
|
|
||||||
const auto space_between_lines = text_->getCharacterSize() * 2.0f;
|
|
||||||
const auto size = space_between_header + space_between_lines * (max_names - 1) + text_->getCharacterSize();
|
|
||||||
const auto first_line = (param.game.height - size) / 2;
|
|
||||||
|
|
||||||
// Pinta en el backbuffer el texto y los sprites
|
// Pinta en el backbuffer el texto y los sprites
|
||||||
auto temp = SDL_GetRenderTarget(renderer_);
|
auto temp = SDL_GetRenderTarget(renderer_);
|
||||||
SDL_SetRenderTarget(renderer_, backbuffer_);
|
SDL_SetRenderTarget(renderer_, backbuffer_);
|
||||||
@@ -122,22 +118,12 @@ void HiScoreTable::fillTexture()
|
|||||||
SDL_RenderClear(renderer_);
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
// Escribe el texto: Mejores puntuaciones
|
// Escribe el texto: Mejores puntuaciones
|
||||||
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, first_line, lang::getText(42), 1, orange_color, 1, shdw_txt_color);
|
header_->render();
|
||||||
|
|
||||||
// Escribe los nombres de la tabla de puntuaciones
|
// Escribe los nombres de la tabla de puntuaciones
|
||||||
for (int i = 0; i < max_names; ++i)
|
for (auto const &entry : entry_names_)
|
||||||
{
|
{
|
||||||
const auto name_lenght = options.game.hi_score_table[i].name.length();
|
entry->render();
|
||||||
const auto score = format(options.game.hi_score_table[i].score);
|
|
||||||
const auto score_lenght = score.size();
|
|
||||||
const auto num_dots = 25 - name_lenght - score_lenght;
|
|
||||||
std::string dots;
|
|
||||||
for (int j = 0; j < (int)num_dots; ++j)
|
|
||||||
{
|
|
||||||
dots = dots + ".";
|
|
||||||
}
|
|
||||||
const auto line = options.game.hi_score_table[i].name + dots + score;
|
|
||||||
text_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, (i * space_between_lines) + first_line + space_between_header, line, 1, orange_color, 1, shdw_txt_color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el destino de renderizado
|
// Cambia el destino de renderizado
|
||||||
@@ -275,3 +261,36 @@ std::string HiScoreTable::format(int number)
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Crea los sprites con los textos
|
||||||
|
void HiScoreTable::createSprites()
|
||||||
|
{
|
||||||
|
// Hay 27 letras - 7 de puntos quedan 20 caracteres 20 - name_lenght 0 num_dots
|
||||||
|
constexpr int max_names = 10;
|
||||||
|
constexpr int space_between_header = 32;
|
||||||
|
const int space_between_lines = text_->getCharacterSize() * 2;
|
||||||
|
const int size = space_between_header + space_between_lines * (max_names - 1) + text_->getCharacterSize();
|
||||||
|
const int first_line = (param.game.height - size) / 2;
|
||||||
|
|
||||||
|
// Crea el sprite para el texto de cabecera
|
||||||
|
header_ = std::make_unique<Sprite>(text_->writeDXToTexture(TEXT_COLOR | TEXT_SHADOW, lang::getText(42), 1, orange_color, 1, shdw_txt_color));
|
||||||
|
header_->setPosition(param.game.game_area.center_x - (header_->getWidth() / 2), first_line);
|
||||||
|
|
||||||
|
// Crea los sprites para las entradas en la tabla de puntuaciones
|
||||||
|
for (int i = 0; i < max_names; ++i)
|
||||||
|
{
|
||||||
|
const auto name_lenght = options.game.hi_score_table.at(i).name.length();
|
||||||
|
const auto score = format(options.game.hi_score_table.at(i).score);
|
||||||
|
const auto score_lenght = score.size();
|
||||||
|
const auto num_dots = 25 - name_lenght - score_lenght;
|
||||||
|
std::string dots;
|
||||||
|
for (int j = 0; j < (int)num_dots; ++j)
|
||||||
|
{
|
||||||
|
dots = dots + ".";
|
||||||
|
}
|
||||||
|
const auto line = options.game.hi_score_table.at(i).name + dots + score;
|
||||||
|
|
||||||
|
entry_names_.emplace_back(std::make_shared<PathSprite>(text_->writeDXToTexture(TEXT_SHADOW, line, 1, orange_color, 1, shdw_txt_color)));
|
||||||
|
entry_names_.back()->setPosition(param.game.game_area.center_x - (entry_names_.back()->getWidth() / 2), (i * space_between_lines) + first_line + space_between_header);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,8 @@
|
|||||||
#include <SDL2/SDL_stdinc.h> // para Uint16, Uint32, Uint8
|
#include <SDL2/SDL_stdinc.h> // para Uint16, Uint32, Uint8
|
||||||
#include <memory> // para unique_ptr
|
#include <memory> // para unique_ptr
|
||||||
#include <string> // para string
|
#include <string> // para string
|
||||||
|
#include "sprite.h"
|
||||||
|
#include "path_sprite.h"
|
||||||
class Background; // lines 8-8
|
class Background; // lines 8-8
|
||||||
class Fade; // lines 9-9
|
class Fade; // lines 9-9
|
||||||
class Text; // lines 10-10
|
class Text; // lines 10-10
|
||||||
@@ -31,9 +33,11 @@ private:
|
|||||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
|
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
|
||||||
|
|
||||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||||
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
|
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
|
||||||
std::shared_ptr<Text> text_; // Objeto para escribir texto
|
std::shared_ptr<Text> text_; // Objeto para escribir texto
|
||||||
|
std::unique_ptr<Sprite> header_; // Sprite con la cabecera del texto
|
||||||
|
std::vector<std::shared_ptr<PathSprite>> entry_names_; // Lista con los spritres de cada uno de los nombres de la tabla de records
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
Uint16 counter_; // Contador
|
Uint16 counter_; // Contador
|
||||||
@@ -65,6 +69,9 @@ private:
|
|||||||
// Gestiona el fade
|
// Gestiona el fade
|
||||||
void updateFade();
|
void updateFade();
|
||||||
|
|
||||||
|
// Crea los sprites con los textos
|
||||||
|
void createSprites();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
HiScoreTable();
|
HiScoreTable();
|
||||||
|
|||||||
@@ -102,6 +102,8 @@ void Tabe::enable()
|
|||||||
{
|
{
|
||||||
enabled_ = true;
|
enabled_ = true;
|
||||||
has_bonus_ = true;
|
has_bonus_ = true;
|
||||||
|
hit_counter_ = 0;
|
||||||
|
number_of_hits_ = 0;
|
||||||
y_ = param.game.game_area.rect.y + 20.0f;
|
y_ = param.game.game_area.rect.y + 20.0f;
|
||||||
|
|
||||||
// Establece una dirección aleatoria
|
// Establece una dirección aleatoria
|
||||||
@@ -164,7 +166,8 @@ void Tabe::setState(TabeState state)
|
|||||||
|
|
||||||
case TabeState::HIT:
|
case TabeState::HIT:
|
||||||
sprite_->setCurrentAnimation("hit");
|
sprite_->setCurrentAnimation("hit");
|
||||||
hit_counter = 5;
|
hit_counter_ = 5;
|
||||||
|
++number_of_hits_;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -178,8 +181,8 @@ void Tabe::updateState()
|
|||||||
{
|
{
|
||||||
if (state_ == TabeState::HIT)
|
if (state_ == TabeState::HIT)
|
||||||
{
|
{
|
||||||
--hit_counter;
|
--hit_counter_;
|
||||||
if (hit_counter == 0)
|
if (hit_counter_ == 0)
|
||||||
{
|
{
|
||||||
setState(TabeState::FLY);
|
setState(TabeState::FLY);
|
||||||
}
|
}
|
||||||
@@ -189,7 +192,7 @@ void Tabe::updateState()
|
|||||||
// Intenta obtener el bonus
|
// Intenta obtener el bonus
|
||||||
bool Tabe::tryToGetBonus()
|
bool Tabe::tryToGetBonus()
|
||||||
{
|
{
|
||||||
if (has_bonus_ && rand() % 8 == 0)
|
if (has_bonus_ && rand() % std::max(1, 10 - number_of_hits_) == 0)
|
||||||
{
|
{
|
||||||
has_bonus_ = false;
|
has_bonus_ = false;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ private:
|
|||||||
TabeDirection direction_; // Dirección del objeto
|
TabeDirection direction_; // Dirección del objeto
|
||||||
TabeDirection destiny_; // Destino del objeto
|
TabeDirection destiny_; // Destino del objeto
|
||||||
TabeState state_ = TabeState::FLY; // Estado
|
TabeState state_ = TabeState::FLY; // Estado
|
||||||
int hit_counter = 0; // Contador para el estado HIT
|
int hit_counter_ = 0; // Contador para el estado HIT
|
||||||
|
int number_of_hits_ = 0; // Cantidad de disparos que ha recibido
|
||||||
bool has_bonus_ = true; // Indica si el Tabe aun tiene el bonus para soltar
|
bool has_bonus_ = true; // Indica si el Tabe aun tiene el bonus para soltar
|
||||||
|
|
||||||
// Mueve el objeto
|
// Mueve el objeto
|
||||||
|
|||||||
@@ -173,6 +173,25 @@ std::shared_ptr<Texture> Text::writeToTexture(const std::string &text, int zoom,
|
|||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Escribe el texto con extras en una textura
|
||||||
|
std::shared_ptr<Texture> Text::writeDXToTexture(Uint8 flags, const std::string &text, int kerning, Color textColor, Uint8 shadow_distance, Color shadow_color, int lenght)
|
||||||
|
{
|
||||||
|
auto renderer = Screen::get()->getRenderer();
|
||||||
|
auto texture = std::make_shared<Texture>(renderer);
|
||||||
|
auto width = Text::lenght(text, kerning);
|
||||||
|
auto height = box_height_ + shadow_distance;
|
||||||
|
auto temp = SDL_GetRenderTarget(renderer);
|
||||||
|
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||||
|
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
|
texture->setAsRenderTarget(renderer);
|
||||||
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
writeDX(flags, 0, 0, text, kerning, textColor, shadow_distance, shadow_color, lenght);
|
||||||
|
SDL_SetRenderTarget(renderer, temp);
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
// Escribe el texto con colores
|
// Escribe el texto con colores
|
||||||
void Text::writeColored(int x, int y, const std::string &text, Color color, int kerning, int lenght)
|
void Text::writeColored(int x, int y, const std::string &text, Color color, int kerning, int lenght)
|
||||||
{
|
{
|
||||||
@@ -272,7 +291,7 @@ void Text::setFixedWidth(bool value)
|
|||||||
void Text::setPalette(int number)
|
void Text::setPalette(int number)
|
||||||
{
|
{
|
||||||
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
||||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
|
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
|
||||||
sprite_->getTexture()->setPalette(number);
|
sprite_->getTexture()->setPalette(number);
|
||||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
||||||
}
|
}
|
||||||
@@ -55,6 +55,9 @@ public:
|
|||||||
// Escribe el texto en una textura
|
// Escribe el texto en una textura
|
||||||
std::shared_ptr<Texture> writeToTexture(const std::string &text, int zoom = 1, int kerning = 1);
|
std::shared_ptr<Texture> writeToTexture(const std::string &text, int zoom = 1, int kerning = 1);
|
||||||
|
|
||||||
|
// Escribe el texto con extras en una textura
|
||||||
|
std::shared_ptr<Texture> writeDXToTexture(Uint8 flags, const std::string &text, int kerning = 1, Color textColor = Color(), Uint8 shadow_distance = 1, Color shadow_color = Color(), int lenght = -1);
|
||||||
|
|
||||||
// Escribe el texto con colores
|
// Escribe el texto con colores
|
||||||
void writeColored(int x, int y, const std::string &text, Color color, int kerning = 1, int lenght = -1);
|
void writeColored(int x, int y, const std::string &text, Color color, int kerning = 1, int lenght = -1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user