Fixed merge conflicts, Nils, Lukas, Stina, Malin, Alma, Arvid
authorlukel495 <lukel495@su15-111.ad.liu.se>
Wed, 15 Nov 2023 13:52:33 +0000 (14:52 +0100)
committerlukel495 <lukel495@su15-111.ad.liu.se>
Wed, 15 Nov 2023 13:52:33 +0000 (14:52 +0100)
1  2 
src/States.cc
src/States.h

diff --cc src/States.cc
index 28269a028bffc806b74989878883e722147d9b6f,708530a907df5b2645fdbd3dff52e285ac6f9b1a..ee4a815fdf116a133eb4adb73c62dc22b0813bca
@@@ -114,42 -48,155 +114,155 @@@ void Game_state::handle_input(sf::Even
          break;
      }
  
 -    player.handle_input(event);
 +    player->handle_input(event);
  }
  
- Start_menu::Start_menu() : texture{}, sprite{}, exit_menu{false}
- {
-     texture.loadFromFile("assets/sack.png");
+ // Start menu --------------------------------------------
+ Start_menu::Start_menu() : texture{},  texture2{}, sprite{}, mouse_l{}, mouse_r{}, start_game{false}, exit_game{false}, menu_index{1},
+                            starttext{}, scoreboardtext{}, quittext{}, font{}
+ {                         
+     //sprite
+     texture.loadFromFile("assets/meny_bild.png");
      sprite.setTexture(texture);
  
-     sf::FloatRect gb{sprite.getGlobalBounds()};
-     sprite.setOrigin(gb.width / 2, gb.height / 2);
-     sprite.setPosition(S_WIDTH / 2, S_HEIGHT / 2);
+     sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF);
+     sf::FloatRect gb {sprite.getGlobalBounds()};
+     sprite.setPosition(0, 0); 
+     //mouse
+     texture2.loadFromFile("assets/muspekareGul.png");
+     mouse_l.setTexture(texture2);
+     mouse_l.setScale(0.1, 0.1);
+     mouse_l.setRotation(180);
+     sf::FloatRect gbm {mouse_l.getGlobalBounds()};
+     mouse_r.setTexture(texture2);
+     mouse_r.setScale(0.1, 0.1);
+     //load textfont
+     if ( !font.loadFromFile ("assets/fonts/Philosopher-Regular.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));
+     //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));
+     //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);
  }
  
 -void Start_menu::update(Contextcontext)
 +void Start_menu::update(Context &context)
  {
-     if (exit_menu)
+     if (start_game)
      {
          context.next_state = std::make_unique<Game_state>();
      }
+     if( menu_index == 1)
+     {
+         starttext.setFillColor(sf::Color::Yellow);
+         scoreboardtext.setFillColor(sf::Color::Black);
+         quittext.setFillColor(sf::Color::Black);  
+     }
+     else if( menu_index == 2)
+     {
+         starttext.setFillColor(sf::Color::Black);
+         scoreboardtext.setFillColor(sf::Color::Yellow);
+         quittext.setFillColor(sf::Color::Black);  
+     }
+         else if( menu_index == 3)
+     {
+         starttext.setFillColor(sf::Color::Black);
+         scoreboardtext.setFillColor(sf::Color::Black);
+         quittext.setFillColor(sf::Color::Yellow);  
+     }
+     // mouse placement
+     mouse_r.setPosition(((S_WIDTH / 2) + 60), ((S_HEIGHT / 2) - 115 + 50*(menu_index - 1)));
+     mouse_l.setPosition(((S_WIDTH / 2) - 58), ((S_HEIGHT / 2) - 68 + 50*(menu_index - 1))); 
+     
  }
  
 -void Start_menu::render(sf::RenderWindowwindow) const
 +void Start_menu::render(sf::RenderWindow &window) const
  {
      window.draw(sprite);
+     window.draw(mouse_l);
+     window.draw(mouse_r);
+     window.draw(starttext);
+     window.draw(scoreboardtext);
+     window.draw(quittext);
+     if (exit_game)
+     {
+         window.close();
+     }
  }
  
 -void Start_menu::handle_input(sf::Eventevent)
 +void Start_menu::handle_input(sf::Event &event)
  {
      switch (event.type)
      {
      case sf::Event::KeyPressed:
 -        switch(event.key.code)
 +        switch (event.key.code)
          {
          case sf::Keyboard::Enter:
-             exit_menu = true;
+             if(menu_index == 1)
+             {
+                start_game = true; 
+                menu_index = 1;
+             }
+             else if(menu_index == 2)
+             {
+                menu_index = 1;
+             }
+             else if(menu_index == 3)
+             {
+                exit_game = true;
+                menu_index = 1;
+             }
+             break;
+         
+         case sf::Keyboard::Up:
+             if(menu_index == 1)
+             {
+                 break;    
+             }
+             else;
+             {
+                menu_index -= 1;
+             }
+             break;
+         case sf::Keyboard::Down:
+             if(menu_index == 3)
+             {
+                 break;
+             }
+             else;
+             {
+                 menu_index += 1;
+             }
              break;
          default:
              break;
          }
      }
  }
  
- Pause_menu::Pause_menu() : texture{}, sprite{}, resume_game{false}, exit_game{false}
+ // Pause menu --------------------------------------------
+ Pause_menu::Pause_menu() : texture{}, texture2{}, sprite{}, resume_game{false}, menu{false}, exit_game{false}, 
+                            resumetext{}, startmenutext{}, quittext{}, mouse_r{}, mouse_l{}, font{}, menu_index{1}
  {
-     texture.loadFromFile("assets/kir.png");
-     sprite.setTexture(texture);
+     texture.loadFromFile("assets/Pause_bild.png");
+     sprite.setTexture(texture);;
+     sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF);
+     sf::FloatRect gb {sprite.getGlobalBounds()};
+     sprite.setPosition(0, 0);
+     // mouse
+     texture2.loadFromFile("assets/muspekareGul.png");
+     mouse_l.setTexture(texture2);
+     mouse_l.setScale(0.1, 0.1);
+     mouse_l.setRotation(180);
+     sf::FloatRect gbm {mouse_l.getGlobalBounds()};
+     mouse_r.setTexture(texture2);
+     mouse_r.setScale(0.1, 0.1);
+     //load textfont
+     if ( !font.loadFromFile ("assets/fonts/Philosopher-Regular.ttf") )
+         throw std::invalid_argument ("Unable to load font");
  
-     sf::FloatRect gb{sprite.getGlobalBounds()};
-     sprite.setOrigin(gb.width / 2, gb.height / 2);
-     sprite.setPosition(S_WIDTH / 2, S_HEIGHT / 2);
+     // Resume text
+     resumetext = sf::Text{ "Resume", font, 24 };
+     sf::FloatRect gbr {resumetext.getGlobalBounds()};
+     resumetext.setOrigin(gbr.width / 2, gbr.height / 2);
+     resumetext.setPosition (S_WIDTH / 2, ((S_HEIGHT / 2) - 30));
+     // Start menu text
+     startmenutext = sf::Text{ "Start menu", font, 24 };
+     sf::FloatRect gbs {startmenutext.getGlobalBounds()};
+     startmenutext.setOrigin(gbs.width / 2, gbs.height / 2);
+     startmenutext.setPosition (S_WIDTH / 2, ((S_HEIGHT / 2) + 20));
+     //quit text
+     quittext = sf::Text{ "Quit", font, 24 };
+     sf::FloatRect gbq {quittext.getGlobalBounds()};
+     quittext.setOrigin(gbq.width / 2, gbq.height / 2 );
+     quittext.setPosition (S_WIDTH / 2, ((S_HEIGHT / 2) + 70));
  }
  
 -void Pause_menu::update(Contextcontext)
 +void Pause_menu::update(Context &context)
  {
      if (resume_game)
      {
          context.next_state = std::make_unique<Start_menu>();
          context.saved_game.release();
      }
+  
+     // changes color on text depending on selection
+     if( menu_index == 1)
+     {
+         resumetext.setFillColor(sf::Color::Yellow);
+         startmenutext.setFillColor(sf::Color::Black);
+         quittext.setFillColor(sf::Color::Black);  
+     }
+     else if( menu_index == 2)
+     {
+         resumetext.setFillColor(sf::Color::Black);
+         startmenutext.setFillColor(sf::Color::Yellow);
+         quittext.setFillColor(sf::Color::Black);  
+     }
+         else if( menu_index == 3)
+     {
+         resumetext.setFillColor(sf::Color::Black);
+         startmenutext.setFillColor(sf::Color::Black);
+         quittext.setFillColor(sf::Color::Yellow);  
+     }
+     // mouse placement
+     mouse_r.setPosition(((S_WIDTH / 2) + 60), ((S_HEIGHT / 2) - 45 + 50*(menu_index - 1)));
+     mouse_l.setPosition(((S_WIDTH / 2) - 58), ((S_HEIGHT / 2) + 2 + 50*(menu_index - 1))); 
  }
  
 -void Pause_menu::render(sf::RenderWindowwindow) const
 +void Pause_menu::render(sf::RenderWindow &window) const
  {
      window.draw(sprite);
+     window.draw(mouse_l);
+     window.draw(mouse_r);
+     window.draw(resumetext);
+     window.draw(startmenutext);
+     window.draw(quittext);
+     if (exit_game)
+     {
+         window.close();
+     }
  }
  
 -void Pause_menu::handle_input(sf::Eventevent)
 +void Pause_menu::handle_input(sf::Event &event)
  {
      switch (event.type)
      {
      case sf::Event::KeyPressed:
 -        switch(event.key.code)
 +        switch (event.key.code)
          {
          case sf::Keyboard::Enter:
-             resume_game = true;
+             if(menu_index == 1)
+             {
+                 resume_game = true; 
+                 menu_index = 1;
+             }
+             else if(menu_index == 2)
+             {
+                 menu = true;
+                 menu_index = 1;
+             }
+             else if(menu_index == 3)
+             {
+                 exit_game = true;
+                 menu_index = 1;
+             }
              break;
-         case sf::Keyboard::Escape:
-             exit_game = true;
+         
+         case sf::Keyboard::Up:
+             if(menu_index == 1)
+             {
+                 break;    
+             }
+             else;
+             {
+                menu_index -= 1;
+             }
              break;
+         case sf::Keyboard::Down:
+             if(menu_index == 3)
+             {
+                 break;
+             }
+             else;
+             {
+                 menu_index += 1;
+             }
+             break;
          default:
              break;
          }
diff --cc src/States.h
index 49cb532b24b1317e380c15a02bf795d9b3c94d5b,85e4ac1b59989be199613229ca418313e3f4afcb..52d0090128c58aa4f1814a1570a1e1a8b67b3376
@@@ -1,22 -1,13 +1,23 @@@
  #ifndef STATES_H
  #define STATES_H
  
+ #include <memory>
  #include "SFML/Graphics.hpp"
 +#include <vector>
 +#include <memory>
  
  #include "Map.h"
  #include "Player.h"
 +#include "Main_enemy.h"
 +#include "Helper.h"
 +#include "Bottle.h"
 +#include "json.hpp"
 +
 +using json = nlohmann::json;
 +
 +
  
- struct Context; //finns en strukt som säger att Context finns innan den är deklarerad
+ struct Context;
  
  class State
  {