merging yf and game_time
authorlukel495 <lukel495@su15-110.ad.liu.se>
Mon, 27 Nov 2023 07:51:08 +0000 (08:51 +0100)
committerlukel495 <lukel495@su15-110.ad.liu.se>
Mon, 27 Nov 2023 07:51:08 +0000 (08:51 +0100)
1  2 
src/States.cc
src/States.h

diff --cc src/States.cc
index eff307cbe0e75354a7183f2df58114efc218a46c,7cc5c5d40977f3e09abb829d5a8830861b60a762..af793b734dff5fc8b448830a2c5d7d4a66e1fc27
@@@ -16,14 -15,14 +16,17 @@@ Game_state::Game_state() 
      pause_game{false},
      player{},
      bottles{}, 
 +    helper{},
 +    main_enemy_texture{},
      time_since_last_bottle{0.0f},
 +    game_time{0},
+     time_since_last_yf{0.0f},
      bottle_texture {},
+     YF_texture {},
+     yf{},
      data{},
 -    enemy{}
 -    
 +    enemy{},
 +    points{0}
  {
      std::ifstream f("assets/data.json");
      data = json::parse(f);
  
      player = std::make_unique<Player>(data["player"]);
      helper = std::make_unique<Helper>(data["helper"]);
 +    game_map = std::make_unique<Map>(data["map"]);
 +    enemy = std::make_unique<Main_enemy>(main_enemy_texture, data["main_enemy"]);
  
      bottle_texture.loadFromFile("assets/kir.png");
-     
+     YF_texture.loadFromFile("assets/YF.png");
  }
  
  void Game_state::update(Context &context)
              
          }
      }
 +    player->update(context);
 +    helper->update(context);
 +
 +    if (player->collides(*helper))
 +    {
 +        points += player->get_collected();
 +        player->zero_collected();
 +
 +        player->collision(*helper);
 +        helper->collision(*player);
 +    }
 +    /*
 +    if (player->get_x() < 0) player->set_x(0);
 +    if (player->get_x() > S_WIDTH) player->set_x(S_WIDTH);
 +    if (player->get_y() < 0) player->set_y(0);
 +    if (player->get_y() > S_HEIGHT) player->set_y(S_HEIGHT);
 +    */
 +
      time_since_last_bottle += context.time.asSeconds();
-     //std::cout << std::fixed << std::setprecision(3) << time_since_last_bottle << std::endl;
+     time_since_last_yf += context.time.asSeconds();
      if (time_since_last_bottle >= data["game_constants"]["bottles_per_second"])
      {
          bottles.push_back(std::make_unique<Bottle>(bottle_texture, data["bottle"]));
-         std::cout << "placed bottle"<< std::endl;
          time_since_last_bottle = 0;
      }
-     //game time
+     if (time_since_last_yf >= 8)
+     {
+         yf.push_back(std::make_unique<YF>(YF_texture));
+         if(yf.size() > 1)
+         {
+             yf.erase(yf.begin());
+         }
+         time_since_last_yf = 0;
+     }
 -    game_map.update(context);
 -    player->update(context);
 -    helper->update(context);
 -    enemy.update(context);
 +    enemy->update(context);
 +    game_map->update(points, remaining_time);
+     if (yf.size()>0)
+     {
+         for(unsigned int i {0}; i < yf.size(); ++i)
+         {
+             yf[i]->update(context);
+         }
+     }
+     
  }
  
  void Game_state::render(sf::RenderWindow &window) const
  {
 -    game_map.render(window);
 +    game_map->render(window);
      player->render(window);
 -    enemy.render(window);
 +    enemy->render(window);
      helper->render(window);
+     
+     
+     for(unsigned int i {0}; i < yf.size(); ++i)
+     {
+         yf[i]->render(window);
+     }
+     
      for (int i{}; i < int(bottles.size()); ++i)
      {
          bottles[i]->render(window);
diff --cc src/States.h
index 9eedbf58890d6ad7f69020ac232c762bf3b54354,45fff0c2657cab92e45b89da90d720fca57a1e57..033d30a13aafa42453c01adc9a9bc798ef0e5857
@@@ -41,18 -42,18 +42,22 @@@ public
  protected:
  private:
      float time_since_last_bottle;
 +    float game_time;
+     float time_since_last_yf;
      
 -    Map game_map;
 +    std::unique_ptr<Map> game_map;
      std::unique_ptr<Player> player;
      std::unique_ptr<Helper> helper;
 -    Main_enemy enemy;
 +    std::unique_ptr<Main_enemy> enemy;
 +
      bool pause_game;
      sf::Texture bottle_texture;
 +    sf::Texture main_enemy_texture;
+     sf::Texture YF_texture;
+     std::vector<std::unique_ptr<YF>> yf;
+     
      json data;
 +    int points;
  
  };