fixat så bottle_texture bara laddas in en gång, arvid, lukas, nils, stina
authorArvid Sjöblom <arvsj277@student.liu.se>
Tue, 14 Nov 2023 12:39:22 +0000 (13:39 +0100)
committerArvid Sjöblom <arvsj277@student.liu.se>
Tue, 14 Nov 2023 12:39:22 +0000 (13:39 +0100)
src/Bottle.cc
src/Bottle.h
src/States.cc
src/States.h

index 568466faaa8909cba2d7c22bae852f0314cd7c19..7bc1e4d72bd4c8f7cf741f7f94677c8deaa0abc9 100644 (file)
@@ -3,9 +3,9 @@
 #include "Context.h"
 #include <random>
 
-Bottle::Bottle() 
+Bottle::Bottle(sf::Texture& txtr
 {
-    texture.loadFromFile("assets/kir.png");
+    texture = txtr;
     sprite.setTexture(texture);
     position ={rand()%(S_WIDTH*5/7 - S_WIDTH/5 +1) + S_WIDTH/5, rand()%S_HEIGHT+1}; //x-pixel WIDTH/5 - WIDTH*5/7
     sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF);
@@ -26,4 +26,4 @@ void Bottle::update(Context& context)
 void Bottle::render(sf::RenderWindow& window) const
 {
     window.draw(sprite);
-}
\ No newline at end of file
+}
index ebba1aeec9350d9400058beed4b402803db2cff6..f7b2afa5b0aab63d4ff9184755f5ab037b6da75f 100644 (file)
@@ -7,10 +7,11 @@
 class Bottle : public Static_object
 {
 public:
-    Bottle();
+    Bottle(sf::Texture& txtr);
     void collision(Object& other) override;
     void update(Context& context) override;
     void render(sf::RenderWindow& window) const override;
+    void set_texture(sf::Texture& txtr);
 private:
         
 };
index 0d1422f6e8a226321c61b3f4e0dc6a399abf361b..502efb904855116c6ec399a35770759491bf4ff3 100644 (file)
@@ -5,10 +5,9 @@
 #include "Context.h"
 #include "constants.h"
 
-Game_state::Game_state() : game_map{}, player{}, pause_game{false}, bottles{}, time_since_last_bottle{0.0f}
+Game_state::Game_state() : game_map{}, player{}, pause_game{false}, bottles{}, time_since_last_bottle{0.0f}, bottle_texture {}
 {
-    
-    bottles.push_back(std::make_unique<Bottle> ());
+    bottle_texture.loadFromFile("assets/kir.png");
 }
 
 void Game_state::update(Context& context)
@@ -42,16 +41,11 @@ void Game_state::update(Context& context)
         }
     }
     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 (bottles.size() > 10)
-        {
-            bottles.erase(bottles.begin());
-        }
-        
-        bottles.push_back(std::make_unique<Bottle>());
-        //std::cout << "placed bottle"<< std::endl;
+        bottles.push_back(std::make_unique<Bottle>(bottle_texture));
+        std::cout << "placed bottle"<< std::endl;
         time_since_last_bottle = 0;
 
     }
index f311abaa2fcc94fafb8eee667e20a62105ea874c..6b8046045944d25e6348179cc484bb4b20eaef2e 100644 (file)
@@ -36,6 +36,8 @@ private:
     Map game_map;
     Player player;
     bool pause_game;
+    sf::Texture bottle_texture;
+
 };
 
 class Start_menu : public State