Basic trackable view
This commit is contained in:
parent
29c5eb7bdd
commit
b3c129e356
14 changed files with 44 additions and 43 deletions
|
@ -54,7 +54,8 @@ set(SOURCES
|
|||
src/game/input/input_identity.h
|
||||
src/utilities/magic_enum.hpp
|
||||
src/game/player/player_spawner.cpp
|
||||
src/game/player/player_spawner.hpp)
|
||||
src/game/player/player_spawner.hpp
|
||||
)
|
||||
|
||||
set(PHYSICS_00_SOURCES
|
||||
src/prototypes/physics_00.cpp)
|
||||
|
|
|
@ -45,7 +45,7 @@ void GridDebugLayer::draw(sf::RenderWindow *window) const
|
|||
}
|
||||
}
|
||||
|
||||
void GridDebugLayer::update(Game *game)
|
||||
void GridDebugLayer::update()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ public:
|
|||
~GridDebugLayer();
|
||||
|
||||
void draw(sf::RenderWindow *window) const override;
|
||||
void update(Game *game) override;
|
||||
void update() override;
|
||||
|
||||
private:
|
||||
std::vector<GameObject*> marker;
|
||||
|
|
|
@ -8,6 +8,7 @@ TrackingView::TrackingView(float freeMoveRadius, float dynamicFollowRadius) : fr
|
|||
{
|
||||
trackables = std::vector<ITrackable *>();
|
||||
marker = new CircleObject(2, sf::Color::Yellow);
|
||||
Game::getInstance()->registerView(this);
|
||||
}
|
||||
|
||||
TrackingView::~TrackingView()
|
||||
|
@ -16,19 +17,19 @@ TrackingView::~TrackingView()
|
|||
delete marker;
|
||||
}
|
||||
|
||||
void TrackingView::lateUpdate(Game *game)
|
||||
void TrackingView::lateUpdate()
|
||||
{
|
||||
// Initialize if necessary
|
||||
if (view == nullptr)
|
||||
{
|
||||
initializeView(game);
|
||||
initializeView();
|
||||
}
|
||||
|
||||
processTrackableStates();
|
||||
|
||||
// Update size
|
||||
// TODO: Update size based on distance of tracked objects
|
||||
setSize(game->window->getSize());
|
||||
setSize(Game::getInstance()->window->getSize());
|
||||
|
||||
if (!trackables.empty())
|
||||
{
|
||||
|
@ -38,14 +39,14 @@ void TrackingView::lateUpdate(Game *game)
|
|||
// Update window if necessary
|
||||
if (hasViewChanged)
|
||||
{
|
||||
game->window->setView(*this->view);
|
||||
Game::getInstance()->window->setView(*this->view);
|
||||
hasViewChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
void TrackingView::initializeView(Game *game)
|
||||
void TrackingView::initializeView()
|
||||
{
|
||||
auto size = game->window->getView().getSize();
|
||||
auto size = Game::getInstance()->window->getView().getSize();
|
||||
view = new sf::View({0, 0}, size);
|
||||
}
|
||||
|
||||
|
@ -78,6 +79,7 @@ void TrackingView::followTarget()
|
|||
{
|
||||
auto trackingPoint = getCollectiveTrackingPoint();
|
||||
marker->coordinates.set(IsometricCoordinates(trackingPoint));
|
||||
moveCenter(trackingPoint - getCenter());
|
||||
return;
|
||||
|
||||
// if (isTargetInArea(freeMoveArea))
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
|
||||
|
||||
#include "../game_object.h"
|
||||
#include "../game.h"
|
||||
#include "ITrackable.h"
|
||||
#include "../../primitives/circle_object.h"
|
||||
|
||||
class CircleObject;
|
||||
|
||||
class TrackingView : public GameObject
|
||||
{
|
||||
public:
|
||||
|
@ -17,11 +18,13 @@ public:
|
|||
|
||||
|
||||
void draw(sf::RenderWindow *window) const override;
|
||||
void lateUpdate(Game *game) override;
|
||||
|
||||
void lateUpdate() override;
|
||||
|
||||
void addTrackable(ITrackable *trackable);
|
||||
|
||||
sf::Vector2f getSize() const;
|
||||
|
||||
sf::Vector2f getCenter() const;
|
||||
|
||||
private:
|
||||
|
@ -33,26 +36,14 @@ private:
|
|||
|
||||
CircleObject *marker;
|
||||
|
||||
void initializeView(Game *game);
|
||||
void initializeView();
|
||||
|
||||
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();
|
||||
|
||||
sf::Vector2f getCollectiveTrackingPoint() const;
|
||||
|
||||
void processTrackableStates();
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
#include "game.h"
|
||||
|
||||
Game::Game(std::shared_ptr<sf::RenderWindow> window) : window(std::move(window)),
|
||||
gameObjects()
|
||||
gameObjects(),
|
||||
views()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -70,7 +71,7 @@ void Game::update()
|
|||
{
|
||||
if (gameObject->isActive)
|
||||
{
|
||||
gameObject->update(this);
|
||||
gameObject->update();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +80,7 @@ void Game::update()
|
|||
{
|
||||
if (gameObject->isActive)
|
||||
{
|
||||
gameObject->lateUpdate(this);
|
||||
gameObject->lateUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,3 +108,8 @@ std::shared_ptr<Game> Game::constructInstance(const std::shared_ptr<sf::RenderWi
|
|||
|
||||
return singletonInstance;
|
||||
}
|
||||
|
||||
void Game::registerView(TrackingView *view)
|
||||
{
|
||||
views.push_back(view);
|
||||
}
|
||||
|
|
|
@ -6,10 +6,9 @@
|
|||
#include "../logging/easylogging++.h"
|
||||
#include "game_object.h"
|
||||
#include "input/input_mapper.h"
|
||||
#include "camera/tracking_view.h"
|
||||
|
||||
|
||||
class GameObject;
|
||||
class ActionController;
|
||||
class TrackingView;
|
||||
|
||||
|
||||
class Game
|
||||
|
@ -27,7 +26,10 @@ public:
|
|||
|
||||
void addGameObject(GameObject *gameObject);
|
||||
|
||||
void registerView(TrackingView *view);
|
||||
|
||||
std::shared_ptr<sf::RenderWindow> window;
|
||||
std::vector<TrackingView*> views;
|
||||
private:
|
||||
static inline std::shared_ptr<Game> singletonInstance = nullptr;
|
||||
std::vector<GameObject *> gameObjects;
|
||||
|
|
|
@ -6,9 +6,6 @@
|
|||
#include <SFML/Graphics/Drawable.hpp>
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include "../coordinates/translated_coordinates.h"
|
||||
#include "game.h"
|
||||
|
||||
class Game;
|
||||
|
||||
class GameObject
|
||||
{
|
||||
|
@ -18,10 +15,10 @@ public:
|
|||
virtual void draw(sf::RenderWindow *window) const
|
||||
{}
|
||||
|
||||
virtual void update(Game *game)
|
||||
virtual void update()
|
||||
{}
|
||||
|
||||
virtual void lateUpdate(Game *game)
|
||||
virtual void lateUpdate()
|
||||
{}
|
||||
|
||||
TranslatedCoordinates coordinates;
|
||||
|
|
|
@ -13,7 +13,7 @@ sf::Vector2f Player::getTrackableSize() const
|
|||
return {static_cast<float>(circle->getRadius() * 2), static_cast<float>(circle->getRadius() * 2)};
|
||||
}
|
||||
|
||||
void Player::update(Game *game)
|
||||
void Player::update()
|
||||
{
|
||||
if (!input->isActive) {
|
||||
isActive = false;
|
||||
|
|
|
@ -14,7 +14,7 @@ public:
|
|||
|
||||
void draw(sf::RenderWindow *window) const override;
|
||||
|
||||
void update(Game *game) override;
|
||||
void update() override;
|
||||
|
||||
sf::Vector2f getTrackablePosition() const override;
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#include "player_spawner.hpp"
|
||||
#include "player.hpp"
|
||||
|
||||
void PlayerSpawner::update(Game *game)
|
||||
void PlayerSpawner::update()
|
||||
{
|
||||
// Create player for new input identities
|
||||
for (auto &inputIdentity: InputMapper::getInstance()->newInputIdentities)
|
||||
{
|
||||
auto player = new Player(inputIdentity, sf::Color::Red, {0, 0});
|
||||
game->addGameObject(player);
|
||||
Game::getInstance()->addGameObject(player);
|
||||
Game::getInstance()->views[0]->addTrackable(player);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
class PlayerSpawner : public GameObject
|
||||
{
|
||||
public:
|
||||
void update(Game *game) override;
|
||||
void update() override;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ void CircleObject::draw(sf::RenderWindow *window) const
|
|||
window->draw(circle);
|
||||
}
|
||||
|
||||
void CircleObject::update(Game *game)
|
||||
void CircleObject::update()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -2,15 +2,16 @@
|
|||
#define HOLESOME_CIRCLE_OBJECT_H
|
||||
|
||||
|
||||
#include "../game/game_object.h"
|
||||
#include <SFML/Graphics/RenderTarget.hpp>
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include "../game/game.h"
|
||||
|
||||
class CircleObject : public GameObject {
|
||||
public:
|
||||
CircleObject(int radius, sf::Color color);
|
||||
|
||||
void draw(sf::RenderWindow *window) const override;
|
||||
void update(Game *game) override;
|
||||
void update() override;
|
||||
|
||||
int getRadius() const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue