#ifndef PLAYER_HPP #define PLAYER_HPP #include "globals.hpp" #include "scheduler.hpp" #include #include #include enum class CollisionDir { None, Left, Right, Top, Bottom }; class Entity { public: Entity(sf::Vector2 size, sf::Vector2 pos, sf::Vector2f velocity, float border_thickness, sf::Color inside_color = sf::Color::Black, sf::Color border_color = sf::Color::White); CollisionDir find_intersection(Entity& entity); void set_velocity(sf::Vector2f velocity); void set_velocity_x(int velocity); void set_velocity_y(int velocity); sf::Vector2 get_velocity(); sf::RectangleShape rect; protected: sf::Vector2f _velocity; sf::Color _inside_color; sf::Color _border_color; float _border_thickness; }; class Player : public Entity { public: Player(sf::Vector2 size, sf::Vector2 pos, sf::Vector2f velocity, float border_thickness, float gravity, float max_acceleration, float dash_distance, sf::Color inside_color, sf::Color border_color); float m_acceleration; float m_jump_strength; float m_dash_distance; bool m_jumping; bool m_dash; Times timers; void handle_movment(); void handle_gravity(); bool get_jumping(); void horizontal_no_out_of_bounds(Entity& base); void vertical_no_out_of_bounds(Entity& base); bool get_horizontal_collision(std::array, MAX_ROWS>); bool get_vertical_top_collision(std::array, MAX_ROWS>); bool get_vertical_bottom_collision(std::array, MAX_ROWS>); private: bool get_vertical_bottom_collision_by_offset(std::array, MAX_ROWS>); sf::Vector2f _min_velocity; }; struct player_data { sf::Vector2 size { TILESIZE / 2.0f, TILESIZE / 2.0f }; sf::Vector2 pos { TILESIZE, TILESIZE }; float max_velocity_y { 15.0f }; float border_size { -1.0f }; float dash_distance { 20.0f }; sf::Vector2f velocity { 3.0f, 0 }; }; #endif