#ifndef HOLESOME_MAP_PLAYER_HPP #define HOLESOME_MAP_PLAYER_HPP #include #include "../player/player.hpp" #include "../../config.h" struct MapPlayer { Player *player; b2Body *body; MapPlayer(Player *player, b2Body *body) : player(player), body(body) {} void updateSimulationPosition() const { auto coordinates = player->coordinates->world(); b2Vec2 playerPosition = b2Vec2(coordinates.x, coordinates.y); // Calculate velocity that theoretically needs to be applied to the body, to get to the same position b2Vec2 delta = playerPosition - body->GetPosition(); b2Vec2 velocity = {delta.x * FRAME_RATE, delta.y * FRAME_RATE}; body->SetLinearVelocity(velocity); } void updatePlayerPosition() const { b2Vec2 playerPosition = body->GetPosition(); player->coordinates->set(sf::Vector2f(playerPosition.x, playerPosition.y)); } }; #endif //HOLESOME_MAP_PLAYER_HPP