From 591bf972f6a7d0fd01e7017cba5c3e288fdd21cd Mon Sep 17 00:00:00 2001 From: Alma Dejus Date: Mon, 13 Nov 2023 11:35:53 +0100 Subject: [PATCH] edited start menu, Alma + Malin --- src/States.cc | 43 +++++++++++++++++++++++++++++++++++++++---- src/States.h | 11 +++++++++-- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/States.cc b/src/States.cc index 012042a..00cd9c1 100644 --- a/src/States.cc +++ b/src/States.cc @@ -50,14 +50,44 @@ void Game_state::handle_input(sf::Event& event) player.handle_input(event); } -Start_menu::Start_menu() : texture{}, sprite{}, exit_menu{false} +Start_menu::Start_menu() : texture{}, sprite{}, exit_menu{false}, gametitle{}, starttext{}, scoreboardtext{}, quittext{}, font{} { - texture.loadFromFile("assets/sack.png"); + //sprite + texture.loadFromFile("assets/meny_bild.png"); sprite.setTexture(texture); + sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF); sf::FloatRect gb {sprite.getGlobalBounds()}; - sprite.setOrigin(gb.width / 2, gb.height / 2); - sprite.setPosition(S_WIDTH / 2, S_HEIGHT / 2); // hej + sprite.setPosition(0, 0); + + + //load textfont + if ( !font.loadFromFile ("assets/fonts/ComicNeue-Bold.ttf") ) + throw std::invalid_argument ("Unable to load font"); + + //start + starttext = sf::Text{ "Start Game", font, 24 }; + sf::FloatRect gbts {starttext.getGlobalBounds()}; + starttext.setOrigin(gbts.width / 2, gbts.height / 2); + starttext.setPosition ((S_WIDTH) / 2, ((S_HEIGHT / 2) - 100)); + starttext.setFillColor(sf::Color::Black); + + //score + scoreboardtext = sf::Text{ "Scoreboard", font, 24 }; + sf::FloatRect gbtb {scoreboardtext.getGlobalBounds()}; + scoreboardtext.setOrigin(gbtb.width / 2, gbtb.height / 2); + scoreboardtext.setPosition (S_WIDTH / 2, ((S_HEIGHT / 2) - 50)); + scoreboardtext.setFillColor(sf::Color::Black); + + //quit + quittext = sf::Text{ "Quit", font, 24 }; + sf::FloatRect gbtq {quittext.getGlobalBounds()}; + quittext.setOrigin(gbtq.width / 2, gbtq.height / 2); + quittext.setPosition (S_WIDTH / 2, S_HEIGHT / 2); + quittext.setFillColor(sf::Color::Black); + + + } void Start_menu::update(Context& context) @@ -71,6 +101,11 @@ void Start_menu::update(Context& context) void Start_menu::render(sf::RenderWindow& window) const { window.draw(sprite); + + window.draw(gametitle); + window.draw(starttext); + window.draw(scoreboardtext); + window.draw(quittext); } void Start_menu::handle_input(sf::Event& event) diff --git a/src/States.h b/src/States.h index 8664b0f..fbefefb 100644 --- a/src/States.h +++ b/src/States.h @@ -1,12 +1,13 @@ #ifndef STATES_H #define STATES_H +#include #include "SFML/Graphics.hpp" #include "Map.h" #include "Player.h" -struct Context; //finns en strukt som säger att Context finns innan den är deklarerad +struct Context; class State { @@ -26,9 +27,9 @@ public: void update(Context& context) override; void render(sf::RenderWindow& window) const override; void handle_input(sf::Event& event) override; + Map game_map; protected: private: - Map game_map; Player player; bool pause_game; }; @@ -45,6 +46,11 @@ public: private: sf::Texture texture; sf::Sprite sprite; + sf::Text gametitle; + sf::Text starttext; + sf::Text scoreboardtext; + sf::Text quittext; + sf::Font font; bool exit_menu; }; @@ -63,4 +69,5 @@ private: bool exit_game; }; + #endif \ No newline at end of file -- 2.30.2