I need to change my collision and movement physics engine entirely
This commit is contained in:
+37
-30
@@ -13,63 +13,70 @@
|
||||
#include "globals.hpp"
|
||||
#include "scheduler.hpp"
|
||||
|
||||
float
|
||||
total_distance(int k);
|
||||
|
||||
float const
|
||||
distance_to_acceleration(int target);
|
||||
|
||||
struct Object;
|
||||
class Entity;
|
||||
class Object;
|
||||
class Player;
|
||||
|
||||
class Object
|
||||
struct Object
|
||||
{
|
||||
public:
|
||||
Object(ObjectData data);
|
||||
Object(ObjectData data)
|
||||
{
|
||||
rect.setSize(data.size);
|
||||
rect.setPosition(data.pos);
|
||||
rect.setOutlineThickness(data.edge);
|
||||
rect.setFillColor(data.interior_color);
|
||||
rect.setOutlineColor(data.exterior_color);
|
||||
};
|
||||
|
||||
sf::RectangleShape rect;
|
||||
};
|
||||
|
||||
class Entity : public Object
|
||||
{
|
||||
public:
|
||||
Entity(EntityData data) : Object(data), _velocity(data.velocity) {};
|
||||
public:
|
||||
Entity(EntityData data) : Object(data.object), _velocity(data.velocity) {};
|
||||
void set_velocity(sf::Vector2f velocity);
|
||||
void set_velocity_x(int velocity);
|
||||
void set_velocity_y(int velocity);
|
||||
sf::Vector2<float> get_velocity();
|
||||
const sf::Vector2<float> get_velocity();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
sf::Vector2f _velocity;
|
||||
};
|
||||
|
||||
class Player : public Entity
|
||||
{
|
||||
public:
|
||||
Player(PlayerData data, float gravity)
|
||||
: Entity(data),
|
||||
max_dash_acceleration(data.max_vertical_acceleration),
|
||||
max_vertical_acceleration(data.max_vertical_acceleration),
|
||||
gravity(gravity) {};
|
||||
public:
|
||||
Player(PlayerData data)
|
||||
: Entity(data.entity),
|
||||
max_dash_acceleration(data.max_dash_acceleration),
|
||||
max_vertical_acceleration(data.max_vertical_acceleration)
|
||||
{
|
||||
bounding_box.rect.setSize(
|
||||
{ total_distance(max_dash_acceleration),
|
||||
data.entity.object.size.y });
|
||||
};
|
||||
|
||||
Object bounding_box { object_data[1] };
|
||||
float max_vertical_acceleration;
|
||||
float max_dash_acceleration;
|
||||
float gravity;
|
||||
bool m_jumping { false };
|
||||
void handle_movment(Timer& dash,
|
||||
std::array<std::array<std::unique_ptr<Object>, 19>, 13>& tilemap);
|
||||
void handle_bounding_box(std::array<std::array<std::unique_ptr<Object>, MAX_COLS>, MAX_ROWS>& tilemap);
|
||||
void handle_movment(std::optional<Timer*> dash);
|
||||
void handle_gravity();
|
||||
bool get_jumping();
|
||||
void horizontal_no_out_of_bounds();
|
||||
void vertical_no_out_of_bounds();
|
||||
bool get_horizontal_collision(
|
||||
std::array<std::array<std::unique_ptr<Object>, MAX_COLS>, MAX_ROWS>& tilemap);
|
||||
bool get_vertical_collision(
|
||||
std::array<std::array<std::unique_ptr<Object>, MAX_COLS>, MAX_ROWS>& tilemap);
|
||||
// bool get_vertical_bottom_collision(
|
||||
// std::array<std::array<std::unique_ptr<Object>, MAX_COLS>, MAX_ROWS>& tilemap);
|
||||
|
||||
private:
|
||||
std::string direction;
|
||||
private:
|
||||
std::string direction { "left" };
|
||||
};
|
||||
|
||||
float
|
||||
total_distance(int k);
|
||||
|
||||
float
|
||||
distance_to_acceleration(int target);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user