57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
#ifndef HOLESOME_WORLD_VIEW_H
|
|
#define HOLESOME_WORLD_VIEW_H
|
|
|
|
|
|
#include "../game_object.h"
|
|
#include "../game.h"
|
|
#include "ITrackable.h"
|
|
#include "../../primitives/circle_object.h"
|
|
|
|
class WorldView : public GameObject
|
|
{
|
|
public:
|
|
explicit WorldView(ITrackable *trackable = nullptr,
|
|
sf::Vector2f freeMoveArea = {200, 200},
|
|
sf::Vector2f dynamicFollowArea = {500, 500});
|
|
|
|
~WorldView();
|
|
|
|
|
|
void draw(sf::RenderWindow *window) const override;
|
|
void lateUpdate(Game *game) override;
|
|
|
|
sf::Vector2f getSize() const;
|
|
sf::Vector2f getCenter() const;
|
|
|
|
private:
|
|
sf::View *view{};
|
|
bool hasViewChanged{};
|
|
sf::Vector2f freeMoveArea;
|
|
sf::Vector2f dynamicFollowArea;
|
|
ITrackable *target;
|
|
|
|
CircleObject *marker;
|
|
|
|
void initializeView(Game *game);
|
|
|
|
void setSize(sf::Vector2u windowSize);
|
|
|
|
void followTarget();
|
|
|
|
bool isTargetInArea(sf::Vector2f areaSize);
|
|
|
|
sf::Vector2f getClosestPositionInArea(sf::Vector2f areaSize) const;
|
|
|
|
/// Calculates the hardDirection the target should be pulled back in.
|
|
/// \return Normalized vector, pointing from center to target.
|
|
sf::Vector2f getRubber() const;
|
|
|
|
void performHardFollow();
|
|
|
|
void moveCenter(sf::Vector2<float> delta);
|
|
|
|
void performDynamicFollow();
|
|
};
|
|
|
|
|
|
#endif //HOLESOME_WORLD_VIEW_H
|