Abans de renombrar player.cpp
This commit is contained in:
@@ -12,67 +12,67 @@
|
|||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
Scoreboard *Scoreboard::scoreboard = nullptr;
|
Scoreboard *Scoreboard::scoreboard_ = nullptr;
|
||||||
|
|
||||||
// [SINGLETON] Crearemos el objeto scoreboard con esta función estática
|
// [SINGLETON] Crearemos el objeto score_board con esta función estática
|
||||||
void Scoreboard::init(SDL_Renderer *renderer)
|
void Scoreboard::init(SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
Scoreboard::scoreboard = new Scoreboard(renderer);
|
Scoreboard::scoreboard_ = new Scoreboard(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto scoreboard con esta función estática
|
// [SINGLETON] Destruiremos el objeto score_board con esta función estática
|
||||||
void Scoreboard::destroy()
|
void Scoreboard::destroy()
|
||||||
{
|
{
|
||||||
delete Scoreboard::scoreboard;
|
delete Scoreboard::scoreboard_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// [SINGLETON] Con este método obtenemos el objeto scoreboard y podemos trabajar con él
|
// [SINGLETON] Con este método obtenemos el objeto score_board y podemos trabajar con él
|
||||||
Scoreboard *Scoreboard::get()
|
Scoreboard *Scoreboard::get()
|
||||||
{
|
{
|
||||||
return Scoreboard::scoreboard;
|
return Scoreboard::scoreboard_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
||||||
: renderer(renderer)
|
: renderer_(renderer)
|
||||||
{
|
{
|
||||||
// Inicializa punteros
|
// Inicializa punteros
|
||||||
gamePowerMeterTexture = nullptr;
|
game_power_meter_texture_ = nullptr;
|
||||||
powerMeterSprite = nullptr;
|
power_meter_sprite_ = nullptr;
|
||||||
textScoreBoard = nullptr;
|
text_scoreboard_ = nullptr;
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
stage = 1;
|
|
||||||
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
||||||
{
|
{
|
||||||
name[i] = "";
|
name_[i] = "";
|
||||||
recordName[i] = "";
|
record_name_[i] = "";
|
||||||
selectorPos[i] = 0;
|
selector_pos_[i] = 0;
|
||||||
score[i] = 0;
|
score_[i] = 0;
|
||||||
mult[i] = 0;
|
mult_[i] = 0;
|
||||||
continueCounter[i] = 0;
|
continue_counter_[i] = 0;
|
||||||
}
|
}
|
||||||
hiScore = 0;
|
stage_ = 1;
|
||||||
power = 0;
|
hi_score_ = 0;
|
||||||
hiScoreName = "";
|
power_ = 0;
|
||||||
color = {0, 0, 0};
|
hi_score_name_ = "";
|
||||||
rect = {0, 0, 320, 40};
|
color_ = {0, 0, 0};
|
||||||
panel[SCOREBOARD_LEFT_PANEL].mode = ScoreboardMode::SCORE;
|
rect_ = {0, 0, 320, 40};
|
||||||
panel[SCOREBOARD_RIGHT_PANEL].mode = ScoreboardMode::SCORE;
|
panel_[SCOREBOARD_LEFT_PANEL].mode = ScoreboardMode::SCORE;
|
||||||
panel[SCOREBOARD_CENTER_PANEL].mode = ScoreboardMode::STAGE_INFO;
|
panel_[SCOREBOARD_RIGHT_PANEL].mode = ScoreboardMode::SCORE;
|
||||||
ticks = SDL_GetTicks();
|
panel_[SCOREBOARD_CENTER_PANEL].mode = ScoreboardMode::STAGE_INFO;
|
||||||
counter = 0;
|
ticks_ = SDL_GetTicks();
|
||||||
|
counter_ = 0;
|
||||||
|
|
||||||
// Recalcula las anclas de los elementos
|
// Recalcula las anclas de los elementos
|
||||||
recalculateAnchors();
|
recalculateAnchors();
|
||||||
|
|
||||||
// Crea objetos
|
// Crea objetos
|
||||||
gamePowerMeterTexture = std::make_shared<Texture>(renderer, Asset::get()->get("game_power_meter.png"));
|
game_power_meter_texture_ = std::make_shared<Texture>(renderer_, Asset::get()->get("game_power_meter.png"));
|
||||||
powerMeterSprite = std::make_unique<Sprite>(slot4_2.x - 20, slot4_2.y, 40, 7, gamePowerMeterTexture);
|
power_meter_sprite_ = std::make_unique<Sprite>(slot4_2_.x - 20, slot4_2_.y, 40, 7, game_power_meter_texture_);
|
||||||
textScoreBoard = std::make_unique<Text>(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), renderer);
|
text_scoreboard_ = std::make_unique<Text>(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), renderer_);
|
||||||
|
|
||||||
// Crea la textura de fondo
|
// Crea la textura de fondo
|
||||||
background = nullptr;
|
background_ = nullptr;
|
||||||
createBackgroundTexture();
|
createBackgroundTexture();
|
||||||
|
|
||||||
// Crea las texturas de los paneles
|
// Crea las texturas de los paneles
|
||||||
@@ -84,12 +84,12 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
|||||||
|
|
||||||
Scoreboard::~Scoreboard()
|
Scoreboard::~Scoreboard()
|
||||||
{
|
{
|
||||||
if (background)
|
if (background_)
|
||||||
{
|
{
|
||||||
SDL_DestroyTexture(background);
|
SDL_DestroyTexture(background_);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto texture : panelTexture)
|
for (auto texture : panel_texture_)
|
||||||
{
|
{
|
||||||
if (texture)
|
if (texture)
|
||||||
{
|
{
|
||||||
@@ -109,10 +109,10 @@ std::string Scoreboard::updateScoreText(int num)
|
|||||||
// Actualiza el contador
|
// Actualiza el contador
|
||||||
void Scoreboard::updateCounter()
|
void Scoreboard::updateCounter()
|
||||||
{
|
{
|
||||||
if (SDL_GetTicks() - ticks > SCOREBOARD_TICK_SPEED)
|
if (SDL_GetTicks() - ticks_ > SCOREBOARD_TICK_SPEED)
|
||||||
{
|
{
|
||||||
ticks = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
counter++;
|
counter_++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,80 +126,80 @@ void Scoreboard::update()
|
|||||||
// Pinta el marcador
|
// Pinta el marcador
|
||||||
void Scoreboard::render()
|
void Scoreboard::render()
|
||||||
{
|
{
|
||||||
SDL_RenderCopy(renderer, background, nullptr, &rect);
|
SDL_RenderCopy(renderer_, background_, nullptr, &rect_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Scoreboard::setName(int panel, std::string name)
|
void Scoreboard::setName(int panel_, std::string name_)
|
||||||
{
|
{
|
||||||
this->name[panel] = name;
|
this->name_[panel_] = name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Scoreboard::setRecordName(int panel, std::string recordName)
|
void Scoreboard::setRecordName(int panel_, std::string record_name_)
|
||||||
{
|
{
|
||||||
this->recordName[panel] = recordName;
|
this->record_name_[panel_] = record_name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Scoreboard::setSelectorPos(int panel, int pos)
|
void Scoreboard::setSelectorPos(int panel_, int pos)
|
||||||
{
|
{
|
||||||
selectorPos[panel] = pos;
|
selector_pos_[panel_] = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Scoreboard::setScore(int panel, int score)
|
void Scoreboard::setScore(int panel_, int score_)
|
||||||
{
|
{
|
||||||
this->score[panel] = score;
|
this->score_[panel_] = score_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Scoreboard::setMult(int panel, float mult)
|
void Scoreboard::setMult(int panel_, float mult_)
|
||||||
{
|
{
|
||||||
this->mult[panel] = mult;
|
this->mult_[panel_] = mult_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Scoreboard::setContinue(int panel, int value)
|
void Scoreboard::setContinue(int panel_, int value)
|
||||||
{
|
{
|
||||||
continueCounter[panel] = value;
|
continue_counter_[panel_] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Scoreboard::setStage(int stage)
|
void Scoreboard::setStage(int stage_)
|
||||||
{
|
{
|
||||||
this->stage = stage;
|
this->stage_ = stage_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Scoreboard::setHiScore(int hiScore)
|
void Scoreboard::setHiScore(int hi_score_)
|
||||||
{
|
{
|
||||||
this->hiScore = hiScore;
|
this->hi_score_ = hi_score_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Scoreboard::setPower(float power)
|
void Scoreboard::setPower(float power_)
|
||||||
{
|
{
|
||||||
this->power = power;
|
this->power_ = power_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Scoreboard::setHiScoreName(std::string name)
|
void Scoreboard::setHiScoreName(std::string name_)
|
||||||
{
|
{
|
||||||
hiScoreName = name;
|
hi_score_name_ = name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Scoreboard::setColor(Color color)
|
void Scoreboard::setColor(Color color_)
|
||||||
{
|
{
|
||||||
this->color = color;
|
this->color_ = color_;
|
||||||
fillBackgroundTexture();
|
fillBackgroundTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Scoreboard::setPos(SDL_Rect rect)
|
void Scoreboard::setPos(SDL_Rect rect_)
|
||||||
{
|
{
|
||||||
this->rect = rect;
|
this->rect_ = rect_;
|
||||||
|
|
||||||
// Recalcula las anclas de los elementos
|
// Recalcula las anclas de los elementos
|
||||||
recalculateAnchors();
|
recalculateAnchors();
|
||||||
@@ -218,42 +218,42 @@ void Scoreboard::setPos(SDL_Rect rect)
|
|||||||
void Scoreboard::fillPanelTextures()
|
void Scoreboard::fillPanelTextures()
|
||||||
{
|
{
|
||||||
// Guarda a donde apunta actualmente el renderizador
|
// Guarda a donde apunta actualmente el renderizador
|
||||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
SDL_Texture *temp = SDL_GetRenderTarget(renderer_);
|
||||||
|
|
||||||
// Genera el contenidoi de cada panel
|
// Genera el contenidoi de cada panel_
|
||||||
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
||||||
{
|
{
|
||||||
// Cambia el destino del renderizador
|
// Cambia el destino del renderizador
|
||||||
SDL_SetRenderTarget(renderer, panelTexture[i]);
|
SDL_SetRenderTarget(renderer_, panel_texture_[i]);
|
||||||
|
|
||||||
// Dibuja el fondo de la textura
|
// Dibuja el fondo de la textura
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
switch (panel[i].mode)
|
switch (panel_[i].mode)
|
||||||
{
|
{
|
||||||
case ScoreboardMode::SCORE:
|
case ScoreboardMode::SCORE:
|
||||||
{
|
{
|
||||||
// SCORE
|
// SCORE
|
||||||
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, name[i]);
|
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y, name_[i]);
|
||||||
textScoreBoard->writeCentered(slot4_2.x, slot4_2.y, updateScoreText(score[i]));
|
text_scoreboard_->writeCentered(slot4_2_.x, slot4_2_.y, updateScoreText(score_[i]));
|
||||||
|
|
||||||
// MULT
|
// MULT
|
||||||
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y, lang::getText(55));
|
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText(55));
|
||||||
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, std::to_string(mult[i]).substr(0, 3));
|
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y, std::to_string(mult_[i]).substr(0, 3));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ScoreboardMode::DEMO:
|
case ScoreboardMode::DEMO:
|
||||||
{
|
{
|
||||||
// DEMO MODE
|
// DEMO MODE
|
||||||
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y + 4, lang::getText(101));
|
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y + 4, lang::getText(101));
|
||||||
|
|
||||||
// PRESS START TO PLAY
|
// PRESS START TO PLAY
|
||||||
if (counter % 10 < 8)
|
if (counter_ % 10 < 8)
|
||||||
{
|
{
|
||||||
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y - 2, lang::getText(103));
|
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y - 2, lang::getText(103));
|
||||||
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y - 2, lang::getText(104));
|
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y - 2, lang::getText(104));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -261,13 +261,13 @@ void Scoreboard::fillPanelTextures()
|
|||||||
case ScoreboardMode::WAITING:
|
case ScoreboardMode::WAITING:
|
||||||
{
|
{
|
||||||
// GAME OVER
|
// GAME OVER
|
||||||
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y + 4, lang::getText(102));
|
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y + 4, lang::getText(102));
|
||||||
|
|
||||||
// PRESS START TO PLAY
|
// PRESS START TO PLAY
|
||||||
if (counter % 10 < 8)
|
if (counter_ % 10 < 8)
|
||||||
{
|
{
|
||||||
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y - 2, lang::getText(103));
|
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y - 2, lang::getText(103));
|
||||||
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y - 2, lang::getText(104));
|
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y - 2, lang::getText(104));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -275,13 +275,13 @@ void Scoreboard::fillPanelTextures()
|
|||||||
case ScoreboardMode::GAME_OVER:
|
case ScoreboardMode::GAME_OVER:
|
||||||
{
|
{
|
||||||
// GAME OVER
|
// GAME OVER
|
||||||
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y + 4, lang::getText(102));
|
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y + 4, lang::getText(102));
|
||||||
|
|
||||||
// PLEASE WAIT
|
// PLEASE WAIT
|
||||||
if (counter % 10 < 8)
|
if (counter_ % 10 < 8)
|
||||||
{
|
{
|
||||||
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y - 2, lang::getText(114));
|
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y - 2, lang::getText(114));
|
||||||
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y - 2, lang::getText(115));
|
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y - 2, lang::getText(115));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -289,58 +289,58 @@ void Scoreboard::fillPanelTextures()
|
|||||||
case ScoreboardMode::STAGE_INFO:
|
case ScoreboardMode::STAGE_INFO:
|
||||||
{
|
{
|
||||||
// STAGE
|
// STAGE
|
||||||
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, lang::getText(57) + std::to_string(stage));
|
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y, lang::getText(57) + std::to_string(stage_));
|
||||||
|
|
||||||
// POWERMETER
|
// POWERMETER
|
||||||
powerMeterSprite->setSpriteClip(0, 0, 40, 7);
|
power_meter_sprite_->setSpriteClip(0, 0, 40, 7);
|
||||||
powerMeterSprite->render();
|
power_meter_sprite_->render();
|
||||||
powerMeterSprite->setSpriteClip(40, 0, int(power * 40.0f), 7);
|
power_meter_sprite_->setSpriteClip(40, 0, int(power_ * 40.0f), 7);
|
||||||
powerMeterSprite->render();
|
power_meter_sprite_->render();
|
||||||
|
|
||||||
// HI-SCORE
|
// HI-SCORE
|
||||||
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y, lang::getText(56));
|
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText(56));
|
||||||
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, hiScoreName + " - " + updateScoreText(hiScore));
|
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y, hi_score_name_ + " - " + updateScoreText(hi_score_));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ScoreboardMode::CONTINUE:
|
case ScoreboardMode::CONTINUE:
|
||||||
{
|
{
|
||||||
// SCORE
|
// SCORE
|
||||||
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, name[i]);
|
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y, name_[i]);
|
||||||
textScoreBoard->writeCentered(slot4_2.x, slot4_2.y, updateScoreText(score[i]));
|
text_scoreboard_->writeCentered(slot4_2_.x, slot4_2_.y, updateScoreText(score_[i]));
|
||||||
|
|
||||||
// CONTINUE
|
// CONTINUE
|
||||||
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y, lang::getText(105));
|
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText(105));
|
||||||
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, std::to_string(continueCounter[i]));
|
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y, std::to_string(continue_counter_[i]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ScoreboardMode::ENTER_NAME:
|
case ScoreboardMode::ENTER_NAME:
|
||||||
{
|
{
|
||||||
// SCORE
|
// SCORE
|
||||||
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, name[i]);
|
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y, name_[i]);
|
||||||
textScoreBoard->writeCentered(slot4_2.x, slot4_2.y, updateScoreText(score[i]));
|
text_scoreboard_->writeCentered(slot4_2_.x, slot4_2_.y, updateScoreText(score_[i]));
|
||||||
|
|
||||||
// ENTER NAME
|
// ENTER NAME
|
||||||
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y, lang::getText(106));
|
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText(106));
|
||||||
SDL_Rect rect = {enterNamePos.x, enterNamePos.y, 5, 7};
|
SDL_Rect rect_ = {enter_name_pos_.x, enter_name_pos_.y, 5, 7};
|
||||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xEB, 255);
|
SDL_SetRenderDrawColor(renderer_, 0xFF, 0xFF, 0xEB, 255);
|
||||||
for (int j = 0; j < (int)recordName[i].size(); ++j)
|
for (int j = 0; j < (int)record_name_[i].size(); ++j)
|
||||||
{
|
{
|
||||||
if (j == selectorPos[i])
|
if (j == selector_pos_[i])
|
||||||
{ // La letra seleccionada se pinta de forma intermitente
|
{ // La letra seleccionada se pinta de forma intermitente
|
||||||
if (counter % 3 > 0)
|
if (counter_ % 3 > 0)
|
||||||
{
|
{
|
||||||
SDL_RenderDrawLine(renderer, rect.x, rect.y + rect.h, rect.x + rect.w, rect.y + rect.h);
|
SDL_RenderDrawLine(renderer_, rect_.x, rect_.y + rect_.h, rect_.x + rect_.w, rect_.y + rect_.h);
|
||||||
textScoreBoard->write(rect.x, rect.y, recordName[i].substr(j, 1));
|
text_scoreboard_->write(rect_.x, rect_.y, record_name_[i].substr(j, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_RenderDrawLine(renderer, rect.x, rect.y + rect.h, rect.x + rect.w, rect.y + rect.h);
|
SDL_RenderDrawLine(renderer_, rect_.x, rect_.y + rect_.h, rect_.x + rect_.w, rect_.y + rect_.h);
|
||||||
textScoreBoard->write(rect.x, rect.y, recordName[i].substr(j, 1));
|
text_scoreboard_->write(rect_.x, rect_.y, record_name_[i].substr(j, 1));
|
||||||
}
|
}
|
||||||
rect.x += 7;
|
rect_.x += 7;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -351,7 +351,7 @@ void Scoreboard::fillPanelTextures()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Deja el renderizador apuntando donde estaba
|
// Deja el renderizador apuntando donde estaba
|
||||||
SDL_SetRenderTarget(renderer, temp);
|
SDL_SetRenderTarget(renderer_, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rellena la textura de fondo
|
// Rellena la textura de fondo
|
||||||
@@ -361,41 +361,41 @@ void Scoreboard::fillBackgroundTexture()
|
|||||||
fillPanelTextures();
|
fillPanelTextures();
|
||||||
|
|
||||||
// Cambia el destino del renderizador
|
// Cambia el destino del renderizador
|
||||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
SDL_Texture *temp = SDL_GetRenderTarget(renderer_);
|
||||||
SDL_SetRenderTarget(renderer, background);
|
SDL_SetRenderTarget(renderer_, background_);
|
||||||
|
|
||||||
// Dibuja el fondo del marcador
|
// Dibuja el fondo del marcador
|
||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
|
SDL_SetRenderDrawColor(renderer_, color_.r, color_.g, color_.b, 255);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
// Copia las texturas de los paneles
|
// Copia las texturas de los paneles
|
||||||
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
||||||
{
|
{
|
||||||
SDL_RenderCopy(renderer, panelTexture[i], nullptr, &panel[i].pos);
|
SDL_RenderCopy(renderer_, panel_texture_[i], nullptr, &panel_[i].pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja la linea que separa la zona de juego del marcador
|
// Dibuja la linea que separa la zona de juego del marcador
|
||||||
renderSeparator();
|
renderSeparator();
|
||||||
|
|
||||||
// Deja el renderizador apuntando donde estaba
|
// Deja el renderizador apuntando donde estaba
|
||||||
SDL_SetRenderTarget(renderer, temp);
|
SDL_SetRenderTarget(renderer_, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recalcula las anclas de los elementos
|
// Recalcula las anclas de los elementos
|
||||||
void Scoreboard::recalculateAnchors()
|
void Scoreboard::recalculateAnchors()
|
||||||
{
|
{
|
||||||
// Recalcula la posición y el tamaño de los paneles
|
// Recalcula la posición y el tamaño de los paneles
|
||||||
const float panelWidth = (float)rect.w / (float)SCOREBOARD_MAX_PANELS;
|
const float panelWidth = (float)rect_.w / (float)SCOREBOARD_MAX_PANELS;
|
||||||
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
||||||
{
|
{
|
||||||
panel[i].pos.x = roundf(panelWidth * i);
|
panel_[i].pos.x = roundf(panelWidth * i);
|
||||||
panel[i].pos.y = 0;
|
panel_[i].pos.y = 0;
|
||||||
panel[i].pos.w = roundf(panelWidth * (i + 1)) - panel[i].pos.x;
|
panel_[i].pos.w = roundf(panelWidth * (i + 1)) - panel_[i].pos.x;
|
||||||
panel[i].pos.h = rect.h;
|
panel_[i].pos.h = rect_.h;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constantes para definir las zonas del panel: 4 filas y 1 columna
|
// Constantes para definir las zonas del panel_: 4 filas y 1 columna
|
||||||
const int rowSize = rect.h / 4;
|
const int rowSize = rect_.h / 4;
|
||||||
const int textHeight = 7;
|
const int textHeight = 7;
|
||||||
|
|
||||||
// Filas
|
// Filas
|
||||||
@@ -408,63 +408,63 @@ void Scoreboard::recalculateAnchors()
|
|||||||
const int col = panelWidth / 2;
|
const int col = panelWidth / 2;
|
||||||
|
|
||||||
// Slots de 4
|
// Slots de 4
|
||||||
slot4_1 = {col, row1};
|
slot4_1_ = {col, row1};
|
||||||
slot4_2 = {col, row2};
|
slot4_2_ = {col, row2};
|
||||||
slot4_3 = {col, row3};
|
slot4_3_ = {col, row3};
|
||||||
slot4_4 = {col, row4};
|
slot4_4_ = {col, row4};
|
||||||
|
|
||||||
// Primer cuadrado para poner el nombre de record
|
// Primer cuadrado para poner el nombre de record
|
||||||
const int enterNameLenght = 8 * 7;
|
const int enterNameLenght = 8 * 7;
|
||||||
enterNamePos.x = (panelWidth - enterNameLenght) / 2;
|
enter_name_pos_.x = (panelWidth - enterNameLenght) / 2;
|
||||||
enterNamePos.y = row4;
|
enter_name_pos_.y = row4;
|
||||||
|
|
||||||
// Recoloca los sprites
|
// Recoloca los sprites
|
||||||
if (powerMeterSprite)
|
if (power_meter_sprite_)
|
||||||
{
|
{
|
||||||
powerMeterSprite->setPosX(slot4_2.x - 20);
|
power_meter_sprite_->setPosX(slot4_2_.x - 20);
|
||||||
powerMeterSprite->setPosY(slot4_2.y);
|
power_meter_sprite_->setPosY(slot4_2_.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el modo del marcador
|
// Establece el modo del marcador
|
||||||
void Scoreboard::setMode(int index, ScoreboardMode mode)
|
void Scoreboard::setMode(int index, ScoreboardMode mode)
|
||||||
{
|
{
|
||||||
panel[index].mode = mode;
|
panel_[index].mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea la textura de fondo
|
// Crea la textura de fondo
|
||||||
void Scoreboard::createBackgroundTexture()
|
void Scoreboard::createBackgroundTexture()
|
||||||
{
|
{
|
||||||
// Elimina la textura en caso de existir
|
// Elimina la textura en caso de existir
|
||||||
if (background)
|
if (background_)
|
||||||
{
|
{
|
||||||
SDL_DestroyTexture(background);
|
SDL_DestroyTexture(background_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recrea la textura de fondo
|
// Recrea la textura de fondo
|
||||||
background = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect.w, rect.h);
|
background_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
|
||||||
SDL_SetTextureBlendMode(background, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(background_, SDL_BLENDMODE_BLEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea las texturas de los paneles
|
// Crea las texturas de los paneles
|
||||||
void Scoreboard::createPanelTextures()
|
void Scoreboard::createPanelTextures()
|
||||||
{
|
{
|
||||||
// Elimina las texturas en caso de existir
|
// Elimina las texturas en caso de existir
|
||||||
for (auto texture : panelTexture)
|
for (auto texture : panel_texture_)
|
||||||
{
|
{
|
||||||
if (texture != nullptr)
|
if (texture != nullptr)
|
||||||
{
|
{
|
||||||
SDL_DestroyTexture(texture);
|
SDL_DestroyTexture(texture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panelTexture.clear();
|
panel_texture_.clear();
|
||||||
|
|
||||||
// Crea las texturas para cada panel
|
// Crea las texturas para cada panel_
|
||||||
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
||||||
{
|
{
|
||||||
SDL_Texture *tex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, panel[i].pos.w, panel[i].pos.h);
|
SDL_Texture *tex = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, panel_[i].pos.w, panel_[i].pos.h);
|
||||||
SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND);
|
||||||
panelTexture.push_back(tex);
|
panel_texture_.push_back(tex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,6 +472,6 @@ void Scoreboard::createPanelTextures()
|
|||||||
void Scoreboard::renderSeparator()
|
void Scoreboard::renderSeparator()
|
||||||
{
|
{
|
||||||
// Dibuja la linea que separa el marcador de la zona de juego
|
// Dibuja la linea que separa el marcador de la zona de juego
|
||||||
SDL_SetRenderDrawColor(renderer, separator_color.r, separator_color.g, separator_color.b, 255);
|
SDL_SetRenderDrawColor(renderer_, separator_color.r, separator_color.g, separator_color.b, 255);
|
||||||
SDL_RenderDrawLine(renderer, 0, 0, rect.w, 0);
|
SDL_RenderDrawLine(renderer_, 0, 0, rect_.w, 0);
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ constexpr int SCOREBOARD_MAX_PANELS = 3;
|
|||||||
constexpr int SCOREBOARD_TICK_SPEED = 100;
|
constexpr int SCOREBOARD_TICK_SPEED = 100;
|
||||||
|
|
||||||
// Enums
|
// Enums
|
||||||
enum class ScoreboardMode
|
enum class ScoreboardMode : int
|
||||||
{
|
{
|
||||||
SCORE,
|
SCORE,
|
||||||
STAGE_INFO,
|
STAGE_INFO,
|
||||||
@@ -32,7 +32,7 @@ enum class ScoreboardMode
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Structs
|
// Structs
|
||||||
struct panel_t
|
struct Panel
|
||||||
{
|
{
|
||||||
ScoreboardMode mode; // Modo en el que se encuentra el panel
|
ScoreboardMode mode; // Modo en el que se encuentra el panel
|
||||||
SDL_Rect pos; // Posición donde dibujar el panel dentro del marcador
|
SDL_Rect pos; // Posición donde dibujar el panel dentro del marcador
|
||||||
@@ -43,38 +43,38 @@ class Scoreboard
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// [SINGLETON] Objeto scoreboard privado para Don Melitón
|
// [SINGLETON] Objeto scoreboard privado para Don Melitón
|
||||||
static Scoreboard *scoreboard;
|
static Scoreboard *scoreboard_;
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
|
|
||||||
std::shared_ptr<Texture> gamePowerMeterTexture; // Textura con el marcador de poder de la fase
|
std::shared_ptr<Texture> game_power_meter_texture_; // Textura con el marcador de poder de la fase
|
||||||
std::unique_ptr<Sprite> powerMeterSprite; // Sprite para el medidor de poder de la fase
|
std::unique_ptr<Sprite> power_meter_sprite_; // Sprite para el medidor de poder de la fase
|
||||||
std::unique_ptr<Text> textScoreBoard; // Fuente para el marcador del juego
|
std::unique_ptr<Text> text_scoreboard_; // Fuente para el marcador del juego
|
||||||
|
|
||||||
SDL_Texture *background; // Textura para dibujar el marcador
|
SDL_Texture *background_; // Textura para dibujar el marcador
|
||||||
std::vector<SDL_Texture *> panelTexture; // Texturas para dibujar cada panel;
|
std::vector<SDL_Texture *> panel_texture_; // Texturas para dibujar cada panel
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int stage; // Número de fase actual
|
std::string name_[SCOREBOARD_MAX_PANELS]; // Nom de cada jugador
|
||||||
std::string name[SCOREBOARD_MAX_PANELS]; // Nom de cada jugador
|
std::string record_name_[SCOREBOARD_MAX_PANELS]; // Nombre introducido para la tabla de records
|
||||||
std::string recordName[SCOREBOARD_MAX_PANELS]; // Nombre introducido para la tabla de records
|
int selector_pos_[SCOREBOARD_MAX_PANELS]; // Posición del selector de letra para introducir el nombre
|
||||||
int selectorPos[SCOREBOARD_MAX_PANELS]; // Posición del selector de letra para introducir el nombre
|
int score_[SCOREBOARD_MAX_PANELS]; // Puntuación de los jugadores
|
||||||
int score[SCOREBOARD_MAX_PANELS]; // Puntuación de los jugadores
|
float mult_[SCOREBOARD_MAX_PANELS]; // Multiplicador de los jugadores
|
||||||
float mult[SCOREBOARD_MAX_PANELS]; // Multiplicador de los jugadores
|
int continue_counter_[SCOREBOARD_MAX_PANELS]; // Tiempo para continuar de los jugadores
|
||||||
int continueCounter[SCOREBOARD_MAX_PANELS]; // Tiempo para continuar de los jugadores
|
Panel panel_[SCOREBOARD_MAX_PANELS]; // Lista con todos los paneles del marcador
|
||||||
int hiScore; // Máxima puntuación
|
int stage_; // Número de fase actual
|
||||||
float power; // Poder actual de la fase
|
int hi_score_; // Máxima puntuación
|
||||||
std::string hiScoreName; // Nombre del jugador con la máxima puntuación
|
float power_; // Poder actual de la fase
|
||||||
Color color; // Color del marcador
|
std::string hi_score_name_; // Nombre del jugador con la máxima puntuación
|
||||||
SDL_Rect rect; // Posición y dimensiones del marcador
|
Color color_; // Color del marcador
|
||||||
panel_t panel[SCOREBOARD_MAX_PANELS]; // Lista con todos los paneles del marcador
|
SDL_Rect rect_; // Posición y dimensiones del marcador
|
||||||
Uint32 ticks; // Variable donde almacenar el valor de SDL_GetTiks()
|
Uint32 ticks_; // Variable donde almacenar el valor de SDL_GetTiks()
|
||||||
int counter; // Contador
|
int counter_; // Contador
|
||||||
|
|
||||||
// Puntos predefinidos para colocar elementos en los paneles
|
// Puntos predefinidos para colocar elementos en los paneles
|
||||||
SDL_Point slot4_1, slot4_2, slot4_3, slot4_4;
|
SDL_Point slot4_1_, slot4_2_, slot4_3_, slot4_4_;
|
||||||
SDL_Point enterNamePos;
|
SDL_Point enter_name_pos_;
|
||||||
|
|
||||||
// Recalcula las anclas de los elementos
|
// Recalcula las anclas de los elementos
|
||||||
void recalculateAnchors();
|
void recalculateAnchors();
|
||||||
@@ -128,7 +128,7 @@ public:
|
|||||||
void setName(int panel, std::string name);
|
void setName(int panel, std::string name);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setRecordName(int panel, std::string recordName);
|
void setRecordName(int panel, std::string record_name);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setSelectorPos(int panel, int pos);
|
void setSelectorPos(int panel, int pos);
|
||||||
@@ -146,7 +146,7 @@ public:
|
|||||||
void setStage(int stage);
|
void setStage(int stage);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setHiScore(int hiScore);
|
void setHiScore(int hi_score);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setPower(float power);
|
void setPower(float power);
|
||||||
|
|||||||
@@ -22,105 +22,101 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
Screen *Screen::screen = nullptr;
|
Screen *Screen::screen_ = nullptr;
|
||||||
|
|
||||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||||
void Screen::init(SDL_Window *window, SDL_Renderer *renderer)
|
void Screen::init(SDL_Window *window, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
Screen::screen = new Screen(window, renderer);
|
Screen::screen_ = new Screen(window, renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||||
void Screen::destroy()
|
void Screen::destroy()
|
||||||
{
|
{
|
||||||
delete Screen::screen;
|
delete Screen::screen_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
||||||
Screen *Screen::get()
|
Screen *Screen::get()
|
||||||
{
|
{
|
||||||
return Screen::screen;
|
return Screen::screen_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||||
: window(window), renderer(renderer)
|
: window_(window), renderer_(renderer)
|
||||||
{
|
{
|
||||||
// Copia punteros
|
|
||||||
input = Input::get();
|
|
||||||
asset = Asset::get();
|
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
srcrect = {0, 0, param.game.width, param.game.height};
|
src_rect_ = {0, 0, param.game.width, param.game.height};
|
||||||
dstrect = {0, 0, param.game.width, param.game.height};
|
dst_rect_ = {0, 0, param.game.width, param.game.height};
|
||||||
borderColor = {0, 0, 0};
|
border_color_ = {0, 0, 0};
|
||||||
flashEffect.enabled = false;
|
flash_effect_.enabled = false;
|
||||||
flashEffect.counter = 0;
|
flash_effect_.counter = 0;
|
||||||
flashEffect.lenght = 0;
|
flash_effect_.lenght = 0;
|
||||||
flashEffect.color = {0xFF, 0xFF, 0xFF};
|
flash_effect_.color = {0xFF, 0xFF, 0xFF};
|
||||||
shakeEffect.enabled = false;
|
shake_effect_.enabled = false;
|
||||||
shakeEffect.desp = 2;
|
shake_effect_.desp = 2;
|
||||||
shakeEffect.delay = 3;
|
shake_effect_.delay = 3;
|
||||||
shakeEffect.counter = 0;
|
shake_effect_.counter = 0;
|
||||||
shakeEffect.lenght = 8;
|
shake_effect_.lenght = 8;
|
||||||
shakeEffect.remaining = 0;
|
shake_effect_.remaining = 0;
|
||||||
shakeEffect.originalPos = 0;
|
shake_effect_.originalPos = 0;
|
||||||
shakeEffect.originalWidth = param.game.width;
|
shake_effect_.originalWidth = param.game.width;
|
||||||
attenuateEffect = false;
|
attenuate_effect_ = false;
|
||||||
fpsTicks = 0;
|
fps_ticks_ = 0;
|
||||||
fpsCounter = 0;
|
fps_counter_ = 0;
|
||||||
fps = 0;
|
fps_ = 0;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
showInfo = true;
|
show_info_ = true;
|
||||||
#else
|
#else
|
||||||
showInfo = false;
|
show_info_ = false;
|
||||||
#endif
|
#endif
|
||||||
SDL_DisplayMode DM;
|
SDL_DisplayMode DM;
|
||||||
SDL_GetCurrentDisplayMode(0, &DM);
|
SDL_GetCurrentDisplayMode(0, &DM);
|
||||||
infoResolution = std::to_string(DM.w) + " X " + std::to_string(DM.h) + " AT " + std::to_string(DM.refresh_rate) + " HZ";
|
info_resolution_ = std::to_string(DM.w) + " X " + std::to_string(DM.h) + " AT " + std::to_string(DM.refresh_rate) + " HZ";
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
notify = std::make_unique<Notify>(renderer, "", asset->get("8bithud.png"), asset->get("8bithud.txt"), asset->get("notify.wav"));
|
notify_ = std::make_unique<Notify>(renderer_, "", Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Asset::get()->get("notify_.wav"));
|
||||||
|
|
||||||
// Define el color del borde para el modo de pantalla completa
|
// Define el color del borde para el modo de pantalla completa
|
||||||
borderColor = {0x00, 0x00, 0x00};
|
border_color_ = {0x00, 0x00, 0x00};
|
||||||
|
|
||||||
// Crea las textura donde se dibujan los graficos del juego
|
// Crea las textura donde se dibujan los graficos del juego
|
||||||
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
game_canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||||
shaderCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
shader_canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
setVideoMode(options.video.mode);
|
setVideoMode(options.video.mode);
|
||||||
|
|
||||||
// Muestra la ventana
|
// Muestra la ventana
|
||||||
SDL_ShowWindow(window);
|
SDL_ShowWindow(window_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Screen::~Screen()
|
Screen::~Screen()
|
||||||
{
|
{
|
||||||
SDL_DestroyTexture(gameCanvas);
|
SDL_DestroyTexture(game_canvas_);
|
||||||
SDL_DestroyTexture(shaderCanvas);
|
SDL_DestroyTexture(shader_canvas_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
void Screen::clean(Color color)
|
void Screen::clean(Color color)
|
||||||
{
|
{
|
||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
void Screen::start()
|
void Screen::start()
|
||||||
{
|
{
|
||||||
SDL_SetRenderTarget(renderer, gameCanvas);
|
SDL_SetRenderTarget(renderer_, game_canvas_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
void Screen::blit()
|
void Screen::blit()
|
||||||
{
|
{
|
||||||
// Actualiza el contador de FPS
|
// Actualiza el contador de FPS
|
||||||
fpsCounter++;
|
fps_counter_++;
|
||||||
|
|
||||||
// Actualiza y dibuja el efecto de flash en la pantalla
|
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||||
doFlash();
|
doFlash();
|
||||||
@@ -135,51 +131,51 @@ void Screen::blit()
|
|||||||
displayInfo();
|
displayInfo();
|
||||||
|
|
||||||
// Muestra las notificaciones
|
// Muestra las notificaciones
|
||||||
notify->render();
|
notify_->render();
|
||||||
|
|
||||||
#ifdef NO_SHADERS
|
#ifdef NO_SHADERS
|
||||||
// Vuelve a dejar el renderizador en modo normal
|
// Vuelve a dejar el renderizador en modo normal
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer_, nullptr);
|
||||||
|
|
||||||
// Borra el contenido previo
|
// Borra el contenido previo
|
||||||
SDL_SetRenderDrawColor(renderer, borderColor.r, borderColor.g, borderColor.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, border_color_.r, border_color_.g, border_color_.b, 0xFF);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||||
if (shakeEffect.enabled)
|
if (shake_effect_.enabled)
|
||||||
SDL_RenderCopy(renderer, gameCanvas, nullptr, nullptr);
|
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr);
|
||||||
SDL_RenderCopy(renderer, gameCanvas, &srcrect, &dstrect);
|
SDL_RenderCopy(renderer_, game_canvas_, &src_rect_, &dst_rect_);
|
||||||
|
|
||||||
// Muestra por pantalla el renderizador
|
// Muestra por pantalla el renderizador
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer_);
|
||||||
#else
|
#else
|
||||||
if (options.video.shaders)
|
if (options.video.shaders)
|
||||||
{
|
{
|
||||||
SDL_SetRenderTarget(renderer, shaderCanvas);
|
SDL_SetRenderTarget(renderer_, shader_canvas_);
|
||||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer_);
|
||||||
if (shakeEffect.enabled)
|
if (shake_effect_.enabled)
|
||||||
SDL_RenderCopy(renderer, gameCanvas, nullptr, nullptr);
|
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr);
|
||||||
SDL_RenderCopy(renderer, gameCanvas, &srcrect, &dstrect);
|
SDL_RenderCopy(renderer_, game_canvas_, &src_rect_, &dst_rect_);
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer_, nullptr);
|
||||||
shader::render();
|
shader::render();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Vuelve a dejar el renderizador en modo normal
|
// Vuelve a dejar el renderizador en modo normal
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer_, nullptr);
|
||||||
|
|
||||||
// Borra el render
|
// Borra el render
|
||||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||||
if (shakeEffect.enabled)
|
if (shake_effect_.enabled)
|
||||||
SDL_RenderCopy(renderer, gameCanvas, nullptr, nullptr);
|
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr);
|
||||||
SDL_RenderCopy(renderer, gameCanvas, &srcrect, &dstrect);
|
SDL_RenderCopy(renderer_, game_canvas_, &src_rect_, &dst_rect_);
|
||||||
|
|
||||||
// Muestra por pantalla el renderizador
|
// Muestra por pantalla el renderizador
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer_);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -197,7 +193,7 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
|
|||||||
case ScreenVideoMode::WINDOW:
|
case ScreenVideoMode::WINDOW:
|
||||||
{
|
{
|
||||||
// Cambia a modo de ventana
|
// Cambia a modo de ventana
|
||||||
SDL_SetWindowFullscreen(window, 0);
|
SDL_SetWindowFullscreen(window_, 0);
|
||||||
|
|
||||||
#ifdef ARCADE
|
#ifdef ARCADE
|
||||||
// Oculta el puntero
|
// Oculta el puntero
|
||||||
@@ -207,8 +203,8 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
|
|||||||
SDL_ShowCursor(SDL_ENABLE);
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
#endif
|
#endif
|
||||||
// Modifica el tamaño de la ventana
|
// Modifica el tamaño de la ventana
|
||||||
SDL_SetWindowSize(window, param.game.width * options.video.window.size, param.game.height * options.video.window.size);
|
SDL_SetWindowSize(window_, param.game.width * options.video.window.size, param.game.height * options.video.window.size);
|
||||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
SDL_SetWindowPosition(window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -217,7 +213,7 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
|
|||||||
case ScreenVideoMode::FULLSCREEN:
|
case ScreenVideoMode::FULLSCREEN:
|
||||||
{
|
{
|
||||||
// Aplica el modo de video
|
// Aplica el modo de video
|
||||||
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
SDL_SetWindowFullscreen(window_, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||||
|
|
||||||
// Oculta el puntero
|
// Oculta el puntero
|
||||||
SDL_ShowCursor(SDL_DISABLE);
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
@@ -233,10 +229,10 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
|
|||||||
if (options.video.shaders)
|
if (options.video.shaders)
|
||||||
{
|
{
|
||||||
#ifndef NO_SHADERS
|
#ifndef NO_SHADERS
|
||||||
std::ifstream f(asset->get("crtpi.glsl").c_str());
|
std::ifstream f(Asset::get()->get("crtpi.glsl").c_str());
|
||||||
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||||
|
|
||||||
shader::init(window, shaderCanvas, source.c_str());
|
shader::init(window_, shader_canvas_, source.c_str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -274,20 +270,20 @@ void Screen::incWindowSize()
|
|||||||
// Cambia el color del borde
|
// Cambia el color del borde
|
||||||
void Screen::setBorderColor(Color color)
|
void Screen::setBorderColor(Color color)
|
||||||
{
|
{
|
||||||
borderColor = color;
|
border_color_ = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el tipo de mezcla
|
// Cambia el tipo de mezcla
|
||||||
void Screen::setBlendMode(SDL_BlendMode blendMode)
|
void Screen::setBlendMode(SDL_BlendMode blendMode)
|
||||||
{
|
{
|
||||||
SDL_SetRenderDrawBlendMode(renderer, blendMode);
|
SDL_SetRenderDrawBlendMode(renderer_, blendMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la lógica de la clase
|
// Actualiza la lógica de la clase
|
||||||
void Screen::update()
|
void Screen::update()
|
||||||
{
|
{
|
||||||
updateShake();
|
updateShakeEffect();
|
||||||
notify->update();
|
notify_->update();
|
||||||
updateFPS();
|
updateFPS();
|
||||||
OnScreenHelp::get()->update();
|
OnScreenHelp::get()->update();
|
||||||
}
|
}
|
||||||
@@ -297,7 +293,7 @@ void Screen::checkInput()
|
|||||||
{
|
{
|
||||||
#ifndef ARCADE
|
#ifndef ARCADE
|
||||||
// Comprueba el teclado para cambiar entre pantalla completa y ventana
|
// Comprueba el teclado para cambiar entre pantalla completa y ventana
|
||||||
if (input->checkInput(input_window_fullscreen, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
if (Input::get()->checkInput(input_window_fullscreen, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||||
{
|
{
|
||||||
switchVideoMode();
|
switchVideoMode();
|
||||||
const std::string mode = options.video.mode == ScreenVideoMode::WINDOW ? "Window" : "Fullscreen";
|
const std::string mode = options.video.mode == ScreenVideoMode::WINDOW ? "Window" : "Fullscreen";
|
||||||
@@ -306,7 +302,7 @@ void Screen::checkInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el teclado para decrementar el tamaño de la ventana
|
// Comprueba el teclado para decrementar el tamaño de la ventana
|
||||||
if (input->checkInput(input_window_dec_size, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
if (Input::get()->checkInput(input_window_dec_size, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||||
{
|
{
|
||||||
decWindowSize();
|
decWindowSize();
|
||||||
const std::string size = std::to_string(options.video.window.size);
|
const std::string size = std::to_string(options.video.window.size);
|
||||||
@@ -315,7 +311,7 @@ void Screen::checkInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el teclado para incrementar el tamaño de la ventana
|
// Comprueba el teclado para incrementar el tamaño de la ventana
|
||||||
if (input->checkInput(input_window_inc_size, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
if (Input::get()->checkInput(input_window_inc_size, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||||
{
|
{
|
||||||
incWindowSize();
|
incWindowSize();
|
||||||
const std::string size = std::to_string(options.video.window.size);
|
const std::string size = std::to_string(options.video.window.size);
|
||||||
@@ -325,7 +321,7 @@ void Screen::checkInput()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Comprueba el teclado para activar o desactivar los shaders
|
// Comprueba el teclado para activar o desactivar los shaders
|
||||||
if (input->checkInput(input_video_shaders, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
if (Input::get()->checkInput(input_video_shaders, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||||
{
|
{
|
||||||
switchShaders();
|
switchShaders();
|
||||||
return;
|
return;
|
||||||
@@ -333,26 +329,26 @@ void Screen::checkInput()
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// Comprueba el teclado para mostrar la información de debug
|
// Comprueba el teclado para mostrar la información de debug
|
||||||
if (input->checkInput(input_showinfo, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
if (Input::get()->checkInput(input_showinfo, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||||
{
|
{
|
||||||
showInfo = !showInfo;
|
show_info_ = !show_info_;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (int i = 0; i < input->getNumControllers(); ++i)
|
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
||||||
{
|
{
|
||||||
// Comprueba los mandos para activar o desactivar los shaders
|
// Comprueba los mandos para activar o desactivar los shaders
|
||||||
if (input->checkModInput(input_service, input_video_shaders, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkModInput(input_service, input_video_shaders, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
switchShaders();
|
switchShaders();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los mandos para mostrar la información de debug
|
// Comprueba los mandos para mostrar la información de debug
|
||||||
if (input->checkModInput(input_service, input_showinfo, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkModInput(input_service, input_showinfo, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
showInfo = !showInfo;
|
show_info_ = !show_info_;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -362,43 +358,43 @@ void Screen::checkInput()
|
|||||||
void Screen::shake()
|
void Screen::shake()
|
||||||
{
|
{
|
||||||
// Si no hay un shake effect activo, se guarda una copia de los valores actuales antes de modificarlos
|
// Si no hay un shake effect activo, se guarda una copia de los valores actuales antes de modificarlos
|
||||||
if (!shakeEffect.enabled)
|
if (!shake_effect_.enabled)
|
||||||
{
|
{
|
||||||
shakeEffect.enabled = true;
|
shake_effect_.enabled = true;
|
||||||
shakeEffect.originalPos = srcrect.x;
|
shake_effect_.originalPos = src_rect_.x;
|
||||||
shakeEffect.originalWidth = srcrect.w;
|
shake_effect_.originalWidth = src_rect_.w;
|
||||||
srcrect.w -= shakeEffect.desp;
|
src_rect_.w -= shake_effect_.desp;
|
||||||
dstrect.w = srcrect.w;
|
dst_rect_.w = src_rect_.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si ya hay un shake effect en marcha no se pilla el origen, solo se renuevan los contadores
|
// Si ya hay un shake effect en marcha no se pilla el origen, solo se renuevan los contadores
|
||||||
shakeEffect.remaining = shakeEffect.lenght;
|
shake_effect_.remaining = shake_effect_.lenght;
|
||||||
shakeEffect.counter = shakeEffect.delay;
|
shake_effect_.counter = shake_effect_.delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la logica para agitar la pantalla
|
// Actualiza la logica para agitar la pantalla
|
||||||
void Screen::updateShake()
|
void Screen::updateShakeEffect()
|
||||||
{
|
{
|
||||||
if (shakeEffect.enabled)
|
if (shake_effect_.enabled)
|
||||||
{
|
{
|
||||||
if (shakeEffect.counter > 0)
|
if (shake_effect_.counter > 0)
|
||||||
{
|
{
|
||||||
shakeEffect.counter--;
|
shake_effect_.counter--;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shakeEffect.counter = shakeEffect.delay;
|
shake_effect_.counter = shake_effect_.delay;
|
||||||
const auto srcdesp = shakeEffect.remaining % 2 == 0 ? 0 : shakeEffect.desp;
|
const auto srcdesp = shake_effect_.remaining % 2 == 0 ? 0 : shake_effect_.desp;
|
||||||
const auto dstdesp = shakeEffect.remaining % 2 == 1 ? 0 : shakeEffect.desp;
|
const auto dstdesp = shake_effect_.remaining % 2 == 1 ? 0 : shake_effect_.desp;
|
||||||
srcrect.x = shakeEffect.originalPos + srcdesp;
|
src_rect_.x = shake_effect_.originalPos + srcdesp;
|
||||||
dstrect.x = shakeEffect.originalPos + dstdesp;
|
dst_rect_.x = shake_effect_.originalPos + dstdesp;
|
||||||
shakeEffect.remaining--;
|
shake_effect_.remaining--;
|
||||||
shakeEffect.enabled = shakeEffect.remaining == -1 ? false : true;
|
shake_effect_.enabled = shake_effect_.remaining == -1 ? false : true;
|
||||||
if (!shakeEffect.enabled)
|
if (!shake_effect_.enabled)
|
||||||
{
|
{
|
||||||
srcrect.x = shakeEffect.originalPos;
|
src_rect_.x = shake_effect_.originalPos;
|
||||||
srcrect.w = shakeEffect.originalWidth;
|
src_rect_.w = shake_effect_.originalWidth;
|
||||||
dstrect = srcrect;
|
dst_rect_ = src_rect_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -407,39 +403,39 @@ void Screen::updateShake()
|
|||||||
// Pone la pantalla de color
|
// Pone la pantalla de color
|
||||||
void Screen::flash(Color color, int lenght)
|
void Screen::flash(Color color, int lenght)
|
||||||
{
|
{
|
||||||
flashEffect.enabled = true;
|
flash_effect_.enabled = true;
|
||||||
flashEffect.counter = 0;
|
flash_effect_.counter = 0;
|
||||||
flashEffect.lenght = lenght;
|
flash_effect_.lenght = lenght;
|
||||||
flashEffect.color = color;
|
flash_effect_.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza y dibuja el efecto de flash en la pantalla
|
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||||
void Screen::doFlash()
|
void Screen::doFlash()
|
||||||
{
|
{
|
||||||
if (flashEffect.enabled)
|
if (flash_effect_.enabled)
|
||||||
{
|
{
|
||||||
// Dibuja el color del flash en la textura
|
// Dibuja el color del flash en la textura
|
||||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
SDL_Texture *temp = SDL_GetRenderTarget(renderer_);
|
||||||
SDL_SetRenderTarget(renderer, gameCanvas);
|
SDL_SetRenderTarget(renderer_, game_canvas_);
|
||||||
SDL_SetRenderDrawColor(renderer, flashEffect.color.r, flashEffect.color.g, flashEffect.color.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, flash_effect_.color.r, flash_effect_.color.g, flash_effect_.color.b, 0xFF);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer_);
|
||||||
SDL_SetRenderTarget(renderer, temp);
|
SDL_SetRenderTarget(renderer_, temp);
|
||||||
|
|
||||||
// Actualiza la lógica del efecto
|
// Actualiza la lógica del efecto
|
||||||
flashEffect.counter < flashEffect.lenght ? flashEffect.counter++ : flashEffect.enabled = false;
|
flash_effect_.counter < flash_effect_.lenght ? flash_effect_.counter++ : flash_effect_.enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Atenua la pantalla
|
// Atenua la pantalla
|
||||||
void Screen::doAttenuate()
|
void Screen::doAttenuate()
|
||||||
{
|
{
|
||||||
if (attenuateEffect)
|
if (attenuate_effect_)
|
||||||
{
|
{
|
||||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
SDL_Texture *temp = SDL_GetRenderTarget(renderer_);
|
||||||
SDL_SetRenderTarget(renderer, gameCanvas);
|
SDL_SetRenderTarget(renderer_, game_canvas_);
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 64);
|
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 64);
|
||||||
SDL_RenderFillRect(renderer, nullptr);
|
SDL_RenderFillRect(renderer_, nullptr);
|
||||||
SDL_SetRenderTarget(renderer, temp);
|
SDL_SetRenderTarget(renderer_, temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,50 +451,50 @@ void Screen::switchShaders()
|
|||||||
// Atenua la pantalla
|
// Atenua la pantalla
|
||||||
void Screen::attenuate(bool value)
|
void Screen::attenuate(bool value)
|
||||||
{
|
{
|
||||||
attenuateEffect = value;
|
attenuate_effect_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Muestra una notificación de texto por pantalla;
|
// Muestra una notificación de texto por pantalla;
|
||||||
void Screen::showNotification(std::string text1, std::string text2, int icon)
|
void Screen::showNotification(std::string text1, std::string text2, int icon)
|
||||||
{
|
{
|
||||||
notify->showText(text1, text2, icon);
|
notify_->showText(text1, text2, icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el puntero al renderizador
|
// Obtiene el puntero al renderizador
|
||||||
SDL_Renderer *Screen::getRenderer()
|
SDL_Renderer *Screen::getRenderer()
|
||||||
{
|
{
|
||||||
return renderer;
|
return renderer_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcula los frames por segundo
|
// Calcula los frames por segundo
|
||||||
void Screen::updateFPS()
|
void Screen::updateFPS()
|
||||||
{
|
{
|
||||||
if (SDL_GetTicks() - fpsTicks > 1000)
|
if (SDL_GetTicks() - fps_ticks_ > 1000)
|
||||||
{
|
{
|
||||||
fpsTicks = SDL_GetTicks();
|
fps_ticks_ = SDL_GetTicks();
|
||||||
fps = fpsCounter;
|
fps_ = fps_counter_;
|
||||||
fpsCounter = 0;
|
fps_counter_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Muestra información por pantalla
|
// Muestra información por pantalla
|
||||||
void Screen::displayInfo()
|
void Screen::displayInfo()
|
||||||
{
|
{
|
||||||
if (showInfo)
|
if (show_info_)
|
||||||
{
|
{
|
||||||
// FPS
|
// FPS
|
||||||
const std::string fpstext = std::to_string(fps) + " FPS";
|
const std::string fpstext = std::to_string(fps_) + " FPS";
|
||||||
dbg_print(param.game.width - fpstext.length() * 8, 0, fpstext.c_str(), 255, 255, 0);
|
dbg_print(param.game.width - fpstext.length() * 8, 0, fpstext.c_str(), 255, 255, 0);
|
||||||
|
|
||||||
// Resolution
|
// Resolution
|
||||||
dbg_print(0, 0, infoResolution.c_str(), 255, 255, 0);
|
dbg_print(0, 0, info_resolution_.c_str(), 255, 255, 0);
|
||||||
|
|
||||||
dbg_print(0, 8, std::to_string(globalInputs::servicePressedCounter[0]).c_str(), 255, 255, 0);
|
dbg_print(0, 8, std::to_string(globalInputs::servicePressedCounter[0]).c_str(), 255, 255, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indica si hay alguna notificación activa en pantalla
|
// Indica si hay alguna notificación activa en pantalla
|
||||||
bool Screen::notificationsAreActive()
|
bool Screen::notificationsAreActive() const
|
||||||
{
|
{
|
||||||
return notify->active();
|
return notify_->active();
|
||||||
}
|
}
|
||||||
@@ -8,17 +8,15 @@
|
|||||||
#include <string> // for basic_string, string
|
#include <string> // for basic_string, string
|
||||||
#include "utils.h" // for Color
|
#include "utils.h" // for Color
|
||||||
#include <memory>
|
#include <memory>
|
||||||
class Asset;
|
|
||||||
class Input;
|
|
||||||
class Notify;
|
class Notify;
|
||||||
|
|
||||||
enum class ScreenFilter
|
enum class ScreenFilter : int
|
||||||
{
|
{
|
||||||
NEAREST = 0,
|
NEAREST = 0,
|
||||||
LINEAL = 1,
|
LINEAL = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class ScreenVideoMode
|
enum class ScreenVideoMode : int
|
||||||
{
|
{
|
||||||
WINDOW = 0,
|
WINDOW = 0,
|
||||||
FULLSCREEN = 1,
|
FULLSCREEN = 1,
|
||||||
@@ -28,29 +26,27 @@ class Screen
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// [SINGLETON] Objeto screen privado para Don Melitón
|
// [SINGLETON] Objeto screen privado para Don Melitón
|
||||||
static Screen *screen;
|
static Screen *screen_;
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Window *window; // Ventana de la aplicación
|
SDL_Window *window_; // Ventana de la aplicación
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
Asset *asset; // Objeto con el listado de recursos
|
std::unique_ptr<Notify> notify_; // Pinta notificaciones en pantalla
|
||||||
Input *input; // Objeto para leer las entradas de teclado o mando
|
SDL_Texture *game_canvas_; // Textura donde se dibuja todo antes de volcarse al renderizador
|
||||||
std::unique_ptr<Notify> notify; // Pinta notificaciones en pantalla
|
SDL_Texture *shader_canvas_; // Textura para pasarle al shader desde gameCanvas
|
||||||
SDL_Texture *gameCanvas; // Textura donde se dibuja todo antes de volcarse al renderizador
|
|
||||||
SDL_Texture *shaderCanvas; // Textura para pasarle al shader desde gameCanvas
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
SDL_Rect srcrect; // Coordenadas de donde va a pillar la textura del juego para dibujarla
|
SDL_Rect src_rect_; // Coordenadas de donde va a pillar la textura del juego para dibujarla
|
||||||
SDL_Rect dstrect; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
SDL_Rect dst_rect_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
||||||
Color borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
Color border_color_; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||||
bool attenuateEffect; // Indica si la pantalla ha de estar atenuada
|
bool attenuate_effect_; // Indica si la pantalla ha de estar atenuada
|
||||||
Uint32 fpsTicks; // Ticks para contar los frames por segundo
|
Uint32 fps_ticks_; // Ticks para contar los frames por segundo
|
||||||
int fpsCounter; // Contador de frames por segundo
|
int fps_counter_; // Contador de frames por segundo
|
||||||
int fps; // Frames calculados en el último segundo
|
int fps_; // Frames calculados en el último segundo
|
||||||
bool showInfo; // Indica si ha de mostrar/ocultar la información de la pantalla
|
bool show_info_; // Indica si ha de mostrar/ocultar la información de la pantalla
|
||||||
std::string infoResolution; // Texto con la informacion de la pantalla
|
std::string info_resolution_; // Texto con la informacion de la pantalla
|
||||||
|
|
||||||
struct effect_t
|
struct FlashEffect
|
||||||
{
|
{
|
||||||
bool enabled; // Indica si el efecto está activo
|
bool enabled; // Indica si el efecto está activo
|
||||||
int counter; // Contador para el efecto
|
int counter; // Contador para el efecto
|
||||||
@@ -58,10 +54,7 @@ private:
|
|||||||
Color color; // Color del efecto
|
Color color; // Color del efecto
|
||||||
};
|
};
|
||||||
|
|
||||||
// Variables - Efectos
|
struct ShakeEffect
|
||||||
effect_t flashEffect; // Variable para gestionar el efecto de flash
|
|
||||||
|
|
||||||
struct shake_t
|
|
||||||
{
|
{
|
||||||
int desp; // Pixels de desplazamiento para agitar la pantalla en el eje x
|
int desp; // Pixels de desplazamiento para agitar la pantalla en el eje x
|
||||||
int delay; // Retraso entre cada desplazamiento de la pantalla al agitarse
|
int delay; // Retraso entre cada desplazamiento de la pantalla al agitarse
|
||||||
@@ -71,10 +64,14 @@ private:
|
|||||||
int originalPos; // Posición inicial de la pantalla para dejarla igual tras el desplazamiento
|
int originalPos; // Posición inicial de la pantalla para dejarla igual tras el desplazamiento
|
||||||
int originalWidth; // Anchura inicial de la pantalla para dejarla igual tras el desplazamiento
|
int originalWidth; // Anchura inicial de la pantalla para dejarla igual tras el desplazamiento
|
||||||
bool enabled; // Indica si el efecto está activo
|
bool enabled; // Indica si el efecto está activo
|
||||||
} shakeEffect;
|
};
|
||||||
|
|
||||||
|
// Variables - Efectos
|
||||||
|
FlashEffect flash_effect_; // Variable para gestionar el efecto de flash
|
||||||
|
ShakeEffect shake_effect_; // Variable para gestionar el efecto de agitar la pantalla
|
||||||
|
|
||||||
// Actualiza la logica para agitar la pantalla
|
// Actualiza la logica para agitar la pantalla
|
||||||
void updateShake();
|
void updateShakeEffect();
|
||||||
|
|
||||||
// Actualiza y dibuja el efecto de flash en la pantalla
|
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||||
void doFlash();
|
void doFlash();
|
||||||
@@ -122,7 +119,7 @@ public:
|
|||||||
void blit();
|
void blit();
|
||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
void setVideoMode(ScreenVideoMode videoMode);
|
void setVideoMode(ScreenVideoMode video_mode);
|
||||||
|
|
||||||
// Camibia entre pantalla completa y ventana
|
// Camibia entre pantalla completa y ventana
|
||||||
void switchVideoMode();
|
void switchVideoMode();
|
||||||
@@ -140,7 +137,7 @@ public:
|
|||||||
void setBorderColor(Color color);
|
void setBorderColor(Color color);
|
||||||
|
|
||||||
// Cambia el tipo de mezcla
|
// Cambia el tipo de mezcla
|
||||||
void setBlendMode(SDL_BlendMode blendMode);
|
void setBlendMode(SDL_BlendMode blend_mode);
|
||||||
|
|
||||||
// Agita la pantalla
|
// Agita la pantalla
|
||||||
void shake();
|
void shake();
|
||||||
@@ -158,7 +155,7 @@ public:
|
|||||||
void showNotification(std::string text1 = "", std::string text2 = "", int icon = -1);
|
void showNotification(std::string text1 = "", std::string text2 = "", int icon = -1);
|
||||||
|
|
||||||
// Indica si hay alguna notificación activa en pantalla
|
// Indica si hay alguna notificación activa en pantalla
|
||||||
bool notificationsAreActive();
|
bool notificationsAreActive() const;
|
||||||
|
|
||||||
// Obtiene el puntero al renderizador
|
// Obtiene el puntero al renderizador
|
||||||
SDL_Renderer *getRenderer();
|
SDL_Renderer *getRenderer();
|
||||||
|
|||||||
Reference in New Issue
Block a user