}
+
void Helper::update(Context& context)
{
- position += direction * max_speed;
+ position += direction * max_speed;
+
+ if (position.y >= stop_bot || position.y <= stop_top )
+ {
+ direction *= -1.0f;
+ }
+
- if (position.y >= stop_bot || position.y <= stop_top )
- {
- direction *= -1.0f;
- }
//Game_state* game = static_cast<Game_state*>(context.current_state.get());
sprite.setPosition(position);
using json = nlohmann::json;
-class Helper : public Autonomous_object
+class Helper : public Object
{
public:
Helper(json& params);
Object() : position{}, sprite{}, texture{}, direction{} {};
virtual ~Object() = default;
- bool collides(Object& other)
+ virtual bool collides(Object& other)
{
return get_hitbox().intersects(other.get_hitbox());
}
virtual void collision(Object& other) = 0;
virtual void update(Context& context) = 0;
virtual void render(sf::RenderWindow& window) const = 0;
+
sf::FloatRect get_hitbox()
{
return sprite.getGlobalBounds();
}
}
-void Player::add_collected()
+int Player::add_collected()
{
collected += 1;
+ return collected;
}
\ No newline at end of file
void update(Context& context) override;
void render(sf::RenderWindow& window) const override;
void handle_input(sf::Event& event);
- void add_collected();
+ int add_collected();
protected:
private:
int collected;
pause_game{false},
player{},
bottles{},
+ helper{},
time_since_last_bottle{0.0f},
bottle_texture {},
data{},
}
}
+ if (player->collides(*helper))
+ {
+ //reset add collected
+ // reset hitbox of sack
+
+ }
+
time_since_last_bottle += context.time.asSeconds();
//std::cout << std::fixed << std::setprecision(3) << time_since_last_bottle << std::endl;
if (time_since_last_bottle >= data["game_constants"]["bottles_per_second"])
time_since_last_bottle = 0;
}
game_map.update(context);
+ if (!(player->collides(*helper)))
+ {
+ helper->update(context);
+ }
player->update(context);
- helper->update(context);
enemy.update(context);
}