Skip to content

Commit

Permalink
made menu gud :)
Browse files Browse the repository at this point in the history
  • Loading branch information
namanyt committed Mar 15, 2022
1 parent c7b4f83 commit 723ad4b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
---

### TODO
- [ ] Make Menus
- [X] Make Menus
- [ ] Add Sounds :)
Binary file added content/Fonts/FlappyBirdy.ttf
Binary file not shown.
76 changes: 58 additions & 18 deletions src/Game/Scenes/MainMenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Scene*>* 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() {
Expand All @@ -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);
}
};
10 changes: 7 additions & 3 deletions src/Game/Utilities/Button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 723ad4b

Please sign in to comment.