From: lukel495 Date: Wed, 15 Nov 2023 13:39:51 +0000 (+0100) Subject: REsolved merge conflicts, Nils, Lukas, Arvid, Stina X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;h=d1edb61e2efe04f9ab3d32b81170c98f51a71b59;p=TDDC76_proj.git REsolved merge conflicts, Nils, Lukas, Arvid, Stina --- d1edb61e2efe04f9ab3d32b81170c98f51a71b59 diff --cc src/States.cc index 40ff025,14aa7e7..8521e78 --- a/src/States.cc +++ b/src/States.cc @@@ -5,8 -5,27 +5,28 @@@ #include "Context.h" #include "constants.h" - Game_state::Game_state() : game_map{}, player{}, enemy{}, pause_game{false}, bottles{}, time_since_last_bottle{0.0f}, bottle_texture {} + #include "json.hpp" + #include + + using json = nlohmann::json; + + Game_state::Game_state() : + game_map{}, + pause_game{false}, + player{}, + bottles{}, + time_since_last_bottle{0.0f}, + bottle_texture {}, - data{} ++ data{}, ++ enemy{} { + std::ifstream f("assets/data.json"); + data = json::parse(f); + + + player = std::make_unique(data["player"]); + helper = std::make_unique(data["helper"]); + bottle_texture.loadFromFile("assets/kir.png"); } @@@ -31,36 -50,26 +51,36 @@@ void Game_state::update(Context &contex player.add_collected(); } }*/ - for (unsigned int i = 0; i < bottles.size(); ++i) + for (unsigned int i {0}; i < bottles.size(); ++i) { - if (player.collides(*(bottles[i]))) + if (player->collides(*(bottles[i]))) { // std::cout <<"crash" << std::endl; bottles.erase(bottles.begin() + i); - player.add_collected(); + player->add_collected(); } } + for (unsigned int i {0}; i < bottles.size(); ++i) + { + if (enemy.collides(*(bottles[i]))) + { + // std::cout <<"crash" << std::endl; + bottles.erase(bottles.begin() + i); + + } + } time_since_last_bottle += context.time.asSeconds(); - std::cout << std::fixed << std::setprecision(3) << time_since_last_bottle << std::endl; + //std::cout << std::fixed << std::setprecision(3) << time_since_last_bottle << std::endl; - if (time_since_last_bottle >= 2) + if (time_since_last_bottle >= data["game_constants"]["bottles_per_second"]) { - bottles.push_back(std::make_unique(bottle_texture)); - //std::cout << "placed bottle"<< std::endl; + bottles.push_back(std::make_unique(bottle_texture, data["bottle"])); + std::cout << "placed bottle"<< std::endl; time_since_last_bottle = 0; } game_map.update(context); - player.update(context); + player->update(context); + helper->update(context); + enemy.update(context); - helper.update(context); } void Game_state::render(sf::RenderWindow &window) const diff --cc src/States.h index 5825ff6,03f74a8..49cb532 --- a/src/States.h +++ b/src/States.h @@@ -7,11 -7,13 +7,15 @@@ #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 class State @@@ -36,13 -37,13 +40,14 @@@ public protected: private: float time_since_last_bottle; - std::vector> bottles; + Map game_map; - Player player; - Helper helper; + std::unique_ptr player; + std::unique_ptr helper; + Main_enemy enemy; bool pause_game; sf::Texture bottle_texture; + json data; };