using json = nlohmann::json;
-GameOver_menu::GameOver_menu(int const points, json& params) : texture{}, texture2{}, sprite{}, rectangle{}, mouse_l{}, mouse_r{}, linetext{}, funfacttext{}, entertext{}, pointstext{},
- playerInput{}, data{}, playerText{}, savetext{}, quittext{}, font{}, exit_game{false}, menu{false}, menu_index{1}, points{points}
+GameOver_menu::GameOver_menu(int const points, json& params) :
+ texture{},
+ texture2{},
+ sprite{},
+ rectangle{},
+ mouse_l{},
+ mouse_r{},
+ linetext{},
+ funfacttext{},
+ entertext{},
+ pointstext{},
+ playerInput{},
+ playerText{},
+ data{params},
+ savetext{},
+ quittext{},
+ font{},
+ exit_game{false},
+ menu{false},
+ menu_index{1},
+ points{points},
+ highscore_file{params["gameover_menu"]["highscore_file"]},
+ scoreboard_size{params["gameover_menu"]["scoreboard"]}
{
- std::cout << params["texture"] << "hejsan" << std::endl;
-
- texture.loadFromFile(params["texture"]);
+ texture.loadFromFile(params["gameover_menu"]["texture"]);
sprite.setTexture(texture);
sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF);
sprite.setPosition(0, 0);
// load textfont
- if ( !font.loadFromFile (params["font"]) )
+ if ( !font.loadFromFile (params["gameover_menu"]["font"]) )
throw std::invalid_argument ("Unable to load font");
{
if (menu)
{
- context.next_state = std::make_unique<Start_menu>();
+ context.next_state = std::make_unique<Start_menu>(data);
}
// changes color on text depending on selection
{
window.draw(sprite);
- window.draw(rectangle);
+ window.draw(rectangle);uniq
window.draw(mouse_l);
window.draw(mouse_r);
{
window.close();
}
-}
+}uniq
void GameOver_menu::handle_input(sf::Event& event)
}
// if not backspace, print letters
- else if(playerInput.getSize() < 15)
+ else if(playerInput.getSize() < 20)
{
playerInput += event.text.unicode;
}
//spara namn till fil
void GameOver_menu::load_to_csv(sf::Text playertext)
{
- std::cout << data["highscore_file"] << "hej" << std::endl;
- std::cout << data["game_constants"]["scoreboard"] << "hejdå" << std::endl;
+
+ std::cout << "hej" << std::endl;
+
std::string current_line{playerText.getString() + ", " + std::to_string(points)};
- std::ifstream highscore_file_r{"assets/highscore.csv"};
+ std::ifstream highscore_file_r{highscore_file};
std::vector<std::string> lines_read;
std::vector<std::string> lines_write;
for (std::string one_line; std::getline(highscore_file_r, one_line);lines_read.push_back(one_line));
}
- if (lines_write.size() > data["scoreboard"]) lines_write.pop_back();
+ if (lines_write.size() > scoreboard_size) lines_write.pop_back();
highscore_file_r.close();
- std::ofstream highscore_file_w{"assets/highscore.csv"};
+ std::ofstream highscore_file_w{highscore_file};
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();
}
\ No newline at end of file
#include "States.h"
#include "Context.h"
#include "constants.h"
+#include "json.hpp"
+using json = nlohmann::json;
-Pause_menu::Pause_menu() : texture{}, texture2{}, sprite{}, mouse_l{}, mouse_r{}, resumetext{}, startmenutext{},
- quittext{}, font{}, resume_game{false}, exit_game{false}, menu{false}, menu_index{1}
+Pause_menu::Pause_menu(json& params) : texture{}, texture2{}, sprite{}, mouse_l{}, mouse_r{}, resumetext{}, startmenutext{},
+ quittext{}, font{}, resume_game{false}, exit_game{false}, menu{false}, menu_index{1}, data{params}
{
- texture.loadFromFile("assets/Pause_bild.png");
- sprite.setTexture(texture);;
+
+ texture.loadFromFile(params["pause_menu"]["texture"]);
+ 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");
+ texture2.loadFromFile(params["pause_menu"]["texture_mouse"]);
mouse_l.setTexture(texture2);
mouse_l.setScale(-0.1, 0.1);
// load textfont
- if ( !font.loadFromFile ("assets/fonts/Philosopher-Regular.ttf") )
+ if ( !font.loadFromFile (params["pause_menu"]["font"]) )
{
throw std::invalid_argument ("Unable to load font");
}
}
else if (menu)
{
- context.next_state = std::make_unique<Start_menu>();
+ context.next_state = std::make_unique<Start_menu>(data);
context.saved_game.release();
}
using json = nlohmann::json;
-Scoreboard_menu::Scoreboard_menu() : texture{}, texture2{}, sprite{}, menu{false}, exit_game{false},
- startmenutext{}, quittext{}, mouse_r{}, mouse_l{}, font{}, menu_index{1}
+Scoreboard_menu::Scoreboard_menu(json& params) : texture{}, texture2{}, sprite{}, menu{false}, exit_game{false},
+ startmenutext{}, quittext{}, mouse_r{}, mouse_l{}, font{}, menu_index{1}, data{params}
+
{
texture.loadFromFile("assets/scoreboard.png");
- sprite.setTexture(texture);;
+ sprite.setTexture(texture);
sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF);
sf::FloatRect gb {sprite.getGlobalBounds()};
{
if (menu)
{
- context.next_state = std::make_unique<Start_menu>();
+ context.next_state = std::make_unique<Start_menu>(data);
}
// changes color on text depending on selection
#include "States.h"
#include "Context.h"
#include "constants.h"
+#include "json.hpp"
+using json = nlohmann::json;
-Start_menu::Start_menu() : texture{}, texture2{}, sprite{}, mouse_l{}, mouse_r{}, starttext{}, scoreboardtext{},
- quittext{}, font{}, start_game{false}, exit_game{false}, scoreboard{false}, menu_index{1}
+Start_menu::Start_menu(json& params) : texture{}, texture2{}, sprite{}, mouse_l{}, mouse_r{}, starttext{}, scoreboardtext{},
+ quittext{}, font{}, start_game{false}, exit_game{false}, scoreboard{false}, menu_index{1}, data{params}
{
//sprite
- texture.loadFromFile("assets/meny_bild.png");
+ texture.loadFromFile(params["start_menu"]["texture"]);
sprite.setTexture(texture);
sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF);
sprite.setPosition(0, 0);
//mouse
- texture2.loadFromFile("assets/muspekareGul.png");
+ texture2.loadFromFile(params["start_menu"]["texture_mouse"]);
mouse_l.setTexture(texture2);
mouse_l.setScale(-0.1, 0.1);
//load textfont
- if ( !font.loadFromFile ("assets/fonts/Philosopher-Regular.ttf") )
+ if ( !font.loadFromFile (params["start_menu"]["font"]) )
throw std::invalid_argument ("Unable to load font");
//start
if (scoreboard)
{
- context.next_state = std::make_unique<Scoreboard_menu>();
+ context.next_state = std::make_unique<Scoreboard_menu>(data);
scoreboard = false;
return;
}
{
context.saved_game.reset(static_cast<Game_state *>(context.current_state.release()));
- context.next_state = std::make_unique<Pause_menu>();
+ context.next_state = std::make_unique<Pause_menu>(data);
pause_game = false;
return;
}
int remaining_time {static_cast<int>(data["game_constants"]["game_time"]) - static_cast<int>(game_time)};
if (remaining_time < 0)
{
- context.next_state = std::make_unique<GameOver_menu>(points, data["gameover_menu"]);
+ context.next_state = std::make_unique<GameOver_menu>(points, data);
return;
}
#include "SFML/Graphics.hpp"
#include <vector>
#include <memory>
+#include <fstream>
#include "Map.h"
#include "Player.h"
sf::Texture main_enemy_texture;
sf::Texture YF_texture;
sf::Texture bike_texture;
- //std::vector<std::unique_ptr<YF>> yf;
-
json data;
int points;
};
class Start_menu : public State
{
public:
- Start_menu();
+ Start_menu(json& params);
~Start_menu() = default;
void update(Context& context) override;
void render(sf::RenderWindow& window) const override;
bool start_game;
bool exit_game;
bool scoreboard;
+ json data;
int menu_index;
};
class Pause_menu : public State
{
public:
- Pause_menu();
+ Pause_menu(json& params);
~Pause_menu() = default;
void update(Context& context) override;
void render(sf::RenderWindow& window) const override;
bool resume_game;
bool exit_game;
bool menu;
+ json data;
int menu_index;
};
class Scoreboard_menu : public State
{
public:
- Scoreboard_menu();
+ Scoreboard_menu(json& params);
~Scoreboard_menu() = default;
void update(Context& context) override;
void render(sf::RenderWindow& window) const override;
bool exit_game;
bool menu;
-
+ json data;
int menu_index;
};
sf::Text quittext;
sf::Font font;
+ std::string highscore_file;
+ int scoreboard_size;
+
bool exit_game;
bool menu;
json data;