#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);
void Bottle::render(sf::RenderWindow& window) const
{
window.draw(sprite);
-}
\ No newline at end of file
+}
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:
};
#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)
}
}
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;
}