From 723ad4beb1fc13fa017a576f14a4d7c5684f6310 Mon Sep 17 00:00:00 2001 From: Cider Date: Tue, 15 Mar 2022 17:27:29 +0530 Subject: [PATCH] made menu gud :) --- README.md | 2 +- content/Fonts/FlappyBirdy.ttf | Bin 0 -> 9720 bytes src/Game/Scenes/MainMenu.hpp | 76 ++++++++++++++++++++++++++-------- src/Game/Utilities/Button.hpp | 10 +++-- 4 files changed, 66 insertions(+), 22 deletions(-) create mode 100644 content/Fonts/FlappyBirdy.ttf diff --git a/README.md b/README.md index 1241c0e..41cfd3b 100644 --- a/README.md +++ b/README.md @@ -3,5 +3,5 @@ --- ### TODO -- [ ] Make Menus +- [X] Make Menus - [ ] Add Sounds :) diff --git a/content/Fonts/FlappyBirdy.ttf b/content/Fonts/FlappyBirdy.ttf new file mode 100644 index 0000000000000000000000000000000000000000..3b99ecc6c314fa4c6db3056f70bcc533c588b808 GIT binary patch literal 9720 zcmbta349#YdH-fsw{5&aUfZ!TenP&uq?P4M29vQdGR6j9U>q!9R)-~7*IHUzwnNCo zNeMYojuMhy)3l`_z0~v|O;b8)-8L;WQCr#qA;|>DMMEOafQfhV|Gs&%J1gY=T>4h? zpKspG`|kI>w>u((h-Q&P2}g~>S8C%*~G4`uC*7c&J?3D2o=vQzo>mAG; z-?9P}84m!S8yN1)eB$}f%pE$Y z3T#F~GcDo7WYk)vrPD~sA403SGP}2^- z^qO!<1~-~buU7?#P$zWG#9uC_$Do;B=91^B~%OgV!@?!A!sF7Pj$f=x`gHd8w8h8 z3iNWp6*M38O5hu`iWUGbrG>!D1TUv|fWAWTN?H`WPK|<1v>0?+u$e9by_%K)TLjn8 z#lg>Mt>8LZ3VOZZ22!9~sUEly_!?bBmjJI8+(ZqauMvDFEdy-{Zl>kItF(ny0IwC? zN-IHMC)h@-KyL%SLf6x!!0mJy@CLyhbUEmqf;Z9?!OL`$;4Zon^lrgD)ChVnH39bt z-c0G>CAvj$KQ)8CRqz0<2K_E-0p13Dkq*)tV7uV$v=;Oof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!ko26y{Vb$#9y5=_us-z2Ao@aI9TyJFaWm}h zrybzXjNI*~1GwIV5AS=p9pYbwW@xQgDEQxo5?BMy|IK47GT|z$2%E5OTnB5mAxF03 x|21~t|1@sI|7YyN|7Glf)%)mX{13){tSATYKNq**9bP-#UUt(hJ9k2rUjhias!{*| literal 0 HcmV?d00001 diff --git a/src/Game/Scenes/MainMenu.hpp b/src/Game/Scenes/MainMenu.hpp index 5a0aa4e..acf9c93 100644 --- a/src/Game/Scenes/MainMenu.hpp +++ b/src/Game/Scenes/MainMenu.hpp @@ -2,27 +2,57 @@ #include "GameScene.hpp" class MainMenu : public Scene { - sf::RectangleShape background; - sf::Font font; + sf::Texture background; + sf::Sprite backgroundSprite; + sf::Font button_font; + sf::Font Title_font; sf::Text text; - Button* button; + Button* play_button; + Button* exit_button; + + bool hoverd_text = false; public: MainMenu(sf::RenderWindow* window, std::stack* scenes) : Scene(window, scenes) { - this->font.loadFromFile("content/Fonts/Dosis-Light.ttf"); + this->button_font.loadFromFile("content/Fonts/PixellettersFull.ttf"); + this->Title_font.loadFromFile("content/Fonts/FlappyBirdy.ttf"); + + this->text.setFont(this->Title_font); + this->text.setString("Flappy Bird"); + this->text.setStyle(this->text.Bold); + this->text.setFillColor(sf::Color::Black); + this->text.setCharacterSize(100); + this->text.setPosition(sf::Vector2f( + (this->window->getSize().x / 2.f) - this->text.getGlobalBounds().width / 2.f, + (this->window->getSize().y / 2.f) - this->text.getGlobalBounds().height / 2.f - 200 + )); - this->background.setSize(sf::Vector2f(window->getSize().x, window->getSize().y)); - this->background.setFillColor(sf::Color::Magenta); + if (!background.loadFromFile("content/Textures/bg.jpeg")) {} + background.setRepeated(true); + backgroundSprite.setTexture(background); + backgroundSprite.setScale(1.f, 1.2f); + backgroundSprite.setTextureRect({ 0, 0, 800 + 284, 600 }); - this->button = new Button(100, 100, 150, 50, - &this->font, "New Game", - sf::Color(70, 70, 70, 200), sf::Color(150, 150, 150, 255), sf::Color(20, 20, 20, 200)); + this->play_button = new Button( + this->window->getSize().x / 2.f, this->window->getSize().y / 2.f + 50, 200, 50, + &this->button_font, "Play Game", + sf::Color(70, 70, 70, 200), + sf::Color(150, 150, 150, 255), + sf::Color(20, 20, 20, 200)); + + this->exit_button = new Button( + this->window->getSize().x / 2.f, this->window->getSize().y / 2.f + 150, 150, 50, + &this->button_font, "Exit", + sf::Color(70, 70, 70, 200), + sf::Color(150, 150, 150, 255), + sf::Color(20, 20, 20, 200)); } virtual ~MainMenu() { - delete this->button; + delete this->play_button; + delete this->exit_button; } void exitScene() { @@ -34,21 +64,31 @@ class MainMenu : public Scene { this->checkForQuit(); this->updateMousePosition(); - // for (auto it : this->buttons) it.second->update(this->mousePosView); - this->button->update(this->mousePosView); + this->play_button->update(this->mousePosView); + this->exit_button->update(this->mousePosView); - if (this->button->isPressed()) { - // std::cout << "Pressed" << std::endl; - // this->exit = true; + if (this->play_button->isPressed()) { this->scenes->push(new GameScene(this->window, this->scenes)); } + + if (this->exit_button->isPressed()) { + this->exit = true; + } + + if (this->backgroundSprite.getPosition().x < -283) { + this->backgroundSprite.setPosition(0, 0); + } + else { + this->backgroundSprite.setPosition(this->backgroundSprite.getPosition().x - 1.f, 0); + } } void render(sf::RenderTarget* target = NULL) { if (!target) target = this->window; - // for (auto it : this->buttons) it.second->render(target); - target->draw(this->background); - this->button->render(target); + target->draw(this->backgroundSprite); + target->draw(this->text); + this->play_button->render(target); + this->exit_button->render(target); } }; diff --git a/src/Game/Utilities/Button.hpp b/src/Game/Utilities/Button.hpp index 969c6b9..d401127 100644 --- a/src/Game/Utilities/Button.hpp +++ b/src/Game/Utilities/Button.hpp @@ -30,17 +30,21 @@ class Button { sf::Color activeColor) { this->state = IDLE; - this->shape.setPosition(sf::Vector2f(x, y)); this->shape.setSize(sf::Vector2f(width, height)); + this->shape.setPosition(sf::Vector2f( + this->shape.getSize().x / -2 + x, + this->shape.getSize().y / -2 + y + )); + this->font = font; this->text.setFont(*this->font); this->text.setString(text); this->text.setFillColor(sf::Color::White); - this->text.setCharacterSize(12); + this->text.setCharacterSize(50); this->text.setPosition( this->shape.getPosition().x + (this->shape.getGlobalBounds().width / 2.f) - this->text.getGlobalBounds().width / 2.f, - this->shape.getPosition().y + (this->shape.getGlobalBounds().height / 2.f) - this->text.getGlobalBounds().height / 2.f + this->shape.getPosition().y + (this->shape.getGlobalBounds().height / 2.f) - this->text.getGlobalBounds().height / 2.f - 25 ); this->CIdle = idleColor;