afegides notificacions per als inputs externs al joc
This commit is contained in:
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
Binary file not shown.
@@ -10,7 +10,7 @@ Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapF
|
|||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->options = options;
|
this->options = options;
|
||||||
bgColor = options->notification.color;
|
bgColor = options->notification.color;
|
||||||
waitTime = 300;
|
waitTime = 100;
|
||||||
|
|
||||||
// Crea objetos
|
// Crea objetos
|
||||||
iconTexture = new Texture(renderer, iconFile);
|
iconTexture = new Texture(renderer, iconFile);
|
||||||
@@ -151,17 +151,20 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
|||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
const int iconSize = 16;
|
const int iconSize = 16;
|
||||||
const int padding = text->getCharacterSize();
|
const int paddingOut = 1;
|
||||||
const int iconSpace = icon >= 0 ? iconSize + padding : 0;
|
const int paddingIn = text->getCharacterSize() / 2;
|
||||||
|
const int iconSpace = icon >= 0 ? iconSize + paddingIn : 0;
|
||||||
const std::string txt = text1.length() > text2.length() ? text1 : text2;
|
const std::string txt = text1.length() > text2.length() ? text1 : text2;
|
||||||
const int width = text->lenght(txt) + (padding * 2) + iconSpace;
|
const int width = text->lenght(txt) + (paddingIn * 2) + iconSpace;
|
||||||
const int height = (text->getCharacterSize() * 2) + (padding * 2);
|
const int numTexts = text2 == "" ? 1 : 2;
|
||||||
|
const int height = (text->getCharacterSize() * numTexts) + (paddingIn * 2);
|
||||||
|
const notification_shape_t shape = notification_shape_squared;
|
||||||
|
|
||||||
// Posición horizontal
|
// Posición horizontal
|
||||||
int despH = 0;
|
int despH = 0;
|
||||||
if (options->notification.posH == pos_left)
|
if (options->notification.posH == pos_left)
|
||||||
{
|
{
|
||||||
despH = padding;
|
despH = paddingOut;
|
||||||
}
|
}
|
||||||
else if (options->notification.posH == pos_middle)
|
else if (options->notification.posH == pos_middle)
|
||||||
{
|
{
|
||||||
@@ -169,21 +172,21 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
despH = options->video.gameWidth - width - padding;
|
despH = options->video.gameWidth - width - paddingOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Posición vertical
|
// Posición vertical
|
||||||
int despV = 0;
|
int despV = 0;
|
||||||
if (options->notification.posV == pos_top)
|
if (options->notification.posV == pos_top)
|
||||||
{
|
{
|
||||||
despV = padding;
|
despV = paddingOut;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
despV = options->video.gameHeight - height - padding;
|
despV = options->video.gameHeight - height - paddingOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int travelDist = height + padding;
|
const int travelDist = height + paddingOut;
|
||||||
|
|
||||||
// Offset
|
// Offset
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
@@ -206,6 +209,7 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
|||||||
n.state = ns_rising;
|
n.state = ns_rising;
|
||||||
n.text1 = text1;
|
n.text1 = text1;
|
||||||
n.text2 = text2;
|
n.text2 = text2;
|
||||||
|
n.shape = shape;
|
||||||
if (options->notification.posV == pos_top)
|
if (options->notification.posV == pos_top)
|
||||||
{
|
{
|
||||||
n.rect = {despH, offset - travelDist, width, height};
|
n.rect = {despH, offset - travelDist, width, height};
|
||||||
@@ -226,23 +230,32 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
|||||||
// Dibuja el fondo de la notificación
|
// Dibuja el fondo de la notificación
|
||||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||||
SDL_Rect rect;
|
SDL_Rect rect;
|
||||||
rect = {4, 0, width - (4 * 2), height};
|
if (shape == notification_shape_rounded)
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
{
|
||||||
|
rect = {4, 0, width - (4 * 2), height};
|
||||||
|
SDL_RenderFillRect(renderer, &rect);
|
||||||
|
|
||||||
rect = {4 / 2, 1, width - 4, height - 2};
|
rect = {4 / 2, 1, width - 4, height - 2};
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer, &rect);
|
||||||
|
|
||||||
rect = {1, 4 / 2, width - 2, height - 4};
|
rect = {1, 4 / 2, width - 2, height - 4};
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer, &rect);
|
||||||
|
|
||||||
|
rect = {0, 4, width, height - (4 * 2)};
|
||||||
|
SDL_RenderFillRect(renderer, &rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (shape == notification_shape_squared)
|
||||||
|
{
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
rect = {0, 4, width, height - (4 * 2)};
|
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
|
||||||
|
|
||||||
// Dibuja el icono de la notificación
|
// Dibuja el icono de la notificación
|
||||||
if (icon >= 0)
|
if (icon >= 0 && numTexts == 2)
|
||||||
{
|
{
|
||||||
Sprite *sp = new Sprite({0, 0, iconSize, iconSize}, iconTexture);
|
Sprite *sp = new Sprite({0, 0, iconSize, iconSize}, iconTexture);
|
||||||
sp->setPos({padding, padding, iconSize, iconSize});
|
sp->setPos({paddingIn, paddingIn, iconSize, iconSize});
|
||||||
sp->setSpriteClip({iconSize * (icon % 10), iconSize * (icon / 10), iconSize, iconSize});
|
sp->setSpriteClip({iconSize * (icon % 10), iconSize * (icon / 10), iconSize, iconSize});
|
||||||
sp->render();
|
sp->render();
|
||||||
delete sp;
|
delete sp;
|
||||||
@@ -250,21 +263,21 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
|||||||
|
|
||||||
// Escribe el texto de la notificación
|
// Escribe el texto de la notificación
|
||||||
color_t color = {255, 255, 255};
|
color_t color = {255, 255, 255};
|
||||||
if (text2 != "")
|
if (numTexts == 2)
|
||||||
{ // Dos lineas de texto
|
{ // Dos lineas de texto
|
||||||
text->writeColored(padding + iconSpace, padding, text1, color);
|
text->writeColored(paddingIn + iconSpace, paddingIn, text1, color);
|
||||||
text->writeColored(padding + iconSpace, padding + text->getCharacterSize() + 1, text2, color);
|
text->writeColored(paddingIn + iconSpace, paddingIn + text->getCharacterSize() + 1, text2, color);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // Una linea de texto
|
{ // Una linea de texto
|
||||||
text->writeColored(padding + iconSpace, (height / 2) - (text->getCharacterSize() / 2), text1, color);
|
text->writeColored(paddingIn + iconSpace, paddingIn, text1, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deja de dibujar en la textura
|
// Deja de dibujar en la textura
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer, nullptr);
|
||||||
|
|
||||||
// Crea el sprite de la notificación
|
// Crea el sprite de la notificación
|
||||||
n.sprite = new Sprite(n.rect, n.texture, renderer);
|
n.sprite = new Sprite(n.rect, n.texture);
|
||||||
|
|
||||||
// Deja la notificación invisible
|
// Deja la notificación invisible
|
||||||
n.texture->setAlpha(0);
|
n.texture->setAlpha(0);
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ private:
|
|||||||
bottomRight
|
bottomRight
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum notification_shape_t
|
||||||
|
{
|
||||||
|
notification_shape_rounded,
|
||||||
|
notification_shape_squared,
|
||||||
|
};
|
||||||
|
|
||||||
struct notification_t
|
struct notification_t
|
||||||
{
|
{
|
||||||
std::string text1;
|
std::string text1;
|
||||||
@@ -46,6 +52,7 @@ private:
|
|||||||
SDL_Rect rect;
|
SDL_Rect rect;
|
||||||
int y;
|
int y;
|
||||||
int travelDist;
|
int travelDist;
|
||||||
|
notification_shape_t shape;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *
|
|||||||
shakeEffect.origin = 0;
|
shakeEffect.origin = 0;
|
||||||
attenuateEffect = false;
|
attenuateEffect = false;
|
||||||
|
|
||||||
|
// Crea los objetos
|
||||||
|
notify = new Notify(renderer, asset->get("notify.png"), asset->get("8bithud.png"), asset->get("8bithud.txt"), asset->get("notify.wav"), options);
|
||||||
|
|
||||||
// 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};
|
borderColor = {0x00, 0x00, 0x00};
|
||||||
|
|
||||||
@@ -53,6 +56,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *
|
|||||||
// Destructor
|
// Destructor
|
||||||
Screen::~Screen()
|
Screen::~Screen()
|
||||||
{
|
{
|
||||||
|
delete notify;
|
||||||
SDL_DestroyTexture(gameCanvas);
|
SDL_DestroyTexture(gameCanvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +236,7 @@ void Screen::setVideoMode(int videoMode)
|
|||||||
// Camibia entre pantalla completa y ventana
|
// Camibia entre pantalla completa y ventana
|
||||||
void Screen::switchVideoMode()
|
void Screen::switchVideoMode()
|
||||||
{
|
{
|
||||||
options->video.mode = (options->video.mode == VIDEO_MODE_WINDOW) ? VIDEO_MODE_FULLSCREEN : VIDEO_MODE_WINDOW;
|
options->video.mode = options->video.mode == VIDEO_MODE_WINDOW ? VIDEO_MODE_FULLSCREEN : VIDEO_MODE_WINDOW;
|
||||||
setVideoMode(options->video.mode);
|
setVideoMode(options->video.mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,21 +313,29 @@ void Screen::checkInput()
|
|||||||
if (input->checkInput(input_window_fullscreen, DO_NOT_ALLOW_REPEAT))
|
if (input->checkInput(input_window_fullscreen, DO_NOT_ALLOW_REPEAT))
|
||||||
{
|
{
|
||||||
switchVideoMode();
|
switchVideoMode();
|
||||||
|
const std::string mode = options->video.mode == VIDEO_MODE_WINDOW ? "Window" : "Fullscreen";
|
||||||
|
showNotification(mode + " mode");
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkInput(input_window_dec_size, DO_NOT_ALLOW_REPEAT))
|
else if (input->checkInput(input_window_dec_size, DO_NOT_ALLOW_REPEAT))
|
||||||
{
|
{
|
||||||
decWindowSize();
|
decWindowSize();
|
||||||
|
const std::string size = std::to_string(options->video.window.size);
|
||||||
|
showNotification("Window size x" + size);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkInput(input_window_inc_size, DO_NOT_ALLOW_REPEAT))
|
else if (input->checkInput(input_window_inc_size, DO_NOT_ALLOW_REPEAT))
|
||||||
{
|
{
|
||||||
incWindowSize();
|
incWindowSize();
|
||||||
|
const std::string size = std::to_string(options->video.window.size);
|
||||||
|
showNotification("Window size x" + size);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkInput(input_video_shaders, DO_NOT_ALLOW_REPEAT))
|
else if (input->checkInput(input_video_shaders, DO_NOT_ALLOW_REPEAT))
|
||||||
{
|
{
|
||||||
switchShaders();
|
switchShaders();
|
||||||
|
const std::string value = options->video.shaders ? "on" : "off";
|
||||||
|
showNotification("Shaders " + value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ bool Director::setFileList()
|
|||||||
asset->add(prefix + "/data/config/gamecontrollerdb.txt", t_data);
|
asset->add(prefix + "/data/config/gamecontrollerdb.txt", t_data);
|
||||||
|
|
||||||
// Notificaciones
|
// Notificaciones
|
||||||
asset->add(prefix + "/data/notifications/notify.png", t_bitmap);
|
asset->add(prefix + "/data/notification/notify.png", t_bitmap);
|
||||||
|
|
||||||
// Musicas
|
// Musicas
|
||||||
asset->add(prefix + "/data/music/intro.ogg", t_music);
|
asset->add(prefix + "/data/music/intro.ogg", t_music);
|
||||||
@@ -308,8 +308,6 @@ bool Director::setFileList()
|
|||||||
asset->add(prefix + "/data/sound/hiscore.wav", t_sound);
|
asset->add(prefix + "/data/sound/hiscore.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/itemdrop.wav", t_sound);
|
asset->add(prefix + "/data/sound/itemdrop.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/itempickup.wav", t_sound);
|
asset->add(prefix + "/data/sound/itempickup.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/menu_move.wav", t_sound);
|
|
||||||
asset->add(prefix + "/data/sound/menu_select.wav", t_sound);
|
|
||||||
asset->add(prefix + "/data/sound/player_collision.wav", t_sound);
|
asset->add(prefix + "/data/sound/player_collision.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/stage_change.wav", t_sound);
|
asset->add(prefix + "/data/sound/stage_change.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/title.wav", t_sound);
|
asset->add(prefix + "/data/sound/title.wav", t_sound);
|
||||||
|
|||||||
@@ -1899,9 +1899,6 @@ void Game::update()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
if (counter == 0)
|
|
||||||
createPowerBall();
|
|
||||||
|
|
||||||
// Actualiza el contador de juego
|
// Actualiza el contador de juego
|
||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
@@ -2136,6 +2133,7 @@ void Game::checkInput()
|
|||||||
else if (input->checkInput(input_reset, DO_NOT_ALLOW_REPEAT))
|
else if (input->checkInput(input_reset, DO_NOT_ALLOW_REPEAT))
|
||||||
{
|
{
|
||||||
section->name = SECTION_PROG_LOGO;
|
section->name = SECTION_PROG_LOGO;
|
||||||
|
screen->showNotification("Reset");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2615,12 +2613,14 @@ bool Game::allPlayersAreDead()
|
|||||||
// Comprueba los eventos que hay en cola
|
// Comprueba los eventos que hay en cola
|
||||||
void Game::checkEvents()
|
void Game::checkEvents()
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
|
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
|
||||||
|
|
||||||
if (keyStates[SDL_SCANCODE_H] != 0)
|
if (keyStates[SDL_SCANCODE_H] != 0)
|
||||||
{
|
{
|
||||||
createItemScoreSprite(param->gameWidth / 2, param->gameWidth / 2, n1000Sprite);
|
createItemScoreSprite(param->gameWidth / 2, param->gameWidth / 2, n1000Sprite);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
while (SDL_PollEvent(eventHandler) != 0)
|
while (SDL_PollEvent(eventHandler) != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ void HiScoreTable::update()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
|
// Actualiza el objeto screen
|
||||||
|
screen->update();
|
||||||
|
|
||||||
// Actualiza el fondo
|
// Actualiza el fondo
|
||||||
background->update();
|
background->update();
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ void Instructions::iniSprites()
|
|||||||
for (int i = 0; i < (int)itemTextures.size(); ++i)
|
for (int i = 0; i < (int)itemTextures.size(); ++i)
|
||||||
{
|
{
|
||||||
Sprite *sprite = new Sprite(0, 0, param->itemSize, param->itemSize, itemTextures[i]);
|
Sprite *sprite = new Sprite(0, 0, param->itemSize, param->itemSize, itemTextures[i]);
|
||||||
sprite->setPos({spritePos.x, spritePos.y + ((param->itemSize + itemSpace) * i)});
|
sprite->setPos((SDL_Point){spritePos.x, spritePos.y + ((param->itemSize + itemSpace) * i)});
|
||||||
sprites.push_back(sprite);
|
sprites.push_back(sprite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -229,6 +229,9 @@ void Instructions::update()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
|
// Actualiza el objeto screen
|
||||||
|
screen->update();
|
||||||
|
|
||||||
// Incrementa el contador
|
// Incrementa el contador
|
||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
|
|||||||
@@ -375,6 +375,9 @@ void Intro::update()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
|
// Actualiza el objeto screen
|
||||||
|
screen->update();
|
||||||
|
|
||||||
// Actualiza los objetos
|
// Actualiza los objetos
|
||||||
for (auto bitmap : bitmaps)
|
for (auto bitmap : bitmaps)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -244,6 +244,9 @@ void Logo::update()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
|
// Actualiza el objeto screen
|
||||||
|
screen->update();
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
checkInput();
|
checkInput();
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,9 @@ void Title::update()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
|
// Actualiza el objeto screen
|
||||||
|
screen->update();
|
||||||
|
|
||||||
// Actualiza el objeto 'defineButtons'
|
// Actualiza el objeto 'defineButtons'
|
||||||
defineButtons->update();
|
defineButtons->update();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user