From fc60db0b5397f70484a972f1109f7c4b1a47b355 Mon Sep 17 00:00:00 2001 From: stian853 Date: Wed, 6 Dec 2023 14:40:20 +0100 Subject: [PATCH] Changed to softcoding, Nils, Arvid, Stina --- assets/data.json | 11 +++++++++ assets/fighter.png | Bin 3571 -> 0 bytes src/Bottle.cc | 2 +- src/Helper.cc | 4 +-- src/Helper.h | 2 +- src/Map.cc | 4 +-- src/Map.h | 2 +- src/Player.cc | 3 ++- src/Player.h | 2 +- src/States.cc | 59 +++++++++++++++------------------------------ src/States.h | 3 --- 11 files changed, 39 insertions(+), 53 deletions(-) delete mode 100644 assets/fighter.png diff --git a/assets/data.json b/assets/data.json index c7a2d2a..635963f 100644 --- a/assets/data.json +++ b/assets/data.json @@ -66,6 +66,17 @@ "direction": [0, 1], "sin_amplitude": 50, "sin_omega": 5 + }, + "game_state_assets": + { + "kir_file": "assets/kir.png", + "YF_file": "assets/YF.png", + "cyklist_file": "assets/cyklist.png", + "ling_file": "assets/6Ling_figur2.png", + "sack_file": "assets/sack.png", + "player_file": "assets/4V_figur.png", + "helper_file": "assets/ysex.png", + "map_file": "assets/bakgrund.png" } } \ No newline at end of file diff --git a/assets/fighter.png b/assets/fighter.png deleted file mode 100644 index 6a36a830db47eb988e7ba2ff4fc510c4cb07aacf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3571 zcmV000McNliru;sg>6Dk>zvzfb@G4S-2R zK~#9!?VNjXT-ANYKj+-XzE{%9whS^THa0fS1F+4*h){PRkO{;N2`RzOgeeWB3@I@b zCUjcxXu?cOCV!-vG!v>c3C*iaGNoiprU4QjiHsH7u>-c{fRQb1Ecv0;zVF@pIH!NC zw3cMqRv?ju?K7j%(be7k{m%D%f8X;v=eKu-Wm%kUN1Hqg!88Qqu}5zUAA9t+a60&6 zP6sD8cK6D&3>n3aiTY8@qeusRl((2Qd2A{uhVu|NgW9Wm;%R%rwsI zRc15;+8cQP;@L{85TzBS6-CO^P(y?eD5X$=gCW7I z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kiKOTJ3(bAY(CmxK!!U)|ODa_nBiRYO0d5DPLtq5A3E@*XxmwE<~d?O$|wU_YPnT zUz!l4K$>eAp~b85pM&5b6a@h(&D@$y!a<4}w$a(kXtTN<&MFp$tP{ zTPB%|Qd;RV7Z9ZsK@bv+*qDYvs5GHcXD%RL{kP`~r4&LQP0+sat(T26H)I(32)7^% z71NGF{IwD6*-G0EHggVO?#Y4KF%?!B*1k9gtimm!=5WZDDr tz3*=}ChDJM$TVr<>^IDuWylHJ{{z;8i`2th6xjd(002ovPDHLkV1m1&qj>-T diff --git a/src/Bottle.cc b/src/Bottle.cc index e414dce..3e642e8 100644 --- a/src/Bottle.cc +++ b/src/Bottle.cc @@ -4,7 +4,7 @@ #include "States.h" #include -Bottle::Bottle(sf::Texture& txtr, json& params) +Bottle::Bottle(sf::Texture& txtr, json& params) { texture = txtr; sprite.setTexture(texture); diff --git a/src/Helper.cc b/src/Helper.cc index 9280f94..41e0d55 100644 --- a/src/Helper.cc +++ b/src/Helper.cc @@ -7,13 +7,13 @@ #include -Helper::Helper(json& params) : stop_bot{params["stop_bot"]}, stop_top{params["stop_top"]}, max_speed{params["max_speed"]}, movement{} +Helper::Helper(sf::Texture& txtr, json& params) : stop_bot{params["stop_bot"]}, stop_top{params["stop_top"]}, max_speed{params["max_speed"]}, movement{} { + texture = txtr; position = {params["start_pos"][0], params["start_pos"][1]}; direction = {params["direction"][0], params["direction"][1]}; movement = direction; - texture.loadFromFile("assets/ysex.png"); sprite.setTexture(texture); sprite.setScale(params["scale"][0], params["scale"][1]); diff --git a/src/Helper.h b/src/Helper.h index 0eb246b..3b2cb6e 100644 --- a/src/Helper.h +++ b/src/Helper.h @@ -11,7 +11,7 @@ using json = nlohmann::json; class Helper : public Object { public: - Helper(json& params); + Helper(sf::Texture& txtr, json& params); ~Helper() = default; void collision(Object& other) override; diff --git a/src/Map.cc b/src/Map.cc index 7e62975..1271507 100644 --- a/src/Map.cc +++ b/src/Map.cc @@ -2,12 +2,10 @@ #include "constants.h" #include -Map::Map(json& params) : texture{}, sprite{}, point_text{}, collected_text{}, time_text{}, bottle_texture{}, bottle_sprite{}, font{} +Map::Map(sf::Texture& txtr, sf::Texture& bottle_txtr, json& params) : texture{txtr}, sprite{}, point_text{}, collected_text{}, time_text{}, bottle_texture{bottle_txtr}, bottle_sprite{}, font{} { - texture.loadFromFile("assets/bakgrund.png"); sprite.setTexture(texture); - bottle_texture.loadFromFile("assets/kir.png"); bottle_sprite.setTexture(bottle_texture); sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF); sprite.setPosition(0,0); diff --git a/src/Map.h b/src/Map.h index 41daf14..12cdbca 100644 --- a/src/Map.h +++ b/src/Map.h @@ -10,7 +10,7 @@ using json = nlohmann::json; class Map { public: - Map(json& params); + Map(sf::Texture& txtr, sf::Texture& bottle_txtr, json& params); ~Map() = default; void update(int const collected, int const points, int const time_left); diff --git a/src/Player.cc b/src/Player.cc index 1f131ce..2a9ee4b 100644 --- a/src/Player.cc +++ b/src/Player.cc @@ -6,8 +6,9 @@ #include "Context.h" #include "constants.h" -Player::Player(json& params) : collected{0}, max_speed{params["max_speed"]}, tumbling{false}, tumble_degrees{0}, rotation{params["degrees_per_second"]} +Player::Player(sf::Texture& player_txtr, sf::Texture& sack_txtr, json& params) : sack_texture{sack_txtr}, collected{0}, max_speed{params["max_speed"]}, tumbling{false}, tumble_degrees{0}, rotation{params["degrees_per_second"]} { + texture = player_txtr; position = {params["start_pos"][0], params["start_pos"][1]}; texture.loadFromFile("assets/4V_figur.png"); diff --git a/src/Player.h b/src/Player.h index 5303611..0d2d698 100644 --- a/src/Player.h +++ b/src/Player.h @@ -16,7 +16,7 @@ using json = nlohmann::json; class Player : public Moving_object { public: - Player(json& params); + Player(sf::Texture& player_txtr, sf::Texture& sack_txtr, json& params); ~Player() = default; void collision(Object& other) override; diff --git a/src/States.cc b/src/States.cc index 9c769f6..9129afd 100644 --- a/src/States.cc +++ b/src/States.cc @@ -20,7 +20,6 @@ Game_state::Game_state() : bottles{}, helper{}, bike{}, - main_enemy_texture{}, time_since_last_bottle{0.0f}, game_time{0}, time_since_last_yf{0.0f}, @@ -35,17 +34,29 @@ Game_state::Game_state() : { std::ifstream f("assets/data.json"); data = json::parse(f); + sf::Texture main_enemy_texture; + sf::Texture sack_texture; + sf::Texture player_texture; + sf::Texture helper_texture; + sf::Texture map_texture; - main_enemy_texture.loadFromFile("assets/6Ling_figur2.png"); + main_enemy_texture.loadFromFile(data["game_state_assets"]["ling_file"]); + sack_texture.loadFromFile(data["game_state_assets"]["sack_file"]); + player_texture.loadFromFile(data["game_state_assets"]["player_file"]); + helper_texture.loadFromFile(data["game_state_assets"]["helper_file"]); + map_texture.loadFromFile(data["game_state_assets"]["map_file"]); + + player = std::make_unique(player_texture, sack_texture, data["player"]); + helper = std::make_unique(helper_texture, data["helper"]); - player = std::make_unique(data["player"]); - helper = std::make_unique(data["helper"]); - game_map = std::make_unique(data["map"]); enemy = std::make_unique(main_enemy_texture, data["main_enemy"]); - bottle_texture.loadFromFile("assets/kir.png"); - YF_texture.loadFromFile("assets/YF.png"); - bike_texture.loadFromFile("assets/cyklist.png"); + bottle_texture.loadFromFile(data["game_state_assets"]["kir_file"]); + YF_texture.loadFromFile(data["game_state_assets"]["YF_file"]); + bike_texture.loadFromFile(data["game_state_assets"]["cyklist_file"]); + + game_map = std::make_unique(map_texture, bottle_texture, data["map"]); + f.close(); } @@ -64,38 +75,6 @@ void Game_state::update(Context &context) int remaining_time {static_cast(data["game_constants"]["game_time"]) - static_cast(game_time)}; if (remaining_time < 0) { - // LÄGG ALLT NEDAN I GAME OVER MENYN. - std::string current_line{"Gorilla," + std::to_string(points)}; - - std::ifstream highscore_file_r{"assets/highscore.csv"}; - std::vector lines_read; - std::vector lines_write; - for (std::string one_line; std::getline(highscore_file_r, one_line);lines_read.push_back(one_line)); - - bool added {false}; - for (std::string::size_type line_count{0}; line_count < lines_read.size(); line_count++) - { - if (!added && points > std::stoi(lines_read[line_count].substr(lines_read[line_count].find_first_of(',') + 1))) - { - std::cout << "i loop" << std::endl; - lines_write.push_back(current_line); - added = true; - } - lines_write.push_back(lines_read[line_count]); - } - - if (!added) lines_write.push_back(current_line); - - - - if (lines_write.size() > data["game_constants"]["scoreboard"]) lines_write.pop_back(); - - highscore_file_r.close(); - - std::ofstream highscore_file_w{"assets/highscore.csv"}; - 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(); - context.next_state = std::make_unique(); return; } diff --git a/src/States.h b/src/States.h index 9e7505c..5e4a754 100644 --- a/src/States.h +++ b/src/States.h @@ -17,8 +17,6 @@ using json = nlohmann::json; - - struct Context; class State @@ -56,7 +54,6 @@ private: bool pause_game; sf::Texture bottle_texture; - sf::Texture main_enemy_texture; sf::Texture YF_texture; sf::Texture bike_texture; //std::vector> yf; -- 2.30.2