2023-06-10 14:48:16 +02:00
|
|
|
#ifndef HOLESOME_MAP_PLAYER_HPP
|
|
|
|
#define HOLESOME_MAP_PLAYER_HPP
|
|
|
|
|
|
|
|
|
|
|
|
#include <box2d/box2d.h>
|
|
|
|
#include "../player/player.hpp"
|
2023-06-10 15:24:03 +02:00
|
|
|
#include "../../config.h"
|
2023-06-10 14:48:16 +02:00
|
|
|
|
|
|
|
struct MapPlayer
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
b2Body *body;
|
|
|
|
|
2023-06-10 15:24:03 +02:00
|
|
|
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));
|
|
|
|
}
|
2023-06-10 14:48:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //HOLESOME_MAP_PLAYER_HPP
|