diff --git a/data/notifications/notify.png b/data/notification/notify.png similarity index 100% rename from data/notifications/notify.png rename to data/notification/notify.png diff --git a/data/sound/menu_move.wav b/data/sound/menu_move.wav deleted file mode 100644 index 6503184..0000000 Binary files a/data/sound/menu_move.wav and /dev/null differ diff --git a/data/sound/menu_select.wav b/data/sound/menu_select.wav deleted file mode 100644 index 7475499..0000000 Binary files a/data/sound/menu_select.wav and /dev/null differ diff --git a/source/common/notify.cpp b/source/common/notify.cpp index 28e63ad..354d47c 100644 --- a/source/common/notify.cpp +++ b/source/common/notify.cpp @@ -10,7 +10,7 @@ Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapF this->renderer = renderer; this->options = options; bgColor = options->notification.color; - waitTime = 300; + waitTime = 100; // Crea objetos iconTexture = new Texture(renderer, iconFile); @@ -151,17 +151,20 @@ void Notify::showText(std::string text1, std::string text2, int icon) { // Inicializa variables const int iconSize = 16; - const int padding = text->getCharacterSize(); - const int iconSpace = icon >= 0 ? iconSize + padding : 0; + const int paddingOut = 1; + 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 int width = text->lenght(txt) + (padding * 2) + iconSpace; - const int height = (text->getCharacterSize() * 2) + (padding * 2); + const int width = text->lenght(txt) + (paddingIn * 2) + iconSpace; + 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 int despH = 0; if (options->notification.posH == pos_left) { - despH = padding; + despH = paddingOut; } else if (options->notification.posH == pos_middle) { @@ -169,21 +172,21 @@ void Notify::showText(std::string text1, std::string text2, int icon) } else { - despH = options->video.gameWidth - width - padding; + despH = options->video.gameWidth - width - paddingOut; } // Posición vertical int despV = 0; if (options->notification.posV == pos_top) { - despV = padding; + despV = paddingOut; } else { - despV = options->video.gameHeight - height - padding; + despV = options->video.gameHeight - height - paddingOut; } - const int travelDist = height + padding; + const int travelDist = height + paddingOut; // Offset int offset = 0; @@ -206,6 +209,7 @@ void Notify::showText(std::string text1, std::string text2, int icon) n.state = ns_rising; n.text1 = text1; n.text2 = text2; + n.shape = shape; if (options->notification.posV == pos_top) { 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 SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255); SDL_Rect rect; - rect = {4, 0, width - (4 * 2), height}; - SDL_RenderFillRect(renderer, &rect); + if (shape == notification_shape_rounded) + { + rect = {4, 0, width - (4 * 2), height}; + SDL_RenderFillRect(renderer, &rect); - rect = {4 / 2, 1, width - 4, height - 2}; - SDL_RenderFillRect(renderer, &rect); + rect = {4 / 2, 1, width - 4, height - 2}; + SDL_RenderFillRect(renderer, &rect); - rect = {1, 4 / 2, width - 2, height - 4}; - SDL_RenderFillRect(renderer, &rect); + rect = {1, 4 / 2, width - 2, height - 4}; + 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 - if (icon >= 0) + if (icon >= 0 && numTexts == 2) { 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->render(); delete sp; @@ -250,21 +263,21 @@ void Notify::showText(std::string text1, std::string text2, int icon) // Escribe el texto de la notificación color_t color = {255, 255, 255}; - if (text2 != "") + if (numTexts == 2) { // Dos lineas de texto - text->writeColored(padding + iconSpace, padding, text1, color); - text->writeColored(padding + iconSpace, padding + text->getCharacterSize() + 1, text2, color); + text->writeColored(paddingIn + iconSpace, paddingIn, text1, color); + text->writeColored(paddingIn + iconSpace, paddingIn + text->getCharacterSize() + 1, text2, color); } else { // 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 SDL_SetRenderTarget(renderer, nullptr); // 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 n.texture->setAlpha(0); diff --git a/source/common/notify.h b/source/common/notify.h index d73a0b6..8f7fc71 100644 --- a/source/common/notify.h +++ b/source/common/notify.h @@ -34,6 +34,12 @@ private: bottomRight }; + enum notification_shape_t + { + notification_shape_rounded, + notification_shape_squared, + }; + struct notification_t { std::string text1; @@ -46,6 +52,7 @@ private: SDL_Rect rect; int y; int travelDist; + notification_shape_t shape; }; // Objetos y punteros diff --git a/source/common/screen.cpp b/source/common/screen.cpp index 32efdb3..a0113ce 100644 --- a/source/common/screen.cpp +++ b/source/common/screen.cpp @@ -37,6 +37,9 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input * shakeEffect.origin = 0; 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 borderColor = {0x00, 0x00, 0x00}; @@ -53,6 +56,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input * // Destructor Screen::~Screen() { + delete notify; SDL_DestroyTexture(gameCanvas); } @@ -232,7 +236,7 @@ void Screen::setVideoMode(int videoMode) // Camibia entre pantalla completa y ventana 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); } @@ -309,21 +313,29 @@ void Screen::checkInput() if (input->checkInput(input_window_fullscreen, DO_NOT_ALLOW_REPEAT)) { 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)) { 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)) { 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)) { switchShaders(); + const std::string value = options->video.shaders ? "on" : "off"; + showNotification("Shaders " + value); } } diff --git a/source/director.cpp b/source/director.cpp index 2446e7d..a3d691a 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -290,7 +290,7 @@ bool Director::setFileList() asset->add(prefix + "/data/config/gamecontrollerdb.txt", t_data); // Notificaciones - asset->add(prefix + "/data/notifications/notify.png", t_bitmap); + asset->add(prefix + "/data/notification/notify.png", t_bitmap); // Musicas 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/itemdrop.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/stage_change.wav", t_sound); asset->add(prefix + "/data/sound/title.wav", t_sound); diff --git a/source/game.cpp b/source/game.cpp index eb76c77..6cb377f 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1899,9 +1899,6 @@ void Game::update() // Actualiza el contador de ticks ticks = SDL_GetTicks(); - if (counter == 0) - createPowerBall(); - // Actualiza el contador de juego counter++; @@ -2136,6 +2133,7 @@ void Game::checkInput() else if (input->checkInput(input_reset, DO_NOT_ALLOW_REPEAT)) { section->name = SECTION_PROG_LOGO; + screen->showNotification("Reset"); return; } @@ -2615,12 +2613,14 @@ bool Game::allPlayersAreDead() // Comprueba los eventos que hay en cola void Game::checkEvents() { +#ifdef DEBUG const Uint8 *keyStates = SDL_GetKeyboardState(nullptr); if (keyStates[SDL_SCANCODE_H] != 0) { createItemScoreSprite(param->gameWidth / 2, param->gameWidth / 2, n1000Sprite); } +#endif while (SDL_PollEvent(eventHandler) != 0) { diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index 9526d70..877ec82 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -68,6 +68,9 @@ void HiScoreTable::update() // Actualiza el contador de ticks ticks = SDL_GetTicks(); + // Actualiza el objeto screen + screen->update(); + // Actualiza el fondo background->update(); diff --git a/source/instructions.cpp b/source/instructions.cpp index 9f24e31..f326636 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -99,7 +99,7 @@ void Instructions::iniSprites() for (int i = 0; i < (int)itemTextures.size(); ++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); } } @@ -229,6 +229,9 @@ void Instructions::update() // Actualiza el contador de ticks ticks = SDL_GetTicks(); + // Actualiza el objeto screen + screen->update(); + // Incrementa el contador counter++; diff --git a/source/intro.cpp b/source/intro.cpp index cc3d959..434a92d 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -375,6 +375,9 @@ void Intro::update() // Actualiza el contador de ticks ticks = SDL_GetTicks(); + // Actualiza el objeto screen + screen->update(); + // Actualiza los objetos for (auto bitmap : bitmaps) { diff --git a/source/logo.cpp b/source/logo.cpp index 5ea6633..945c6f6 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -244,6 +244,9 @@ void Logo::update() // Actualiza el contador de ticks ticks = SDL_GetTicks(); + // Actualiza el objeto screen + screen->update(); + // Comprueba las entradas checkInput(); diff --git a/source/title.cpp b/source/title.cpp index 917e821..3ca17a4 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -81,6 +81,9 @@ void Title::update() // Actualiza el contador de ticks ticks = SDL_GetTicks(); + // Actualiza el objeto screen + screen->update(); + // Actualiza el objeto 'defineButtons' defineButtons->update();