REsolved merge conflicts, Nils, Lukas, Arvid, Stina
authorlukel495 <lukel495@su15-111.ad.liu.se>
Wed, 15 Nov 2023 13:39:51 +0000 (14:39 +0100)
committerlukel495 <lukel495@su15-111.ad.liu.se>
Wed, 15 Nov 2023 13:39:51 +0000 (14:39 +0100)
1  2 
src/Bottle.cc
src/Bottle.h
src/Player.cc
src/Player.h
src/States.cc
src/States.h

diff --cc src/Bottle.cc
Simple merge
diff --cc src/Bottle.h
Simple merge
diff --cc src/Player.cc
Simple merge
diff --cc src/Player.h
Simple merge
diff --cc src/States.cc
index 40ff02505562b1be9541d6a02c26712d264ac194,14aa7e7fa9386a83f566a20878747f833a78b1b1..8521e78c8bb9b58c66bce0bb145f407fbb6d4386
@@@ -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 <fstream>
+ 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<Player>(data["player"]);
+     helper = std::make_unique<Helper>(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>(bottle_texture));
-         //std::cout << "placed bottle"<< std::endl;
+         bottles.push_back(std::make_unique<Bottle>(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 5825ff615143ecc0c609a13902095b320a6de8fc,03f74a8fe5d17907095d5cb97ecdaa8ff18cffca..49cb532b24b1317e380c15a02bf795d9b3c94d5b
@@@ -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<std::unique_ptr<Bottle>> bottles;
 +    
      Map game_map;
-     Player player;
-     Helper helper;
+     std::unique_ptr<Player> player;
+     std::unique_ptr<Helper> helper;
 +    Main_enemy enemy;
      bool pause_game;
      sf::Texture bottle_texture;
+     json data;
  
  };