From: Arvid Sjöblom Date: Tue, 14 Nov 2023 12:39:22 +0000 (+0100) Subject: fixat så bottle_texture bara laddas in en gång, arvid, lukas, nils, stina X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;h=eba7c70aef86b3eacc2413a481b6f5a7b34a7ed6;p=TDDC76_proj.git fixat så bottle_texture bara laddas in en gång, arvid, lukas, nils, stina --- diff --git a/src/Bottle.cc b/src/Bottle.cc index 568466f..7bc1e4d 100644 --- a/src/Bottle.cc +++ b/src/Bottle.cc @@ -3,9 +3,9 @@ #include "Context.h" #include -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 +} diff --git a/src/Bottle.h b/src/Bottle.h index ebba1ae..f7b2afa 100644 --- a/src/Bottle.h +++ b/src/Bottle.h @@ -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: }; diff --git a/src/States.cc b/src/States.cc index 0d1422f..502efb9 100644 --- a/src/States.cc +++ b/src/States.cc @@ -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_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()); - //std::cout << "placed bottle"<< std::endl; + bottles.push_back(std::make_unique(bottle_texture)); + std::cout << "placed bottle"<< std::endl; time_since_last_bottle = 0; } diff --git a/src/States.h b/src/States.h index f311aba..6b80460 100644 --- a/src/States.h +++ b/src/States.h @@ -36,6 +36,8 @@ private: Map game_map; Player player; bool pause_game; + sf::Texture bottle_texture; + }; class Start_menu : public State