switch (event.joystickButton.button)
{
case 0: // A
-- if(menu_index == 1)
-- {
- load_to_csv(playerText);
- load_to_csv();
-- menu = true;
-- menu_index = 1;
-- }
--
-- else if(menu_index == 2)
-- {
-- exit_game = true;
-- menu_index = 1;
-- }
++ if_enter();
break;
-- default:
--
++
++ default:
break;
}
--
break;
++
case sf::Event::JoystickMoved:
switch(event.joystickMove.axis)
{
case sf::Joystick::PovY:
if (event.joystickMove.position <= -50)
{
-- if(menu_index == 1)
-- {
-- break;
-- }
--
-- else
-- {
-- menu_index -= 1;
-- }
++ if_up();
break;
}
else if (event.joystickMove.position >= 50)
{
-- if(menu_index == 2)
-- {
-- break;
-- }
--
-- else
-- {
-- menu_index += 1;
-- }
++ if_down();
break;
}
break;
-
+ default:
+ break;
}
break;
case sf::Event::KeyPressed:
switch(event.key.code)
{
case sf::Keyboard::Enter:
--
-- if(menu_index == 1)
-- {
- load_to_csv(playerText);
- load_to_csv();
-- menu = true;
-- menu_index = 1;
-- }
--
-- else if(menu_index == 2)
-- {
-- exit_game = true;
-- menu_index = 1;
-- }
++ if_enter();
break;
--
--
case sf::Keyboard::Up:
-- if(menu_index == 1)
-- {
-- break;
-- }
--
-- else
-- {
-- menu_index -= 1;
-- }
++ if_up();
break;
case sf::Keyboard::Down:
-- if(menu_index == 2)
-- {
-- break;
-- }
--
-- else
-- {
-- menu_index += 1;
-- }
++ if_down();
break;
default:
break;
}
++ break;
+
++ case sf::Event::TextEntered:
+
++ text_input(event);
break;
default:
break;
}
++}
-- // enter name
-- if (event.type == sf::Event::TextEntered)
++void GameOver_menu::text_input(sf::Event& event)
++{
++ // delete last charakter with backspace
++ if (sf::Keyboard::isKeyPressed( sf::Keyboard::Backspace ))
{
-- // delete last charakter with backspace
-- if (sf::Keyboard::isKeyPressed( sf::Keyboard::Backspace ))
++ if(!playerInput.isEmpty())
{
-- if(!playerInput.isEmpty())
-- {
-- playerInput.erase(playerInput.getSize() - 1, 1);
-- }
--
-- else
-- {
-- return;
-- }
--
++ playerInput.erase(playerInput.getSize() - 1, 1);
}
- // if not backspace, print letters
- else if(playerInput.getSize() < 20)
+
- // if not backspace, print letters
- else if(playerInput.getSize() < 20)
++ else
{
-- playerInput += event.text.unicode;
++ return;
}
- playerText.setString(playerInput);
+
- playerText.setString(playerInput);
-
}
-
-
++ // if not backspace, print letters
++ else if(playerInput.getSize() < 20)
++ {
++ playerInput += event.text.unicode;
++ }
++ playerText.setString(playerInput);
}
//spara namn till fil
std::ofstream highscore_file_w{data["game_constants"]["highscore_file"].get<std::string>()};
for (std::string::size_type line_count{0}; line_count < lines_write.size(); highscore_file_w << lines_write[line_count++] << std::endl);
highscore_file_w.close();
++}
++
++
++void GameOver_menu::if_enter()
++{
++ if(menu_index == 1)
++ {
++ load_to_csv();
++ menu = true;
++ menu_index = 1;
++ }
++
++ else if(menu_index == 2)
++ {
++ exit_game = true;
++ menu_index = 1;
++ }
++}
++
++void GameOver_menu::if_up()
++{
++ if(menu_index == 1)
++ {
++ return;
++ }
++ else
++ {
++ menu_index -= 1;
++ }
++}
++
++void GameOver_menu::if_down()
++{
++ if(menu_index == 2)
++ {
++ return;
++ }
++
++ else
++ {
++ menu_index += 1;
++ }
}
switch (event.joystickButton.button)
{
case 0: // A
-- 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;
-- }
++ if_enter();
break;
default:
case sf::Joystick::PovY:
if (event.joystickMove.position <= -50)
{
-- if(menu_index == 1)
-- {
-- break;
-- }
--
-- else
-- {
-- menu_index -= 1;
-- }
-- break;
++ if_up();
}
else if (event.joystickMove.position >= 50)
{
-- if(menu_index == 3)
-- {
-- break;
-- }
--
-- else
-- {
-- menu_index += 1;
-- }
-- break;
++ if_down();
}
break;
+ default:
+ break;
}
break;
case sf::Event::KeyPressed:
switch(event.key.code)
{
case sf::Keyboard::Enter:
-- 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;
-- }
++ if_enter();
break;
case sf::Keyboard::Up:
-- if(menu_index == 1)
-- {
-- break;
-- }
--
-- else
-- {
-- menu_index -= 1;
-- }
++ if_up();
break;
case sf::Keyboard::Down:
-- if(menu_index == 3)
-- {
-- break;
-- }
--
-- else
-- {
-- menu_index += 1;
-- }
++ if_down();
break;
default:
break;
}
}
++
++void Pause_menu::if_enter()
++{
++ 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;
++ }
++}
++
++void Pause_menu::if_up()
++{
++ if(menu_index == 1)
++ {
++ return;
++ }
++ else
++ {
++ menu_index -= 1;
++ }
++}
++
++void Pause_menu::if_down()
++{
++ if(menu_index == 3)
++ {
++ return;
++ }
++
++ else
++ {
++ menu_index += 1;
++ }
++}
switch (event.joystickButton.button)
{
case 0: // A
-- if(menu_index == 1)
-- {
-- menu = true;
-- menu_index = 1;
-- }
--
-- else if(menu_index == 2)
-- {
-- exit_game = true;
-- menu_index = 1;
-- }
++ if_enter();
break;
-- default:
--
++
++ default:
break;
}
--
break;
++
case sf::Event::JoystickMoved:
switch(event.joystickMove.axis)
{
case sf::Joystick::PovY:
if (event.joystickMove.position <= -50)
{
-- if(menu_index == 1)
-- {
-- break;
-- }
--
-- else
-- {
-- menu_index -= 1;
-- }
++ if_up();
break;
}
else if (event.joystickMove.position >= 50)
{
-- if(menu_index == 3)
-- {
-- break;
-- }
--
-- else
-- {
-- menu_index += 1;
-- }
++ if_down();
break;
}
break;
switch(event.key.code)
{
case sf::Keyboard::Enter:
--
-- if(menu_index == 1)
-- {
-- menu = true;
-- menu_index = 1;
-- }
--
-- else if(menu_index == 2)
-- {
-- exit_game = true;
-- menu_index = 1;
-- }
++ if_enter();
break;
case sf::Keyboard::Up:
-- if(menu_index == 1)
-- {
-- break;
-- }
--
-- else
-- {
-- menu_index -= 1;
-- }
++ if_up();
break;
case sf::Keyboard::Down:
-- if(menu_index == 2)
-- {
-- break;
-- }
--
-- else
-- {
-- menu_index += 1;
-- }
++ if_down();
break;
default:
break;
}
}
++
++
++void Scoreboard_menu::if_enter()
++{
++ if(menu_index == 1)
++ {
++ menu = true;
++ menu_index = 1;
++ }
++
++ else if(menu_index == 2)
++ {
++ exit_game = true;
++ menu_index = 1;
++ }
++}
++
++void Scoreboard_menu::if_up()
++{
++ if(menu_index == 1)
++ {
++ return;
++ }
++ else
++ {
++ menu_index -= 1;
++ }
++}
++
++void Scoreboard_menu::if_down()
++{
++ if(menu_index == 2)
++ {
++ return;
++ }
++
++ else
++ {
++ menu_index += 1;
++ }
++}
void update(Context& context) override;
void render(sf::RenderWindow& window) const override;
void handle_input(sf::Event& event) override;
- private:
+
+ private:
+ void if_enter();
+ void if_up();
+ void if_down();
+
+ bool start_game;
+ bool exit_game;
+ bool scoreboard;
+
+ int menu_index;
+
sf::Texture texture;
sf::Texture texture2;
+
sf::Sprite sprite;
sf::Sprite mouse_l;
sf::Sprite mouse_r;
void render(sf::RenderWindow& window) const override;
void handle_input(sf::Event& event) override;
private:
++ void if_enter();
++ void if_up();
++ void if_down();
++
+ int menu_index;
+
+ bool resume_game;
+ bool exit_game;
+ bool menu;
+
sf::Texture texture;
sf::Texture texture2;
+
sf::Sprite sprite;
sf::Sprite mouse_l;
sf::Sprite mouse_r;
void update(Context& context) override;
void render(sf::RenderWindow& window) const override;
void handle_input(sf::Event& event) override;
-private:
+private:
++ void if_enter();
++ void if_up();
++ void if_down();
++
+ int menu_index;
+
+ bool exit_game;
+ bool menu;
+
sf::Texture texture;
sf::Texture texture2;
+
sf::Sprite sprite;
sf::Sprite mouse_l;
sf::Sprite mouse_r;
void update(Context& context) override;
void render(sf::RenderWindow& window) const override;
void handle_input(sf::Event& event) override;
- void load_to_csv(sf::Text playerText);
- void load_to_csv();
private:
++ void load_to_csv();
++ void if_enter();
++ void if_up();
++ void if_down();
++ void text_input(sf::Event& event);
++
+ int menu_index;
+ int points;
+
+ bool exit_game;
+ bool menu;
+
sf::Texture texture;
sf::Texture texture2;
+
sf::Sprite sprite;
- sf::CircleShape rectangle;
sf::Sprite mouse_l;
sf::Sprite mouse_r;
+
+ sf::CircleShape rectangle;
+
sf::String playerInput;
+
sf::Text playerText;
sf::Text linetext;
sf::Text funfacttext;